@burdenoff/mcp-libs 2026.1031.3 → 2026.1101.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/README.md +30 -0
- package/dist/{chunk-FVLIANOQ.js → chunk-LUXDBCVJ.js} +3 -3
- package/dist/{chunk-FVLIANOQ.js.map → chunk-LUXDBCVJ.js.map} +1 -1
- package/dist/{chunk-76RGHRRS.js → chunk-WYCRYHHY.js} +83 -33
- package/dist/chunk-WYCRYHHY.js.map +1 -0
- package/dist/core/auth/store.d.ts +1 -0
- package/dist/core/gql/client.d.ts +6 -0
- package/dist/core/index.cjs +83 -30
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +1 -1
- package/dist/index.cjs +80 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/modules/adaptercloud/index.js +1 -1
- package/dist/modules/adaptercloud/tools/shared.d.ts +91 -13
- package/dist/modules/artistrybase/index.js +1 -1
- package/dist/modules/artistrybase/tools/shared.d.ts +80 -12
- package/dist/modules/assethandler/index.js +1 -1
- package/dist/modules/assethandler/tools/shared.d.ts +52 -8
- package/dist/modules/atheletebridge/index.js +1 -1
- package/dist/modules/atheletebridge/tools/shared.d.ts +83 -12
- package/dist/modules/auth/index.js +3 -3
- package/dist/modules/billing/index.js +1 -1
- package/dist/modules/brainyrich/index.js +1 -1
- package/dist/modules/brainyrich/tools/shared.d.ts +102 -14
- package/dist/modules/buildmyiq/index.js +1 -1
- package/dist/modules/buildmyiq/tools/shared.d.ts +75 -12
- package/dist/modules/channels/index.js +1 -1
- package/dist/modules/collabkin/index.js +1 -1
- package/dist/modules/collabkin/tools/shared.d.ts +66 -10
- package/dist/modules/comradecircle/index.js +1 -1
- package/dist/modules/comradecircle/tools/shared.d.ts +78 -14
- package/dist/modules/conversations/index.js +1 -1
- package/dist/modules/coolandlovely/index.js +1 -1
- package/dist/modules/coolandlovely/tools/shared.d.ts +76 -19
- package/dist/modules/cosmicintersection/index.js +1 -1
- package/dist/modules/cosmicintersection/tools/shared.d.ts +94 -13
- package/dist/modules/crewfoundry/index.js +1 -1
- package/dist/modules/devportal/index.js +1 -1
- package/dist/modules/ecoimpacthub/index.js +1 -1
- package/dist/modules/ecoimpacthub/tools/shared.d.ts +130 -17
- package/dist/modules/eventfullymanaged/index.js +1 -1
- package/dist/modules/export/index.js +1 -1
- package/dist/modules/files/index.js +1 -1
- package/dist/modules/fluidgrids/durable-operations.d.ts +23 -0
- package/dist/modules/fluidgrids/index.cjs +566 -13
- package/dist/modules/fluidgrids/index.cjs.map +1 -1
- package/dist/modules/fluidgrids/index.js +490 -12
- package/dist/modules/fluidgrids/index.js.map +1 -1
- package/dist/modules/fluidgrids/operations.d.ts +4 -3
- package/dist/modules/fluidgrids/tools/durable.d.ts +3 -0
- package/dist/modules/ggnomad/index.js +1 -1
- package/dist/modules/ggnomad/tools/shared.d.ts +23 -3
- package/dist/modules/govcitizenhub/index.js +1 -1
- package/dist/modules/govcitizenhub/tools/shared.d.ts +68 -10
- package/dist/modules/groups/index.js +1 -1
- package/dist/modules/headshotmarketing/index.js +1 -1
- package/dist/modules/headshotmarketing/tools/shared.d.ts +299 -42
- package/dist/modules/health/index.js +1 -1
- package/dist/modules/healthybowl/index.js +1 -1
- package/dist/modules/healthybowl/tools/shared.d.ts +5 -1
- package/dist/modules/hookmovies/index.js +1 -1
- package/dist/modules/hookmovies/tools/shared.d.ts +93 -13
- package/dist/modules/housingvista/index.js +1 -1
- package/dist/modules/housingvista/tools/shared.d.ts +15 -2
- package/dist/modules/integrations/index.js +1 -1
- package/dist/modules/intelwatchtower/index.js +1 -1
- package/dist/modules/intelwatchtower/tools/shared.d.ts +121 -16
- package/dist/modules/kadaikodi/index.js +1 -1
- package/dist/modules/kadaikodi/tools/shared.d.ts +52 -7
- package/dist/modules/labsofscience/index.js +1 -1
- package/dist/modules/labsofscience/tools/shared.d.ts +85 -13
- package/dist/modules/manufacturedops/index.js +1 -1
- package/dist/modules/manufacturedops/tools/shared.d.ts +95 -14
- package/dist/modules/movethewheels/index.js +1 -1
- package/dist/modules/movethewheels/tools/shared.d.ts +111 -14
- package/dist/modules/mybodyshield/index.js +1 -1
- package/dist/modules/mybodyshield/tools/shared.d.ts +84 -12
- package/dist/modules/notifications/index.js +1 -1
- package/dist/modules/organizations/index.js +1 -1
- package/dist/modules/planmagnet/index.js +1 -1
- package/dist/modules/planmagnet/tools/shared.d.ts +231 -31
- package/dist/modules/products/index.js +1 -1
- package/dist/modules/proserviceworld/index.js +1 -1
- package/dist/modules/proserviceworld/tools/shared.d.ts +53 -9
- package/dist/modules/rbac/index.js +1 -1
- package/dist/modules/sandbox/index.js +1 -1
- package/dist/modules/scheduler/index.js +1 -1
- package/dist/modules/security/index.js +1 -1
- package/dist/modules/semanticfed/index.js +1 -1
- package/dist/modules/semanticfed/tools/shared.d.ts +87 -12
- package/dist/modules/store/index.js +1 -1
- package/dist/modules/subscriberbot/index.js +1 -1
- package/dist/modules/subscriberbot/tools/shared.d.ts +157 -19
- package/dist/modules/support/index.js +1 -1
- package/dist/modules/tags/index.js +1 -1
- package/dist/modules/technospam/index.js +1 -1
- package/dist/modules/technospam/tools/shared.d.ts +63 -10
- package/dist/modules/theculturepost/index.js +1 -1
- package/dist/modules/theculturepost/tools/shared.d.ts +63 -8
- package/dist/modules/theglobalfuel/index.js +1 -1
- package/dist/modules/theglobalfuel/tools/shared.d.ts +117 -14
- package/dist/modules/timecampus/index.js +1 -1
- package/dist/modules/timecampus/tools/shared.d.ts +131 -21
- package/dist/modules/tours/index.js +1 -1
- package/dist/modules/vibecontrols/index.js +2 -2
- package/dist/modules/workspaces/index.js +1 -1
- package/package.json +16 -15
- package/dist/chunk-76RGHRRS.js.map +0 -1
package/README.md
CHANGED
|
@@ -74,3 +74,33 @@ See [CLAUDE.md](./CLAUDE.md) for the full architecture, hard rules, and adding-a
|
|
|
74
74
|
## License
|
|
75
75
|
|
|
76
76
|
UNLICENSED — Burdenoff Consultancy Services Pvt. Ltd.
|
|
77
|
+
## FluidGrids code-first and durable tools
|
|
78
|
+
|
|
79
|
+
The FluidGrids module includes the SDK's code-first and durable-run operations:
|
|
80
|
+
`runs_by_workflow_id`, `runs_count`, `runs_describe`, `runs_determinism`,
|
|
81
|
+
`runs_history`, `runs_pending`, `runs_signal`, `runs_stack_trace`,
|
|
82
|
+
`runs_terminate`, `workflows_create_version`, `workflows_export`,
|
|
83
|
+
`workflows_import`, `workflows_import_template`, `workflows_interface`,
|
|
84
|
+
`workflows_start`, and `workflows_validate`. Tool names receive the host's product
|
|
85
|
+
prefix, for example `fluidgrids_runs_history`.
|
|
86
|
+
|
|
87
|
+
Run tools that accept `run` support either a run ID or a
|
|
88
|
+
`{ workflowKey, workflowId, firstRunId? }` target. History is bounded to one page
|
|
89
|
+
(1–1,000 events); pass `nextAfter` as `after` to continue. File and offloaded
|
|
90
|
+
payload URLs are returned without being downloaded. Imports accept exactly one
|
|
91
|
+
of `definitionJson` or inline JSON/TypeScript `source` files. URL-based source
|
|
92
|
+
imports are not exposed because the backend reserves and rejects that mode.
|
|
93
|
+
|
|
94
|
+
Starts and signals can execute external actions, and termination stops a run
|
|
95
|
+
without cancellation handlers. They explicitly advertise `destructiveHint: true`;
|
|
96
|
+
hosts must enable `enforceDestructiveConfirmation` to require `confirm: true`
|
|
97
|
+
before the handler runs. The FluidGrids MCP host already enables this option.
|
|
98
|
+
`TERMINATE_EXISTING` also requires `workflowId` and is sent to the separate
|
|
99
|
+
`startWorkflowTerminateExisting` gateway mutation, which enforces delete
|
|
100
|
+
permission. Confirmation never grants a missing gateway permission or feature
|
|
101
|
+
entitlement. Draft import/version creation does not activate or execute a workflow.
|
|
102
|
+
|
|
103
|
+
The library's exact MCP SDK peer is `1.32.1`. Zod `^3.25.0` remains supported for
|
|
104
|
+
existing consumers, while new hosts should install patched Zod `^4.6.6`.
|
|
105
|
+
Dependency vulnerability checks and host installation tests must cover the
|
|
106
|
+
actual resolved graph; a peer range is not a security clearance for old versions.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fetchWorkspaces, issueWorkspaceToken } from './chunk-
|
|
1
|
+
import { fetchWorkspaces, issueWorkspaceToken } from './chunk-WYCRYHHY.js';
|
|
2
2
|
|
|
3
3
|
// src/modules/auth/legacy-auth.ts
|
|
4
4
|
var helpers = /* @__PURE__ */ new WeakMap();
|
|
@@ -269,5 +269,5 @@ function createAuthHelper(ctx) {
|
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
export { getAuth };
|
|
272
|
-
//# sourceMappingURL=chunk-
|
|
273
|
-
//# sourceMappingURL=chunk-
|
|
272
|
+
//# sourceMappingURL=chunk-LUXDBCVJ.js.map
|
|
273
|
+
//# sourceMappingURL=chunk-LUXDBCVJ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/modules/auth/legacy-auth.ts"],"names":[],"mappings":";;;AA6EA,IAAM,OAAA,uBAAc,OAAA,EAAgC;AAE7C,SAAS,QAAQ,GAAA,EAA6B;AACnD,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,GAAA,CAAI,GAAG,CAAA;AAC9B,EAAA,IAAI,QAAQ,OAAO,MAAA;AACnB,EAAA,MAAM,MAAA,GAAS,iBAAiB,GAAG,CAAA;AACnC,EAAA,OAAA,CAAQ,GAAA,CAAI,KAAK,MAAM,CAAA;AACvB,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,iBAAiB,GAAA,EAA6B;AACrD,EAAA,IAAI,OAAA,GAAoC,IAAA;AACxC,EAAA,IAAI,eAAA,GAAuC,IAAA;AAC3C,EAAA,IAAI,iBAAA,GAA0C,IAAA;AAE9C,EAAA,SAAS,MAAA,GAAe;AACtB,IAAA,eAAA,IAAkB;AAAA,EACpB;AAEA,EAAA,eAAe,UAAA,GAAwC;AACrD,IAAA,MAAM,EAAE,UAAA,EAAY,QAAA,EAAS,GAAI,GAAA,CAAI,OAAO,WAAA,E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AAA,GAAqC;AAC5C,IAAA,MAAM,IAAA,GAAO,GAAA,CAAI,IAAA,CAAK,IAAA,EAAK;AAC3B,IAAA,MAAM,UAAkC,EAAC;AACzC,IAAA,IAAI,IAAA,EAAM,MAAA,EAAQ,OAAA,CAAQ,WAAW,IAAI,IAAA,CAAK,MAAA;AAC9C,IAAA,IAAI,MAAM,WAAA,EAAa,OAAA,CAAQ,eAAe,CAAA,GAAI,CAAA,OAAA,EAAU,KAAK,WAAW,CAAA,CAAA;AAC5E,IAAA,IAAI,IAAA,EAAM,cAAA;AACR,MAAA,OAAA,CAAQ,2BAA2B,CAAA,GAAI,CAAA,OAAA,EAAU,IAAA,CAAK,cAAc,CAAA,CAAA;AACtE,IAAA,IAAI,IAAA,EAAM,cAAA,EAAgB,OAAA,CAAQ,UAAU,IAAI,IAAA,CAAK,cAAA;AACrD,IAAA,IAAI,IAAA,EAAM,WAAA,EAAa,OAAA,CAAQ,gBAAgB,IAAI,IAAA,CAAK,WAAA;AACxD,IAAA,OAAO,OAAA;AAAA,EACT;AAEA,EAAA,SAAS,UAAA,GAAsB;AAC7B,IAAA,MAAM,IAAA,GAAO,GAAA,CAAI,IAAA,CAAK,IAAA,EAAK;AAC3B,IAAA,OAAO,CAAC,EAAE,IAAA,EAAM,WAAA,IAAe,IAAA,EAAM,MAAA,CAAA;AAAA,EACvC;AAEA,EAAA,SAAS,mBAAmB,EAAA,EAAsB;AAChD,IAAA,eAAA,GAAkB,EAAA;AAAA,EACpB;AAEA,EAAA,OAAO;AAAA,IACL,UAAA;AAAA,IACA,aAAA;AAAA,IACA,eAAA;AAAA,IACA,cAAA;AAAA,IACA,mBAAA;AAAA,IACA,SAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,GACF;AACF","file":"chunk-FVLIANOQ.js","sourcesContent":["/**\n * Auth helper for the auth module — ports VibeControlsMCPAuth from\n * vibecontrols-mcp/src/auth/index.ts to a ctx-aware factory.\n *\n * Differences from the legacy class:\n * - Per-ctx instance (no module-level singleton; each product MCP gets its own)\n * - Token persistence delegated to ctx.auth (StoredAuth file)\n * - Endpoints + clientId resolved via ctx.config.resolveOIDC + ctx.config.read\n * - pendingDeviceCode kept in closure scope (alive for the MCP server process,\n * suitable for stdio's lifetime; HTTP's per-session servers each get their own\n * pending state)\n *\n * Public surface mirrors the legacy class so the lifted auth/tools.ts works\n * without modification: startLogin / completeLogin / selectWorkspace /\n * listWorkspaces / getStatus / logout / ensureAuthenticated / getHeaders /\n * isLoggedIn / setOnTokensChanged.\n */\n\nimport type { McpContext } from '../../core/index.js';\nimport { fetchWorkspaces, issueWorkspaceToken } from '../../core/auth/device-code.js';\n\ninterface PendingDeviceCode {\n deviceCode: string;\n userCode: string;\n verificationUri: string;\n verificationUriComplete: string | null;\n expiresAt: number;\n interval: number;\n clientId: string;\n tokenUrl: string;\n}\n\nexport interface WorkspaceInfo {\n id: string;\n name: string;\n slug: string;\n tenantId: string;\n organizationId: string;\n}\n\nexport interface LoginStartResult {\n status: 'device_code_issued';\n verificationUri: string;\n verificationUriComplete: string | null;\n userCode: string;\n expiresIn: number;\n message: string;\n}\n\nexport interface LoginCompleteResult {\n status: 'authenticated' | 'workspace_selection_required' | 'pending' | 'expired';\n message: string;\n workspaces?: WorkspaceInfo[];\n}\n\nexport interface AuthHelper {\n startLogin(): Promise<LoginStartResult>;\n completeLogin(): Promise<LoginCompleteResult>;\n selectWorkspace(workspaceId: string, organizationId: string): Promise<void>;\n listWorkspaces(): Promise<WorkspaceInfo[]>;\n ensureAuthenticated(): Promise<void>;\n getStatus(): Promise<{\n authenticated: boolean;\n method: string;\n expiresAt: string | null;\n workspaceId: string | null;\n organizationId: string | null;\n workspaceTokenExpiresAt: string | null;\n hasWorkspaceToken: boolean;\n hasPendingLogin: boolean;\n }>;\n logout(): Promise<void>;\n getHeaders(): Record<string, string>;\n isLoggedIn(): boolean;\n setOnTokensChanged(cb: () => void): void;\n}\n\nconst helpers = new WeakMap<McpContext, AuthHelper>();\n\nexport function getAuth(ctx: McpContext): AuthHelper {\n const cached = helpers.get(ctx);\n if (cached) return cached;\n const helper = createAuthHelper(ctx);\n helpers.set(ctx, helper);\n return helper;\n}\n\nfunction createAuthHelper(ctx: McpContext): AuthHelper {\n let pending: PendingDeviceCode | null = null;\n let onTokensChanged: (() => void) | null = null;\n let refreshInProgress: Promise<void> | null = null;\n\n function notify(): void {\n onTokensChanged?.();\n }\n\n async function startLogin(): Promise<LoginStartResult> {\n const { oidcIssuer, clientId } = ctx.config.resolveOIDC();\n const deviceCodeUrl = `${oidcIssuer}/oidc/device/code`;\n const tokenUrl = `${oidcIssuer}/oauth/device/token`;\n\n const response = await fetch(deviceCodeUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({\n client_id: clientId,\n scope: 'openid profile email offline_access',\n }).toString(),\n });\n\n if (!response.ok) {\n const text = await response.text().catch(() => 'Unknown error');\n throw new Error(`Device code request failed (${response.status}): ${text}`);\n }\n\n const data = (await response.json()) as Record<string, unknown>;\n const deviceCode = data['device_code'] as string;\n const userCode = data['user_code'] as string;\n const verificationUri = data['verification_uri'] as string;\n const verificationUriComplete = (data['verification_uri_complete'] as string) ?? null;\n const expiresIn = (data['expires_in'] as number) ?? 900;\n const interval = (data['interval'] as number) ?? 5;\n\n pending = {\n deviceCode,\n userCode,\n verificationUri,\n verificationUriComplete,\n expiresAt: Date.now() + expiresIn * 1000,\n interval,\n clientId,\n tokenUrl,\n };\n\n return {\n status: 'device_code_issued',\n verificationUri,\n verificationUriComplete,\n userCode,\n expiresIn,\n message: `Open ${verificationUriComplete ?? verificationUri} in a browser and enter code: ${userCode}. Then call ${ctx.productName}_auth_complete to finish authentication.`,\n };\n }\n\n async function completeLogin(): Promise<LoginCompleteResult> {\n if (!pending) {\n throw new Error(\n `No pending login flow. Call ${ctx.productName}_auth_login first to start the device code flow.`,\n );\n }\n\n const p = pending;\n if (Date.now() >= p.expiresAt) {\n pending = null;\n return {\n status: 'expired',\n message: `Device code has expired. Call ${ctx.productName}_auth_login again to get a new code.`,\n };\n }\n\n const response = await fetch(p.tokenUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({\n grant_type: 'urn:ietf:params:oauth:grant-type:device_code',\n device_code: p.deviceCode,\n client_id: p.clientId,\n }).toString(),\n });\n\n const data = (await response.json()) as Record<string, unknown>;\n\n if (response.ok && data['access_token']) {\n pending = null;\n const expiresIn = (data['expires_in'] as number) ?? 3600;\n const auth = ctx.auth.read() ?? { accessToken: '', refreshToken: '' };\n ctx.auth.write({\n ...auth,\n accessToken: data['access_token'] as string,\n refreshToken: (data['refresh_token'] as string) ?? '',\n expiresAt: Date.now() + expiresIn * 1000,\n authMethod: 'device_code',\n });\n ctx.gql.reset();\n return await handlePostLogin();\n }\n\n const errorCode = data['error'] as string | undefined;\n if (errorCode === 'authorization_pending') {\n return {\n status: 'pending',\n message: `Still waiting for user to authorize. Open ${p.verificationUriComplete ?? p.verificationUri} and enter code: ${p.userCode}. Then call ${ctx.productName}_auth_complete again.`,\n };\n } else if (errorCode === 'slow_down') {\n p.interval += 5;\n return {\n status: 'pending',\n message: `Authorization server asked to slow down. Wait a moment, then call ${ctx.productName}_auth_complete again.`,\n };\n } else if (errorCode === 'expired_token') {\n pending = null;\n return {\n status: 'expired',\n message: `Device code has expired. Call ${ctx.productName}_auth_login again.`,\n };\n } else if (errorCode === 'access_denied') {\n pending = null;\n throw new Error('Authorization was denied by the user.');\n } else {\n pending = null;\n throw new Error(\n `Device code error: ${(data['error_description'] as string) ?? errorCode ?? 'Unknown'}`,\n );\n }\n }\n\n async function handlePostLogin(): Promise<LoginCompleteResult> {\n try {\n const workspaces = await listWorkspaces();\n if (workspaces.length === 0) {\n notify();\n ctx.logger.info('Device code login successful (no workspaces found)');\n return {\n status: 'authenticated',\n message: `Authentication successful. No workspaces found — use ${ctx.productName}_auth_select_workspace when one is available.`,\n };\n }\n if (workspaces.length === 1) {\n const ws = workspaces[0];\n if (!ws)\n throw new Error('Unexpected: workspaces.length === 1 but workspaces[0] is undefined');\n await issueAndStoreWorkspaceToken(ws.id, ws.organizationId);\n ctx.logger.info('Device code login successful', {\n workspaceId: ws.id,\n workspaceName: ws.name,\n });\n return {\n status: 'authenticated',\n message: `Authentication successful. Workspace \"${ws.name}\" selected automatically.`,\n };\n }\n notify();\n ctx.logger.info('Device code login successful, workspace selection needed');\n return {\n status: 'workspace_selection_required',\n message: `Authentication successful. ${workspaces.length} workspaces available — call ${ctx.productName}_auth_select_workspace to choose one.`,\n workspaces,\n };\n } catch (wsError) {\n notify();\n ctx.logger.warn('Workspace discovery failed after login', {\n error: wsError instanceof Error ? wsError.message : String(wsError),\n });\n return {\n status: 'authenticated',\n message: `Authentication successful. Workspace discovery failed: ${wsError instanceof Error ? wsError.message : String(wsError)}`,\n };\n }\n }\n\n async function listWorkspaces(): Promise<WorkspaceInfo[]> {\n const auth = ctx.auth.read();\n if (!auth?.accessToken) throw new Error('Not authenticated. Please login first.');\n return fetchWorkspaces(ctx.config.read().globalEndpoint, auth.accessToken);\n }\n\n async function issueAndStoreWorkspaceToken(\n workspaceId: string,\n organizationId: string,\n ): Promise<void> {\n const auth = ctx.auth.read();\n if (!auth?.accessToken) throw new Error('Not authenticated.');\n const result = await issueWorkspaceToken(\n ctx.config.read().workspaceEndpoint,\n auth.accessToken,\n workspaceId,\n organizationId,\n );\n ctx.auth.write({\n ...auth,\n workspaceToken: result.token,\n workspaceTokenExpiresAt: new Date(result.expiresAt).getTime(),\n workspaceId,\n organizationId,\n });\n ctx.gql.reset();\n notify();\n }\n\n async function selectWorkspace(workspaceId: string, organizationId: string): Promise<void> {\n const auth = ctx.auth.read();\n if (!auth?.accessToken) throw new Error('Not authenticated. Please login first.');\n await issueAndStoreWorkspaceToken(workspaceId, organizationId);\n ctx.logger.info('Workspace selected', { workspaceId });\n }\n\n async function ensureAuthenticated(): Promise<void> {\n if (refreshInProgress) {\n await refreshInProgress;\n return;\n }\n const doEnsure = async (): Promise<void> => {\n const auth = ctx.auth.read();\n if (auth?.apiKey) return;\n if (!auth?.accessToken) {\n throw new Error(\n `Not authenticated. Call ${ctx.productName}_auth_login to start the login flow, then ${ctx.productName}_auth_complete after authorizing in the browser.`,\n );\n }\n // The shared gql client handles refresh via isTokenExpiringSoon + isWorkspaceTokenExpiringSoon —\n // trigger by issuing a no-op request that goes through the workspace client's refresh path.\n // We simulate a no-op via a cheap query if needed; today the gql wrapper does it lazily,\n // so we just delegate to it on the next request. Nothing to do here.\n };\n refreshInProgress = doEnsure().finally(() => {\n refreshInProgress = null;\n });\n await refreshInProgress;\n }\n\n function getStatus(): Promise<{\n authenticated: boolean;\n method: string;\n expiresAt: string | null;\n workspaceId: string | null;\n organizationId: string | null;\n workspaceTokenExpiresAt: string | null;\n hasWorkspaceToken: boolean;\n hasPendingLogin: boolean;\n }> {\n const auth = ctx.auth.read();\n return Promise.resolve({\n authenticated: !!(auth?.accessToken || auth?.apiKey),\n method: auth?.apiKey ? 'api_key' : auth?.accessToken ? 'oauth_token' : 'none',\n expiresAt: auth?.expiresAt ? new Date(auth.expiresAt).toISOString() : null,\n workspaceId: auth?.workspaceId ?? null,\n organizationId: auth?.organizationId ?? null,\n workspaceTokenExpiresAt: auth?.workspaceTokenExpiresAt\n ? new Date(auth.workspaceTokenExpiresAt).toISOString()\n : null,\n hasWorkspaceToken: !!auth?.workspaceToken,\n hasPendingLogin: !!pending,\n });\n }\n\n async function logout(): Promise<void> {\n pending = null;\n ctx.auth.clear();\n ctx.gql.reset();\n notify();\n ctx.logger.info('Logged out and cleared stored tokens');\n }\n\n function getHeaders(): Record<string, string> {\n const auth = ctx.auth.read();\n const headers: Record<string, string> = {};\n if (auth?.apiKey) headers['X-API-Key'] = auth.apiKey;\n if (auth?.accessToken) headers['Authorization'] = `Bearer ${auth.accessToken}`;\n if (auth?.workspaceToken)\n headers['X-Workspace-Authorization'] = `Bearer ${auth.workspaceToken}`;\n if (auth?.organizationId) headers['x-org-id'] = auth.organizationId;\n if (auth?.workspaceId) headers['x-workspace-id'] = auth.workspaceId;\n return headers;\n }\n\n function isLoggedIn(): boolean {\n const auth = ctx.auth.read();\n return !!(auth?.accessToken || auth?.apiKey);\n }\n\n function setOnTokensChanged(cb: () => void): void {\n onTokensChanged = cb;\n }\n\n return {\n startLogin,\n completeLogin,\n selectWorkspace,\n listWorkspaces,\n ensureAuthenticated,\n getStatus,\n logout,\n getHeaders,\n isLoggedIn,\n setOnTokensChanged,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/modules/auth/legacy-auth.ts"],"names":[],"mappings":";;;AA6EA,IAAM,OAAA,uBAAc,OAAA,EAAgC;AAE7C,SAAS,QAAQ,GAAA,EAA6B;AACnD,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,GAAA,CAAI,GAAG,CAAA;AAC9B,EAAA,IAAI,QAAQ,OAAO,MAAA;AACnB,EAAA,MAAM,MAAA,GAAS,iBAAiB,GAAG,CAAA;AACnC,EAAA,OAAA,CAAQ,GAAA,CAAI,KAAK,MAAM,CAAA;AACvB,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,iBAAiB,GAAA,EAA6B;AACrD,EAAA,IAAI,OAAA,GAAoC,IAAA;AACxC,EAAA,IAAI,eAAA,GAAuC,IAAA;AAC3C,EAAA,IAAI,iBAAA,GAA0C,IAAA;AAE9C,EAAA,SAAS,MAAA,GAAe;AACtB,IAAA,eAAA,IAAkB;AAAA,EACpB;AAEA,EAAA,eAAe,UAAA,GAAwC;AACrD,IAAA,MAAM,EAAE,UAAA,EAAY,QAAA,EAAS,GAAI,GAAA,CAAI,OAAO,WAAA,EAAY;AACxD,IAAA,MAAM,aAAA,GAAgB,GAAG,UAAU,CAAA,iBAAA,CAAA;AACnC,IAAA,MAAM,QAAA,GAAW,GAAG,UAAU,CAAA,mBAAA,CAAA;AAE9B,IAAA,MAAM,QAAA,GAAW,MAAM,KAA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AAW,IAAI,IAAA,CAAK,MAAA;AAC9C,IAAA,IAAI,MAAM,WAAA,EAAa,OAAA,CAAQ,eAAe,CAAA,GAAI,CAAA,OAAA,EAAU,KAAK,WAAW,CAAA,CAAA;AAC5E,IAAA,IAAI,IAAA,EAAM,cAAA;AACR,MAAA,OAAA,CAAQ,2BAA2B,CAAA,GAAI,CAAA,OAAA,EAAU,IAAA,CAAK,cAAc,CAAA,CAAA;AACtE,IAAA,IAAI,IAAA,EAAM,cAAA,EAAgB,OAAA,CAAQ,UAAU,IAAI,IAAA,CAAK,cAAA;AACrD,IAAA,IAAI,IAAA,EAAM,WAAA,EAAa,OAAA,CAAQ,gBAAgB,IAAI,IAAA,CAAK,WAAA;AACxD,IAAA,OAAO,OAAA;AAAA,EACT;AAEA,EAAA,SAAS,UAAA,GAAsB;AAC7B,IAAA,MAAM,IAAA,GAAO,GAAA,CAAI,IAAA,CAAK,IAAA,EAAK;AAC3B,IAAA,OAAO,CAAC,EAAE,IAAA,EAAM,WAAA,IAAe,IAAA,EAAM,MAAA,CAAA;AAAA,EACvC;AAEA,EAAA,SAAS,mBAAmB,EAAA,EAAsB;AAChD,IAAA,eAAA,GAAkB,EAAA;AAAA,EACpB;AAEA,EAAA,OAAO;AAAA,IACL,UAAA;AAAA,IACA,aAAA;AAAA,IACA,eAAA;AAAA,IACA,cAAA;AAAA,IACA,mBAAA;AAAA,IACA,SAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,GACF;AACF","file":"chunk-LUXDBCVJ.js","sourcesContent":["/**\n * Auth helper for the auth module — ports VibeControlsMCPAuth from\n * vibecontrols-mcp/src/auth/index.ts to a ctx-aware factory.\n *\n * Differences from the legacy class:\n * - Per-ctx instance (no module-level singleton; each product MCP gets its own)\n * - Token persistence delegated to ctx.auth (StoredAuth file)\n * - Endpoints + clientId resolved via ctx.config.resolveOIDC + ctx.config.read\n * - pendingDeviceCode kept in closure scope (alive for the MCP server process,\n * suitable for stdio's lifetime; HTTP's per-session servers each get their own\n * pending state)\n *\n * Public surface mirrors the legacy class so the lifted auth/tools.ts works\n * without modification: startLogin / completeLogin / selectWorkspace /\n * listWorkspaces / getStatus / logout / ensureAuthenticated / getHeaders /\n * isLoggedIn / setOnTokensChanged.\n */\n\nimport type { McpContext } from '../../core/index.js';\nimport { fetchWorkspaces, issueWorkspaceToken } from '../../core/auth/device-code.js';\n\ninterface PendingDeviceCode {\n deviceCode: string;\n userCode: string;\n verificationUri: string;\n verificationUriComplete: string | null;\n expiresAt: number;\n interval: number;\n clientId: string;\n tokenUrl: string;\n}\n\nexport interface WorkspaceInfo {\n id: string;\n name: string;\n slug: string;\n tenantId: string;\n organizationId: string;\n}\n\nexport interface LoginStartResult {\n status: 'device_code_issued';\n verificationUri: string;\n verificationUriComplete: string | null;\n userCode: string;\n expiresIn: number;\n message: string;\n}\n\nexport interface LoginCompleteResult {\n status: 'authenticated' | 'workspace_selection_required' | 'pending' | 'expired';\n message: string;\n workspaces?: WorkspaceInfo[];\n}\n\nexport interface AuthHelper {\n startLogin(): Promise<LoginStartResult>;\n completeLogin(): Promise<LoginCompleteResult>;\n selectWorkspace(workspaceId: string, organizationId: string): Promise<void>;\n listWorkspaces(): Promise<WorkspaceInfo[]>;\n ensureAuthenticated(): Promise<void>;\n getStatus(): Promise<{\n authenticated: boolean;\n method: string;\n expiresAt: string | null;\n workspaceId: string | null;\n organizationId: string | null;\n workspaceTokenExpiresAt: string | null;\n hasWorkspaceToken: boolean;\n hasPendingLogin: boolean;\n }>;\n logout(): Promise<void>;\n getHeaders(): Record<string, string>;\n isLoggedIn(): boolean;\n setOnTokensChanged(cb: () => void): void;\n}\n\nconst helpers = new WeakMap<McpContext, AuthHelper>();\n\nexport function getAuth(ctx: McpContext): AuthHelper {\n const cached = helpers.get(ctx);\n if (cached) return cached;\n const helper = createAuthHelper(ctx);\n helpers.set(ctx, helper);\n return helper;\n}\n\nfunction createAuthHelper(ctx: McpContext): AuthHelper {\n let pending: PendingDeviceCode | null = null;\n let onTokensChanged: (() => void) | null = null;\n let refreshInProgress: Promise<void> | null = null;\n\n function notify(): void {\n onTokensChanged?.();\n }\n\n async function startLogin(): Promise<LoginStartResult> {\n const { oidcIssuer, clientId } = ctx.config.resolveOIDC();\n const deviceCodeUrl = `${oidcIssuer}/oidc/device/code`;\n const tokenUrl = `${oidcIssuer}/oauth/device/token`;\n\n const response = await fetch(deviceCodeUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({\n client_id: clientId,\n scope: 'openid profile email offline_access',\n }).toString(),\n });\n\n if (!response.ok) {\n const text = await response.text().catch(() => 'Unknown error');\n throw new Error(`Device code request failed (${response.status}): ${text}`);\n }\n\n const data = (await response.json()) as Record<string, unknown>;\n const deviceCode = data['device_code'] as string;\n const userCode = data['user_code'] as string;\n const verificationUri = data['verification_uri'] as string;\n const verificationUriComplete = (data['verification_uri_complete'] as string) ?? null;\n const expiresIn = (data['expires_in'] as number) ?? 900;\n const interval = (data['interval'] as number) ?? 5;\n\n pending = {\n deviceCode,\n userCode,\n verificationUri,\n verificationUriComplete,\n expiresAt: Date.now() + expiresIn * 1000,\n interval,\n clientId,\n tokenUrl,\n };\n\n return {\n status: 'device_code_issued',\n verificationUri,\n verificationUriComplete,\n userCode,\n expiresIn,\n message: `Open ${verificationUriComplete ?? verificationUri} in a browser and enter code: ${userCode}. Then call ${ctx.productName}_auth_complete to finish authentication.`,\n };\n }\n\n async function completeLogin(): Promise<LoginCompleteResult> {\n if (!pending) {\n throw new Error(\n `No pending login flow. Call ${ctx.productName}_auth_login first to start the device code flow.`,\n );\n }\n\n const p = pending;\n if (Date.now() >= p.expiresAt) {\n pending = null;\n return {\n status: 'expired',\n message: `Device code has expired. Call ${ctx.productName}_auth_login again to get a new code.`,\n };\n }\n\n const response = await fetch(p.tokenUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({\n grant_type: 'urn:ietf:params:oauth:grant-type:device_code',\n device_code: p.deviceCode,\n client_id: p.clientId,\n }).toString(),\n });\n\n const data = (await response.json()) as Record<string, unknown>;\n\n if (response.ok && data['access_token']) {\n pending = null;\n const expiresIn = (data['expires_in'] as number) ?? 3600;\n const auth = ctx.auth.read() ?? { accessToken: '', refreshToken: '' };\n ctx.auth.write({\n ...auth,\n accessToken: data['access_token'] as string,\n refreshToken: (data['refresh_token'] as string) ?? '',\n expiresAt: Date.now() + expiresIn * 1000,\n authMethod: 'device_code',\n });\n ctx.gql.reset();\n return await handlePostLogin();\n }\n\n const errorCode = data['error'] as string | undefined;\n if (errorCode === 'authorization_pending') {\n return {\n status: 'pending',\n message: `Still waiting for user to authorize. Open ${p.verificationUriComplete ?? p.verificationUri} and enter code: ${p.userCode}. Then call ${ctx.productName}_auth_complete again.`,\n };\n } else if (errorCode === 'slow_down') {\n p.interval += 5;\n return {\n status: 'pending',\n message: `Authorization server asked to slow down. Wait a moment, then call ${ctx.productName}_auth_complete again.`,\n };\n } else if (errorCode === 'expired_token') {\n pending = null;\n return {\n status: 'expired',\n message: `Device code has expired. Call ${ctx.productName}_auth_login again.`,\n };\n } else if (errorCode === 'access_denied') {\n pending = null;\n throw new Error('Authorization was denied by the user.');\n } else {\n pending = null;\n throw new Error(\n `Device code error: ${(data['error_description'] as string) ?? errorCode ?? 'Unknown'}`,\n );\n }\n }\n\n async function handlePostLogin(): Promise<LoginCompleteResult> {\n try {\n const workspaces = await listWorkspaces();\n if (workspaces.length === 0) {\n notify();\n ctx.logger.info('Device code login successful (no workspaces found)');\n return {\n status: 'authenticated',\n message: `Authentication successful. No workspaces found — use ${ctx.productName}_auth_select_workspace when one is available.`,\n };\n }\n if (workspaces.length === 1) {\n const ws = workspaces[0];\n if (!ws)\n throw new Error('Unexpected: workspaces.length === 1 but workspaces[0] is undefined');\n await issueAndStoreWorkspaceToken(ws.id, ws.organizationId);\n ctx.logger.info('Device code login successful', {\n workspaceId: ws.id,\n workspaceName: ws.name,\n });\n return {\n status: 'authenticated',\n message: `Authentication successful. Workspace \"${ws.name}\" selected automatically.`,\n };\n }\n notify();\n ctx.logger.info('Device code login successful, workspace selection needed');\n return {\n status: 'workspace_selection_required',\n message: `Authentication successful. ${workspaces.length} workspaces available — call ${ctx.productName}_auth_select_workspace to choose one.`,\n workspaces,\n };\n } catch (wsError) {\n notify();\n ctx.logger.warn('Workspace discovery failed after login', {\n error: wsError instanceof Error ? wsError.message : String(wsError),\n });\n return {\n status: 'authenticated',\n message: `Authentication successful. Workspace discovery failed: ${wsError instanceof Error ? wsError.message : String(wsError)}`,\n };\n }\n }\n\n async function listWorkspaces(): Promise<WorkspaceInfo[]> {\n const auth = ctx.auth.read();\n if (!auth?.accessToken) throw new Error('Not authenticated. Please login first.');\n return fetchWorkspaces(ctx.config.read().globalEndpoint, auth.accessToken);\n }\n\n async function issueAndStoreWorkspaceToken(\n workspaceId: string,\n organizationId: string,\n ): Promise<void> {\n const auth = ctx.auth.read();\n if (!auth?.accessToken) throw new Error('Not authenticated.');\n const result = await issueWorkspaceToken(\n ctx.config.read().workspaceEndpoint,\n auth.accessToken,\n workspaceId,\n organizationId,\n );\n ctx.auth.write({\n ...auth,\n workspaceToken: result.token,\n workspaceTokenExpiresAt: new Date(result.expiresAt).getTime(),\n workspaceId,\n organizationId,\n });\n ctx.gql.reset();\n notify();\n }\n\n async function selectWorkspace(workspaceId: string, organizationId: string): Promise<void> {\n const auth = ctx.auth.read();\n if (!auth?.accessToken) throw new Error('Not authenticated. Please login first.');\n await issueAndStoreWorkspaceToken(workspaceId, organizationId);\n ctx.logger.info('Workspace selected', { workspaceId });\n }\n\n async function ensureAuthenticated(): Promise<void> {\n if (refreshInProgress) {\n await refreshInProgress;\n return;\n }\n const doEnsure = async (): Promise<void> => {\n const auth = ctx.auth.read();\n if (auth?.apiKey) return;\n if (!auth?.accessToken) {\n throw new Error(\n `Not authenticated. Call ${ctx.productName}_auth_login to start the login flow, then ${ctx.productName}_auth_complete after authorizing in the browser.`,\n );\n }\n // The shared gql client handles refresh via isTokenExpiringSoon + isWorkspaceTokenExpiringSoon —\n // trigger by issuing a no-op request that goes through the workspace client's refresh path.\n // We simulate a no-op via a cheap query if needed; today the gql wrapper does it lazily,\n // so we just delegate to it on the next request. Nothing to do here.\n };\n refreshInProgress = doEnsure().finally(() => {\n refreshInProgress = null;\n });\n await refreshInProgress;\n }\n\n function getStatus(): Promise<{\n authenticated: boolean;\n method: string;\n expiresAt: string | null;\n workspaceId: string | null;\n organizationId: string | null;\n workspaceTokenExpiresAt: string | null;\n hasWorkspaceToken: boolean;\n hasPendingLogin: boolean;\n }> {\n const auth = ctx.auth.read();\n return Promise.resolve({\n authenticated: !!(auth?.accessToken || auth?.apiKey),\n method: auth?.apiKey ? 'api_key' : auth?.accessToken ? 'oauth_token' : 'none',\n expiresAt: auth?.expiresAt ? new Date(auth.expiresAt).toISOString() : null,\n workspaceId: auth?.workspaceId ?? null,\n organizationId: auth?.organizationId ?? null,\n workspaceTokenExpiresAt: auth?.workspaceTokenExpiresAt\n ? new Date(auth.workspaceTokenExpiresAt).toISOString()\n : null,\n hasWorkspaceToken: !!auth?.workspaceToken,\n hasPendingLogin: !!pending,\n });\n }\n\n async function logout(): Promise<void> {\n pending = null;\n ctx.auth.clear();\n ctx.gql.reset();\n notify();\n ctx.logger.info('Logged out and cleared stored tokens');\n }\n\n function getHeaders(): Record<string, string> {\n const auth = ctx.auth.read();\n const headers: Record<string, string> = {};\n if (auth?.apiKey) headers['X-API-Key'] = auth.apiKey;\n if (auth?.accessToken) headers['Authorization'] = `Bearer ${auth.accessToken}`;\n if (auth?.workspaceToken)\n headers['X-Workspace-Authorization'] = `Bearer ${auth.workspaceToken}`;\n if (auth?.organizationId) headers['x-org-id'] = auth.organizationId;\n if (auth?.workspaceId) headers['x-workspace-id'] = auth.workspaceId;\n return headers;\n }\n\n function isLoggedIn(): boolean {\n const auth = ctx.auth.read();\n return !!(auth?.accessToken || auth?.apiKey);\n }\n\n function setOnTokensChanged(cb: () => void): void {\n onTokensChanged = cb;\n }\n\n return {\n startLogin,\n completeLogin,\n selectWorkspace,\n listWorkspaces,\n ensureAuthenticated,\n getStatus,\n logout,\n getHeaders,\n isLoggedIn,\n setOnTokensChanged,\n };\n}\n"]}
|
|
@@ -10,6 +10,31 @@ import { z } from 'zod';
|
|
|
10
10
|
|
|
11
11
|
// src/core/auth/store.ts
|
|
12
12
|
var TOKEN_BUFFER_MS = 5 * 60 * 1e3;
|
|
13
|
+
function decodeJwtPayload(token) {
|
|
14
|
+
if (!token) return null;
|
|
15
|
+
const parts = token.split(".");
|
|
16
|
+
if (parts.length !== 3) return null;
|
|
17
|
+
try {
|
|
18
|
+
const payload = JSON.parse(
|
|
19
|
+
Buffer.from(parts[1].replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8")
|
|
20
|
+
);
|
|
21
|
+
return payload && typeof payload === "object" ? payload : null;
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function jwtExpiryMs(token) {
|
|
27
|
+
const exp = decodeJwtPayload(token)?.exp;
|
|
28
|
+
return typeof exp === "number" && Number.isFinite(exp) ? exp * 1e3 : null;
|
|
29
|
+
}
|
|
30
|
+
function accessTokenExpiry(auth) {
|
|
31
|
+
if (!auth) return null;
|
|
32
|
+
return auth.expiresAt ?? jwtExpiryMs(auth.accessToken);
|
|
33
|
+
}
|
|
34
|
+
function workspaceTokenExpiry(auth) {
|
|
35
|
+
if (!auth?.workspaceToken) return auth?.workspaceTokenExpiresAt ?? null;
|
|
36
|
+
return auth.workspaceTokenExpiresAt ?? jwtExpiryMs(auth.workspaceToken);
|
|
37
|
+
}
|
|
13
38
|
function createAuthStore(configDir, authFileName2 = "auth.json") {
|
|
14
39
|
const authFile = join(configDir, authFileName2);
|
|
15
40
|
function ensureConfigDir() {
|
|
@@ -41,24 +66,24 @@ function createAuthStore(configDir, authFileName2 = "auth.json") {
|
|
|
41
66
|
}
|
|
42
67
|
}
|
|
43
68
|
function isTokenExpired() {
|
|
44
|
-
const
|
|
45
|
-
if (!
|
|
46
|
-
return Date.now() >=
|
|
69
|
+
const expiresAt = accessTokenExpiry(read());
|
|
70
|
+
if (!expiresAt) return false;
|
|
71
|
+
return Date.now() >= expiresAt;
|
|
47
72
|
}
|
|
48
73
|
function isTokenExpiringSoon() {
|
|
49
|
-
const
|
|
50
|
-
if (!
|
|
51
|
-
return Date.now() + TOKEN_BUFFER_MS >=
|
|
74
|
+
const expiresAt = accessTokenExpiry(read());
|
|
75
|
+
if (!expiresAt) return false;
|
|
76
|
+
return Date.now() + TOKEN_BUFFER_MS >= expiresAt;
|
|
52
77
|
}
|
|
53
78
|
function isWorkspaceTokenExpired() {
|
|
54
|
-
const
|
|
55
|
-
if (!
|
|
56
|
-
return Date.now() >=
|
|
79
|
+
const expiresAt = workspaceTokenExpiry(read());
|
|
80
|
+
if (!expiresAt) return false;
|
|
81
|
+
return Date.now() >= expiresAt;
|
|
57
82
|
}
|
|
58
83
|
function isWorkspaceTokenExpiringSoon() {
|
|
59
|
-
const
|
|
60
|
-
if (!
|
|
61
|
-
return Date.now() + TOKEN_BUFFER_MS >=
|
|
84
|
+
const expiresAt = workspaceTokenExpiry(read());
|
|
85
|
+
if (!expiresAt) return false;
|
|
86
|
+
return Date.now() + TOKEN_BUFFER_MS >= expiresAt;
|
|
62
87
|
}
|
|
63
88
|
function isAuthenticated() {
|
|
64
89
|
const auth = read();
|
|
@@ -67,19 +92,8 @@ function createAuthStore(configDir, authFileName2 = "auth.json") {
|
|
|
67
92
|
return !isTokenExpired();
|
|
68
93
|
}
|
|
69
94
|
function getActorUserId() {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
if (!token) return null;
|
|
73
|
-
const parts = token.split(".");
|
|
74
|
-
if (parts.length !== 3) return null;
|
|
75
|
-
try {
|
|
76
|
-
const payload = JSON.parse(
|
|
77
|
-
Buffer.from(parts[1].replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8")
|
|
78
|
-
);
|
|
79
|
-
return typeof payload.sub === "string" ? payload.sub : null;
|
|
80
|
-
} catch {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
95
|
+
const sub = decodeJwtPayload(read()?.accessToken)?.sub;
|
|
96
|
+
return typeof sub === "string" ? sub : null;
|
|
83
97
|
}
|
|
84
98
|
return {
|
|
85
99
|
read,
|
|
@@ -336,6 +350,30 @@ function isNetworkOrServerError(error) {
|
|
|
336
350
|
}
|
|
337
351
|
return false;
|
|
338
352
|
}
|
|
353
|
+
var GqlRequestError = class extends Error {
|
|
354
|
+
status;
|
|
355
|
+
authFailure;
|
|
356
|
+
constructor(message, status, authFailure) {
|
|
357
|
+
super(message);
|
|
358
|
+
this.name = "GqlRequestError";
|
|
359
|
+
this.status = status;
|
|
360
|
+
this.authFailure = authFailure;
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
function toGqlRequestError(error) {
|
|
364
|
+
let status;
|
|
365
|
+
let authFailure;
|
|
366
|
+
if (error && typeof error === "object" && "response" in error) {
|
|
367
|
+
const resp = error.response;
|
|
368
|
+
if (typeof resp?.status === "number") status = resp.status;
|
|
369
|
+
const failure = resp?.errors?.find((e) => typeof e.extensions?.authFailure === "string")?.extensions?.authFailure;
|
|
370
|
+
if (typeof failure === "string") authFailure = failure;
|
|
371
|
+
}
|
|
372
|
+
return new GqlRequestError(extractGqlErrorMessage(error), status, authFailure);
|
|
373
|
+
}
|
|
374
|
+
function isExpiredCredentialError(error) {
|
|
375
|
+
return error instanceof GqlRequestError && error.authFailure === "CREDENTIAL_EXPIRED";
|
|
376
|
+
}
|
|
339
377
|
function extractGqlErrorMessage(error) {
|
|
340
378
|
if (error && typeof error === "object" && "response" in error) {
|
|
341
379
|
const resp = error;
|
|
@@ -388,7 +426,7 @@ async function executeWithRetry(client, document, variables) {
|
|
|
388
426
|
break;
|
|
389
427
|
}
|
|
390
428
|
}
|
|
391
|
-
throw
|
|
429
|
+
throw toGqlRequestError(lastError);
|
|
392
430
|
}
|
|
393
431
|
function createGqlClients(config, authStore) {
|
|
394
432
|
let workspaceClient = null;
|
|
@@ -450,7 +488,7 @@ function createGqlClients(config, authStore) {
|
|
|
450
488
|
}
|
|
451
489
|
async function refreshWorkspaceToken() {
|
|
452
490
|
const auth = authStore.read();
|
|
453
|
-
if (!auth?.accessToken || !auth.workspaceId || !auth.organizationId) return;
|
|
491
|
+
if (!auth?.accessToken || !auth.workspaceId || !auth.organizationId) return false;
|
|
454
492
|
const cfg = config.read();
|
|
455
493
|
try {
|
|
456
494
|
const result = await issueWorkspaceToken(
|
|
@@ -465,7 +503,9 @@ function createGqlClients(config, authStore) {
|
|
|
465
503
|
workspaceTokenExpiresAt: new Date(result.expiresAt).getTime()
|
|
466
504
|
});
|
|
467
505
|
workspaceClient = null;
|
|
506
|
+
return true;
|
|
468
507
|
} catch {
|
|
508
|
+
return false;
|
|
469
509
|
}
|
|
470
510
|
}
|
|
471
511
|
async function ensureFreshTokens() {
|
|
@@ -478,12 +518,22 @@ function createGqlClients(config, authStore) {
|
|
|
478
518
|
await refreshWorkspaceToken();
|
|
479
519
|
}
|
|
480
520
|
}
|
|
521
|
+
async function requestWorkspace(document, variables) {
|
|
522
|
+
const { workspace: ws } = workspaceClient ? { workspace: workspaceClient } : init();
|
|
523
|
+
ws.setHeaders(getWorkspaceHeaders(authStore.read()));
|
|
524
|
+
return executeWithRetry(ws, document, variables);
|
|
525
|
+
}
|
|
481
526
|
const workspace = {
|
|
482
527
|
async request(document, variables) {
|
|
483
528
|
await ensureFreshTokens();
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
529
|
+
try {
|
|
530
|
+
return await requestWorkspace(document, variables);
|
|
531
|
+
} catch (error) {
|
|
532
|
+
if (!isExpiredCredentialError(error) || authStore.read()?.apiKey) throw error;
|
|
533
|
+
if (authStore.isTokenExpiringSoon()) await refreshPlatformToken();
|
|
534
|
+
if (!await refreshWorkspaceToken()) throw error;
|
|
535
|
+
return requestWorkspace(document, variables);
|
|
536
|
+
}
|
|
487
537
|
}
|
|
488
538
|
};
|
|
489
539
|
const global = {
|
|
@@ -1102,6 +1152,6 @@ function stringifyCause(cause) {
|
|
|
1102
1152
|
}
|
|
1103
1153
|
}
|
|
1104
1154
|
|
|
1105
|
-
export { CircularDependencyError, DESTRUCTIVE_NAME_VERBS, McpAuthError, McpInternalError, McpUserError, MissingDependencyError, TOOL_NAME_LIMIT, buildContext, clientCredentialsFlow, createAuthStore, createConfigStore, createGqlClients, createLogger, createMcpServer, createProgress, errorResult, extractGqlErrorMessage, fetchWorkspaces, inferDestructiveHint, inferReadOnlyHint, issueWorkspaceToken, jsonResult, mcpPromptName, mcpResourceUri, mcpToolName, pollDeviceTokenOnce, registerTool, scopeToolFilter, sortModules, startDeviceCodeFlow, textResult, toServerCapabilities, toolArgsSha256, unionCapabilities, withToolAnnotations, wrapServerWithToolGovernance };
|
|
1106
|
-
//# sourceMappingURL=chunk-
|
|
1107
|
-
//# sourceMappingURL=chunk-
|
|
1155
|
+
export { CircularDependencyError, DESTRUCTIVE_NAME_VERBS, GqlRequestError, McpAuthError, McpInternalError, McpUserError, MissingDependencyError, TOOL_NAME_LIMIT, buildContext, clientCredentialsFlow, createAuthStore, createConfigStore, createGqlClients, createLogger, createMcpServer, createProgress, errorResult, extractGqlErrorMessage, fetchWorkspaces, inferDestructiveHint, inferReadOnlyHint, isExpiredCredentialError, issueWorkspaceToken, jsonResult, jwtExpiryMs, mcpPromptName, mcpResourceUri, mcpToolName, pollDeviceTokenOnce, registerTool, scopeToolFilter, sortModules, startDeviceCodeFlow, textResult, toServerCapabilities, toolArgsSha256, unionCapabilities, withToolAnnotations, wrapServerWithToolGovernance };
|
|
1156
|
+
//# sourceMappingURL=chunk-WYCRYHHY.js.map
|
|
1157
|
+
//# sourceMappingURL=chunk-WYCRYHHY.js.map
|