@lostgradient/mcp 0.2.1 → 0.2.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.
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-taxyscge.js";
4
4
  import {
5
5
  PACKAGE_VERSION
6
- } from "./chunk-wfty87ws.js";
6
+ } from "./chunk-gezawyg9.js";
7
7
  import {
8
8
  hasRegisteredUiExtensionResource
9
9
  } from "./chunk-rxnyn7tf.js";
@@ -1,4 +1,4 @@
1
1
  // src/version.ts
2
- var PACKAGE_VERSION = "0.2.1";
2
+ var PACKAGE_VERSION = "0.2.2";
3
3
 
4
4
  export { PACKAGE_VERSION };
@@ -6,9 +6,9 @@ import {
6
6
  createMcpServer,
7
7
  hasValidLocalhostRebindingHeaders,
8
8
  isLoopbackHostname
9
- } from "../chunk-7dpts3r9.js";
9
+ } from "../chunk-g912yspg.js";
10
10
  import"../chunk-taxyscge.js";
11
- import"../chunk-wfty87ws.js";
11
+ import"../chunk-gezawyg9.js";
12
12
  import {
13
13
  resolveOauthNetworkIdentity
14
14
  } from "../chunk-yf4nw40e.js";
package/dist/index.js CHANGED
@@ -11,13 +11,13 @@ import {
11
11
  readRequestSender,
12
12
  readSessionIdentifier,
13
13
  stringifyUnknown
14
- } from "./chunk-7dpts3r9.js";
14
+ } from "./chunk-g912yspg.js";
15
15
  import {
16
16
  metricsCollector
17
17
  } from "./chunk-taxyscge.js";
18
18
  import {
19
19
  PACKAGE_VERSION
20
- } from "./chunk-wfty87ws.js";
20
+ } from "./chunk-gezawyg9.js";
21
21
  import {
22
22
  getSupportedScopes,
23
23
  hasRegisteredUiExtensionResource
@@ -7,6 +7,39 @@ export type PostgresOAuthDatabase = PostgresOAuthExecutor & {
7
7
  };
8
8
  export declare function hashOpaqueValue(value: string): string;
9
9
  export declare function resultRows<T>(result: unknown): T[];
10
+ /**
11
+ * Coerces a driver timestamp value to a Date.
12
+ *
13
+ * The read paths in these stores call `database.execute(sql`…`)`, which bypasses
14
+ * drizzle's typed column mapping. Every drizzle pg-family driver — node-postgres,
15
+ * neon-serverless, and pglite alike — overrides the `timestamptz`/`timestamp`/
16
+ * `date` type parser to return the raw string so that its column `mode` can do
17
+ * the conversion, but `execute` never reaches that mapping. So these columns
18
+ * arrive as strings even though the store types declare `Date`, and a consumer
19
+ * calling a `Date` method on one (for example the resource-server auth building
20
+ * `expiresAt.getTime()`, or the client-secret expiry check) throws in
21
+ * production. A value already a `Date` (a driver without the override) passes
22
+ * through unchanged.
23
+ *
24
+ * Fails loudly rather than coercing silently: a `NOT NULL` column that comes
25
+ * back null would make `new Date(null)` the Unix epoch, and an unparseable
26
+ * string would make an `Invalid Date` — both still `Date` instances that would
27
+ * corrupt `expiresAt`/`createdAt` or propagate `NaN` downstream. So null,
28
+ * undefined, and unparseable values throw here instead.
29
+ */
30
+ export declare function toDate(value: unknown): Date;
31
+ /**
32
+ * Null-safe {@link toDate} for nullable timestamp columns: null and undefined
33
+ * map to null, and any present value is validated by {@link toDate}.
34
+ */
35
+ export declare function toNullableDate(value: unknown): Date | null;
36
+ /**
37
+ * Coerces the named timestamp columns on a result row to `Date` in place and
38
+ * returns the row. `required` columns are `NOT NULL`; `nullable` columns may be
39
+ * null. Keeps the raw-SQL read paths' declared return types honest without
40
+ * threading a bespoke mapper through every store.
41
+ */
42
+ export declare function coerceRowDates<T>(row: T, required: readonly (keyof T)[], nullable?: readonly (keyof T)[]): T;
10
43
  export declare function affectedRows(result: unknown): number;
11
44
  export declare function countRows(result: unknown): number;
12
45
  export declare function columnIdentifier(column: {
@@ -109,6 +109,27 @@ function resultRows(result) {
109
109
  }
110
110
  return [];
111
111
  }
112
+ function toDate(value) {
113
+ if (value === null || value === undefined) {
114
+ throw new TypeError("OAuth store timestamp column was null; expected a NOT NULL timestamp.");
115
+ }
116
+ const date = value instanceof Date ? value : new Date(value);
117
+ if (Number.isNaN(date.getTime())) {
118
+ throw new TypeError(`OAuth store timestamp could not be parsed: ${String(value)}`);
119
+ }
120
+ return date;
121
+ }
122
+ function toNullableDate(value) {
123
+ return value === null || value === undefined ? null : toDate(value);
124
+ }
125
+ function coerceRowDates(row, required, nullable = []) {
126
+ const record = row;
127
+ for (const key of required)
128
+ record[key] = toDate(record[key]);
129
+ for (const key of nullable)
130
+ record[key] = toNullableDate(record[key]);
131
+ return row;
132
+ }
112
133
  function affectedRows(result) {
113
134
  if (result && typeof result === "object" && "rowCount" in result && typeof result.rowCount === "number") {
114
135
  return result.rowCount;
@@ -160,7 +181,8 @@ class PostgresTransactionStore {
160
181
  client_id AS "clientId", redirect_uri AS "redirectUri", code_challenge AS "codeChallenge",
161
182
  code_challenge_method AS "codeChallengeMethod", state, issuer, resource, scope,
162
183
  expires_at AS "expiresAt", consumed_at AS "consumedAt", created_at AS "createdAt"`);
163
- return resultRows(result)[0] ?? null;
184
+ const row = resultRows(result)[0];
185
+ return row ? coerceRowDates(row, ["expiresAt", "consumedAt", "createdAt"]) : null;
164
186
  }
165
187
  async unconsume(transactionId, consumedAt) {
166
188
  return affectedRows(await this.database.execute(sql`UPDATE ${this.schema.transactions} SET consumed_at = NULL
@@ -203,13 +225,15 @@ class PostgresCodeStore {
203
225
  async findByHash(codeHash) {
204
226
  const userId = columnIdentifier(this.schema.codes.userId);
205
227
  const result = await this.database.execute(sql`SELECT ${returnedCode(userId)} FROM ${this.schema.codes} WHERE code_hash = ${codeHash}`);
206
- return resultRows(result)[0] ?? null;
228
+ const row = resultRows(result)[0];
229
+ return row ? coerceRowDates(row, ["expiresAt", "createdAt"], ["usedAt"]) : null;
207
230
  }
208
231
  async consume(codeHash, now) {
209
232
  const userId = columnIdentifier(this.schema.codes.userId);
210
233
  const result = await this.database.execute(sql`UPDATE ${this.schema.codes} SET used_at = date_trunc('milliseconds', clock_timestamp())
211
234
  WHERE code_hash = ${codeHash} AND used_at IS NULL AND expires_at > ${now} RETURNING ${returnedCode(userId)}`);
212
- return resultRows(result)[0] ?? null;
235
+ const row = resultRows(result)[0];
236
+ return row ? coerceRowDates(row, ["expiresAt", "usedAt", "createdAt"]) : null;
213
237
  }
214
238
  async unconsume(codeHash, usedAt) {
215
239
  return affectedRows(await this.database.execute(sql`UPDATE ${this.schema.codes} SET used_at = NULL
@@ -254,7 +278,8 @@ class PostgresTokenStore {
254
278
  const userId = columnIdentifier(this.schema.accessTokens.userId);
255
279
  const result = await this.database.execute(sql`SELECT ${returnedAccessToken(userId)} FROM ${this.schema.accessTokens}
256
280
  WHERE access_token_hash = ${tokenHash}`);
257
- return resultRows(result)[0] ?? null;
281
+ const row = resultRows(result)[0];
282
+ return row ? coerceRowDates(row, ["expiresAt", "createdAt"], ["revokedAt"]) : null;
258
283
  }
259
284
  async rotateRefreshToken(input) {
260
285
  return this.database.transaction(async (transaction) => {
@@ -517,7 +542,10 @@ class PostgresClientStore {
517
542
  async findById(clientId) {
518
543
  const result = await this.database.execute(sql`SELECT ${returnedClient} FROM ${this.schema.clients} WHERE client_id = ${clientId}`);
519
544
  const client = resultRows(result)[0];
520
- return client ? structuredClone(client) : null;
545
+ if (!client)
546
+ return null;
547
+ coerceRowDates(client, ["createdAt", "updatedAt"], ["clientSecretExpiresAt"]);
548
+ return structuredClone(client);
521
549
  }
522
550
  async update(clientId, patch) {
523
551
  const columns = {
package/dist/version.d.ts CHANGED
@@ -20,4 +20,4 @@
20
20
  * thing making this approach safe — do not delete it to silence a release
21
21
  * bump; update this constant instead.
22
22
  */
23
- export declare const PACKAGE_VERSION = "0.2.1";
23
+ export declare const PACKAGE_VERSION = "0.2.2";
package/dist/version.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  PACKAGE_VERSION
3
- } from "./chunk-wfty87ws.js";
3
+ } from "./chunk-gezawyg9.js";
4
4
  export {
5
5
  PACKAGE_VERSION
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lostgradient/mcp",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "A Model Context Protocol server engine: registries, scope vocabularies, and an OAuth-ready request boundary.",
5
5
  "license": "MIT",
6
6
  "author": "Steve Kinney <hello@stevekinney.net>",