@structured-world/gitlab-mcp-db 10.1.0 → 12.0.0
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 +8 -8
- package/dist/generated/prisma/client.d.ts +2 -0
- package/dist/generated/prisma/commonInputTypes.d.ts +178 -9
- package/dist/generated/prisma/internal/class.d.ts +6 -0
- package/dist/generated/prisma/internal/class.js +6 -6
- package/dist/generated/prisma/internal/class.js.map +1 -1
- package/dist/generated/prisma/internal/prismaNamespace.d.ts +209 -1
- package/dist/generated/prisma/internal/prismaNamespace.js +56 -5
- package/dist/generated/prisma/internal/prismaNamespace.js.map +1 -1
- package/dist/generated/prisma/models/AccountSettings.d.ts +400 -0
- package/dist/generated/prisma/models/AccountSettings.js +3 -0
- package/dist/generated/prisma/models/AccountSettings.js.map +1 -0
- package/dist/generated/prisma/models/AuthCodeFlowState.d.ts +174 -2
- package/dist/generated/prisma/models/DeviceFlowState.d.ts +214 -2
- package/dist/generated/prisma/models/OAuthClient.d.ts +577 -0
- package/dist/generated/prisma/models/OAuthClient.js +3 -0
- package/dist/generated/prisma/models/OAuthClient.js.map +1 -0
- package/dist/generated/prisma/models/OAuthSession.d.ts +555 -3
- package/dist/generated/prisma/models.d.ts +2 -0
- package/dist/src/migrate.d.ts +16 -0
- package/dist/src/migrate.js +115 -0
- package/dist/src/migrate.js.map +1 -0
- package/dist/src/postgresql.d.ts +29 -1
- package/dist/src/postgresql.js +580 -86
- package/dist/src/postgresql.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -6
- package/prisma/migrations/0_init/migration.sql +115 -0
- package/prisma/migrations/20261008000000_released_schema_columns/migration.sql +15 -0
- package/prisma/migrations/20261009000000_oauth_account_linking/migration.sql +47 -0
- package/prisma/migrations/20261010000000_account_settings/migration.sql +12 -0
- package/prisma/migrations/20261017000000_linked_accounts/migration.sql +15 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +66 -0
- package/prisma.config.ts +19 -0
|
@@ -2,5 +2,7 @@ export type * from './models/OAuthSession';
|
|
|
2
2
|
export type * from './models/DeviceFlowState';
|
|
3
3
|
export type * from './models/AuthCodeFlowState';
|
|
4
4
|
export type * from './models/AuthorizationCode';
|
|
5
|
+
export type * from './models/OAuthClient';
|
|
6
|
+
export type * from './models/AccountSettings';
|
|
5
7
|
export type * from './models/McpSessionMapping';
|
|
6
8
|
export type * from './commonInputTypes';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface Queryable {
|
|
2
|
+
query(text: string, values?: unknown[]): Promise<{
|
|
3
|
+
rows: unknown[];
|
|
4
|
+
}>;
|
|
5
|
+
end(): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export interface MigrateDeps {
|
|
8
|
+
connect(url: string, timeoutMs: number): Promise<Queryable>;
|
|
9
|
+
prisma(args: string[]): number;
|
|
10
|
+
sleep(ms: number): Promise<void>;
|
|
11
|
+
now(): number;
|
|
12
|
+
log(message: string): void;
|
|
13
|
+
}
|
|
14
|
+
export declare function migrate(url: string | undefined, deps: MigrateDeps): Promise<number>;
|
|
15
|
+
export declare function connectPostgres(url: string, timeoutMs: number): Promise<Queryable>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.migrate = migrate;
|
|
37
|
+
exports.connectPostgres = connectPostgres;
|
|
38
|
+
const node_child_process_1 = require("node:child_process");
|
|
39
|
+
const path = __importStar(require("node:path"));
|
|
40
|
+
const pg_1 = require("pg");
|
|
41
|
+
const BASELINE_MIGRATION = '0_init';
|
|
42
|
+
const WAIT_MS = 60_000;
|
|
43
|
+
const RETRY_MS = 1_000;
|
|
44
|
+
async function waitForDatabase(url, deps) {
|
|
45
|
+
const deadline = deps.now() + WAIT_MS;
|
|
46
|
+
for (;;) {
|
|
47
|
+
try {
|
|
48
|
+
return await deps.connect(url, Math.max(1, deadline - deps.now()));
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (deps.now() >= deadline) {
|
|
52
|
+
deps.log(`Database is not reachable: ${error.message}`);
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
await deps.sleep(RETRY_MS);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function needsBaseline(client, url) {
|
|
60
|
+
const schema = new URL(url).searchParams.get('schema') ?? 'public';
|
|
61
|
+
const { rows } = await client.query(`SELECT to_regclass(quote_ident($1) || '.oauth_sessions') IS NOT NULL AS has_tables,
|
|
62
|
+
to_regclass(quote_ident($1) || '._prisma_migrations') IS NOT NULL AS has_history`, [schema]);
|
|
63
|
+
const state = rows[0];
|
|
64
|
+
return state.has_tables && !state.has_history;
|
|
65
|
+
}
|
|
66
|
+
async function migrate(url, deps) {
|
|
67
|
+
if (!url) {
|
|
68
|
+
deps.log('Set OAUTH_STORAGE_POSTGRESQL_URL or DATABASE_URL');
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
const client = await waitForDatabase(url, deps);
|
|
72
|
+
if (!client)
|
|
73
|
+
return 1;
|
|
74
|
+
let baseline;
|
|
75
|
+
try {
|
|
76
|
+
baseline = await needsBaseline(client, url);
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
await client.end();
|
|
80
|
+
}
|
|
81
|
+
if (baseline) {
|
|
82
|
+
deps.log(`Existing tables without migration history: marking ${BASELINE_MIGRATION} applied`);
|
|
83
|
+
const status = deps.prisma(['migrate', 'resolve', '--applied', BASELINE_MIGRATION]);
|
|
84
|
+
if (status !== 0)
|
|
85
|
+
return status;
|
|
86
|
+
}
|
|
87
|
+
return deps.prisma(['migrate', 'deploy']);
|
|
88
|
+
}
|
|
89
|
+
const PACKAGE_DIR = path.resolve(__dirname, '..', '..');
|
|
90
|
+
async function connectPostgres(url, timeoutMs) {
|
|
91
|
+
const client = new pg_1.Client({ connectionString: url, connectionTimeoutMillis: timeoutMs });
|
|
92
|
+
await client.connect();
|
|
93
|
+
return client;
|
|
94
|
+
}
|
|
95
|
+
const defaultDeps = {
|
|
96
|
+
connect: connectPostgres,
|
|
97
|
+
prisma(args) {
|
|
98
|
+
const cli = path.join(path.dirname(require.resolve('prisma/package.json')), 'build/index.js');
|
|
99
|
+
const result = (0, node_child_process_1.spawnSync)(process.execPath, [cli, ...args], {
|
|
100
|
+
cwd: PACKAGE_DIR,
|
|
101
|
+
stdio: 'inherit',
|
|
102
|
+
});
|
|
103
|
+
return result.status ?? 1;
|
|
104
|
+
},
|
|
105
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
106
|
+
now: () => Date.now(),
|
|
107
|
+
log: (message) => console.error(message),
|
|
108
|
+
};
|
|
109
|
+
if (require.main === module) {
|
|
110
|
+
migrate(process.env.OAUTH_STORAGE_POSTGRESQL_URL ?? process.env.DATABASE_URL, defaultDeps).then((status) => process.exit(status), (error) => {
|
|
111
|
+
console.error('Migration failed:', error);
|
|
112
|
+
process.exit(1);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../src/migrate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyEA,0BAmBC;AAMD,0CAIC;AA1FD,2DAA+C;AAC/C,gDAAkC;AAClC,2BAA4B;AAG5B,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAEpC,MAAM,OAAO,GAAG,MAAM,CAAC;AACvB,MAAM,QAAQ,GAAG,KAAK,CAAC;AAkBvB,KAAK,UAAU,eAAe,CAAC,GAAW,EAAE,IAAiB;IAC3D,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC;IACtC,SAAS,CAAC;QACR,IAAI,CAAC;YAGH,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACrE,CAAC;QAAC,OAAO,K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,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;IACrB,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;CACzC,CAAC;AAEF,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,IAAI,CAC7F,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAChC,CAAC,KAAc,EAAE,EAAE;QACjB,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;QAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/dist/src/postgresql.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { OAuthSession, DeviceFlowState as DeviceFlowStateType, AuthCodeFlowState as AuthCodeFlowStateType, AuthorizationCode as AuthorizationCodeType, SessionStorageBackend, SessionStorageStats } from '@structured-world/gitlab-mcp/storage-contract';
|
|
1
|
+
import type { AbandonedFlowGrantHandler, ExpiredSessionHandler, OAuthSession, DeviceFlowState as DeviceFlowStateType, AuthCodeFlowState as AuthCodeFlowStateType, AuthorizationCode as AuthorizationCodeType, RegisteredOAuthClient as RegisteredOAuthClientType, GitLabTokenResponse, SessionStorageBackend, SessionStorageStats, LinkedAccountCommit, AccountSettings, AccountSettingsRecord } from '@structured-world/gitlab-mcp/storage-contract';
|
|
2
2
|
export interface PostgreSQLStorageOptions {
|
|
3
3
|
connectionString?: string;
|
|
4
4
|
}
|
|
@@ -6,21 +6,32 @@ export declare class PostgreSQLStorageBackend implements SessionStorageBackend {
|
|
|
6
6
|
readonly type: "postgresql";
|
|
7
7
|
private prisma;
|
|
8
8
|
private cleanupIntervalId;
|
|
9
|
+
private abandonedFlowGrant;
|
|
10
|
+
private expiredSession;
|
|
11
|
+
private readonly connectionString;
|
|
12
|
+
constructor(options?: PostgreSQLStorageOptions);
|
|
9
13
|
initialize(): Promise<void>;
|
|
10
14
|
private getPrisma;
|
|
15
|
+
commitLinkedAccount(commit: LinkedAccountCommit): Promise<boolean>;
|
|
16
|
+
private insertSession;
|
|
11
17
|
createSession(session: OAuthSession): Promise<void>;
|
|
12
18
|
getSession(sessionId: string): Promise<OAuthSession | undefined>;
|
|
13
19
|
getSessionByToken(token: string): Promise<OAuthSession | undefined>;
|
|
14
20
|
getSessionByRefreshToken(refreshToken: string): Promise<OAuthSession | undefined>;
|
|
15
21
|
updateSession(sessionId: string, updates: Partial<OAuthSession>): Promise<boolean>;
|
|
22
|
+
rotateSession(sessionId: string, expectedRefreshToken: string, updates: Partial<OAuthSession>): Promise<boolean>;
|
|
23
|
+
private sessionUpdateData;
|
|
16
24
|
deleteSession(sessionId: string): Promise<boolean>;
|
|
17
25
|
getAllSessions(): Promise<OAuthSession[]>;
|
|
26
|
+
getLinkedSessions(sessionId: string): Promise<OAuthSession[]>;
|
|
18
27
|
private rowToSession;
|
|
19
28
|
storeDeviceFlow(state: string, flow: DeviceFlowStateType): Promise<void>;
|
|
20
29
|
getDeviceFlow(state: string): Promise<DeviceFlowStateType | undefined>;
|
|
21
30
|
getDeviceFlowByDeviceCode(deviceCode: string): Promise<DeviceFlowStateType | undefined>;
|
|
22
31
|
deleteDeviceFlow(state: string): Promise<boolean>;
|
|
23
32
|
private rowToDeviceFlow;
|
|
33
|
+
cacheLinkedFlowTokens(flow: AuthCodeFlowStateType, tokens: GitLabTokenResponse): Promise<boolean>;
|
|
34
|
+
private authCodeFlowData;
|
|
24
35
|
storeAuthCodeFlow(internalState: string, flow: AuthCodeFlowStateType): Promise<void>;
|
|
25
36
|
getAuthCodeFlow(internalState: string): Promise<AuthCodeFlowStateType | undefined>;
|
|
26
37
|
deleteAuthCodeFlow(internalState: string): Promise<boolean>;
|
|
@@ -32,6 +43,23 @@ export declare class PostgreSQLStorageBackend implements SessionStorageBackend {
|
|
|
32
43
|
associateMcpSession(mcpSessionId: string, oauthSessionId: string): Promise<void>;
|
|
33
44
|
getSessionByMcpSessionId(mcpSessionId: string): Promise<OAuthSession | undefined>;
|
|
34
45
|
removeMcpSessionAssociation(mcpSessionId: string): Promise<boolean>;
|
|
46
|
+
consumeAuthCode(code: string): Promise<AuthorizationCodeType | undefined>;
|
|
47
|
+
consumeAuthCodeFlow(internalState: string): Promise<AuthCodeFlowStateType | undefined>;
|
|
48
|
+
consumeDeviceFlow(state: string): Promise<DeviceFlowStateType | undefined>;
|
|
49
|
+
claimGitLabRefresh(sessionId: string, expectedRefreshToken: string, now: number, leaseUntil: number): Promise<boolean>;
|
|
50
|
+
releaseGitLabRefresh(sessionId: string, leaseUntil: number): Promise<void>;
|
|
51
|
+
claimDevicePoll(state: string, now: number, nextPollAt: number): Promise<DeviceFlowStateType | undefined>;
|
|
52
|
+
storeClient(client: RegisteredOAuthClientType): Promise<void>;
|
|
53
|
+
markClientUsed(clientId: string): Promise<void>;
|
|
54
|
+
countClientsRegisteredSince(registeredFrom: string, since: number): Promise<number>;
|
|
55
|
+
getClient(clientId: string): Promise<RegisteredOAuthClientType | undefined>;
|
|
56
|
+
getAccountSettings(accountKey: string): Promise<AccountSettingsRecord | undefined>;
|
|
57
|
+
putAccountSettings(accountKey: string, settings: AccountSettings, expectedVersion: number): Promise<AccountSettingsRecord | undefined>;
|
|
58
|
+
onAbandonedFlowGrant(handler: AbandonedFlowGrantHandler, leaseMs: number): void;
|
|
59
|
+
onExpiredSession(handler: ExpiredSessionHandler): void;
|
|
60
|
+
private expireSessions;
|
|
61
|
+
private claimAbandonedFlow;
|
|
62
|
+
private endAbandonedFlows;
|
|
35
63
|
cleanup(): Promise<void>;
|
|
36
64
|
close(): Promise<void>;
|
|
37
65
|
getStats(): Promise<SessionStorageStats>;
|