@kontext-dev/js-sdk 1.0.0 → 1.1.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/dist/adapters/ai/index.cjs +12 -2
- package/dist/adapters/ai/index.cjs.map +1 -1
- package/dist/adapters/ai/index.js +12 -2
- package/dist/adapters/ai/index.js.map +1 -1
- package/dist/adapters/cloudflare/index.cjs +13 -0
- package/dist/adapters/cloudflare/index.cjs.map +1 -1
- package/dist/adapters/cloudflare/index.js +13 -0
- package/dist/adapters/cloudflare/index.js.map +1 -1
- package/dist/adapters/cloudflare/react.cjs +12 -2
- package/dist/adapters/cloudflare/react.cjs.map +1 -1
- package/dist/adapters/cloudflare/react.js +12 -2
- package/dist/adapters/cloudflare/react.js.map +1 -1
- package/dist/adapters/react/index.cjs +12 -2
- package/dist/adapters/react/index.cjs.map +1 -1
- package/dist/adapters/react/index.js +12 -2
- package/dist/adapters/react/index.js.map +1 -1
- package/dist/client/index.cjs +89 -68
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +2 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +90 -70
- package/dist/client/index.js.map +1 -1
- package/dist/errors.cjs +78 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +7 -1
- package/dist/errors.d.ts +7 -1
- package/dist/errors.js +78 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.cjs +124 -86
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +125 -87
- package/dist/index.js.map +1 -1
- package/dist/{kontext-CgIBANFo.d.cts → kontext-CBPuE-hq.d.cts} +3 -0
- package/dist/{kontext-CgIBANFo.d.ts → kontext-CBPuE-hq.d.ts} +3 -0
- package/dist/management/index.cjs +15 -0
- package/dist/management/index.cjs.map +1 -1
- package/dist/management/index.d.cts +2 -2
- package/dist/management/index.d.ts +2 -2
- package/dist/management/index.js +15 -1
- package/dist/management/index.js.map +1 -1
- package/dist/mcp/index.cjs +13 -2
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.cts +3 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.js +14 -3
- package/dist/mcp/index.js.map +1 -1
- package/dist/oauth/index.cjs +12 -2
- package/dist/oauth/index.cjs.map +1 -1
- package/dist/oauth/index.d.cts +1 -1
- package/dist/oauth/index.d.ts +1 -1
- package/dist/oauth/index.js +12 -2
- package/dist/oauth/index.js.map +1 -1
- package/dist/server/index.cjs +47 -20
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +48 -21
- package/dist/server/index.js.map +1 -1
- package/dist/{types-C6ep5fVw.d.cts → types-DicGI7ix.d.cts} +21 -1
- package/dist/{types-C6ep5fVw.d.ts → types-DicGI7ix.d.ts} +21 -1
- package/package.json +1 -1
package/dist/server/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { I as IntegrationCredential, a as IntegrationName, b as IntegrationResolvedCredentials, K as KnownIntegration, c as Kontext, d as KontextOptions, M as McpServerFactory, e as McpServerOrFactory, f as MiddlewareOptions } from '../kontext-
|
|
1
|
+
export { I as IntegrationCredential, a as IntegrationName, b as IntegrationResolvedCredentials, K as KnownIntegration, c as Kontext, d as KontextOptions, M as McpServerFactory, e as McpServerOrFactory, f as MiddlewareOptions } from '../kontext-CBPuE-hq.cjs';
|
|
2
2
|
export { K as KontextTokenVerifier } from '../verifier-CoJmYiw3.cjs';
|
|
3
3
|
export { IntegrationConnectionRequiredError } from '../errors.cjs';
|
|
4
|
-
export { T as TokenExchangeRequest, a as TokenExchangeResponse } from '../types-
|
|
4
|
+
export { T as TokenExchangeRequest, a as TokenExchangeResponse } from '../types-DicGI7ix.cjs';
|
|
5
5
|
export { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js';
|
|
6
6
|
export { OAuthTokenVerifier } from '@modelcontextprotocol/sdk/server/auth/provider.js';
|
|
7
7
|
import 'express';
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { I as IntegrationCredential, a as IntegrationName, b as IntegrationResolvedCredentials, K as KnownIntegration, c as Kontext, d as KontextOptions, M as McpServerFactory, e as McpServerOrFactory, f as MiddlewareOptions } from '../kontext-
|
|
1
|
+
export { I as IntegrationCredential, a as IntegrationName, b as IntegrationResolvedCredentials, K as KnownIntegration, c as Kontext, d as KontextOptions, M as McpServerFactory, e as McpServerOrFactory, f as MiddlewareOptions } from '../kontext-CBPuE-hq.js';
|
|
2
2
|
export { K as KontextTokenVerifier } from '../verifier-CoJmYiw3.js';
|
|
3
3
|
export { IntegrationConnectionRequiredError } from '../errors.js';
|
|
4
|
-
export { T as TokenExchangeRequest, a as TokenExchangeResponse } from '../types-
|
|
4
|
+
export { T as TokenExchangeRequest, a as TokenExchangeResponse } from '../types-DicGI7ix.js';
|
|
5
5
|
export { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js';
|
|
6
6
|
export { OAuthTokenVerifier } from '@modelcontextprotocol/sdk/server/auth/provider.js';
|
|
7
7
|
import 'express';
|
package/dist/server/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'crypto';
|
|
2
2
|
import { createRequire } from 'module';
|
|
3
3
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
4
|
-
import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
import { ErrorCode, isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
import { mcpAuthMetadataRouter, getOAuthProtectedResourceMetadataUrl } from '@modelcontextprotocol/sdk/server/auth/router.js';
|
|
6
6
|
import { requireBearerAuth } from '@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js';
|
|
7
7
|
import { InvalidTokenError } from '@modelcontextprotocol/sdk/server/auth/errors.js';
|
|
@@ -12,8 +12,7 @@ import { jwtVerify, errors, decodeProtectedHeader, createRemoteJWKSet } from 'jo
|
|
|
12
12
|
// src/management/types.ts
|
|
13
13
|
var TOKEN_EXCHANGE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:token-exchange";
|
|
14
14
|
var TOKEN_TYPE_ACCESS_TOKEN = "urn:ietf:params:oauth:token-type:access_token";
|
|
15
|
-
|
|
16
|
-
// src/errors.ts
|
|
15
|
+
var TOKEN_TYPE_USER_ID = "urn:kontext:user-id";
|
|
17
16
|
var KontextError = class extends Error {
|
|
18
17
|
/** Brand field for type narrowing without instanceof */
|
|
19
18
|
kontextError = true;
|
|
@@ -84,6 +83,17 @@ var IntegrationConnectionRequiredError = class extends KontextError {
|
|
|
84
83
|
this.connectUrl = options?.connectUrl;
|
|
85
84
|
}
|
|
86
85
|
};
|
|
86
|
+
({
|
|
87
|
+
[ErrorCode.ParseError]: { },
|
|
88
|
+
[ErrorCode.InvalidRequest]: { },
|
|
89
|
+
[ErrorCode.MethodNotFound]: { },
|
|
90
|
+
[ErrorCode.InvalidParams]: { },
|
|
91
|
+
[ErrorCode.InternalError]: {
|
|
92
|
+
},
|
|
93
|
+
[ErrorCode.RequestTimeout]: {
|
|
94
|
+
},
|
|
95
|
+
[ErrorCode.ConnectionClosed]: { }
|
|
96
|
+
});
|
|
87
97
|
|
|
88
98
|
// src/oauth/token-exchange.ts
|
|
89
99
|
async function exchangeToken(config, subjectToken, resource, scope, subjectTokenType = TOKEN_TYPE_ACCESS_TOKEN) {
|
|
@@ -563,7 +573,7 @@ var Kontext = class _Kontext {
|
|
|
563
573
|
oauthMetadata = null;
|
|
564
574
|
metadataFetchedAt = 0;
|
|
565
575
|
metadataPromise = null;
|
|
566
|
-
// Token exchange caching: keyed by `${integration}\0${subjectToken}`
|
|
576
|
+
// Token exchange caching: keyed by `${mode}\0${integration}\0${subjectToken}`
|
|
567
577
|
credentialCache = /* @__PURE__ */ new Map();
|
|
568
578
|
resolvedCredentialCache = /* @__PURE__ */ new Map();
|
|
569
579
|
runtimeAuthCache = /* @__PURE__ */ new Map();
|
|
@@ -721,23 +731,28 @@ var Kontext = class _Kontext {
|
|
|
721
731
|
router.delete(mcpPath, mcpHandler.delete);
|
|
722
732
|
return router;
|
|
723
733
|
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
734
|
+
async require(integration, tokenOrOpts) {
|
|
735
|
+
let isUserIdMode = false;
|
|
736
|
+
let subjectToken = "";
|
|
737
|
+
if (typeof tokenOrOpts === "string") {
|
|
738
|
+
subjectToken = tokenOrOpts;
|
|
739
|
+
} else if (tokenOrOpts !== null && typeof tokenOrOpts === "object" && typeof tokenOrOpts.userId === "string") {
|
|
740
|
+
isUserIdMode = true;
|
|
741
|
+
subjectToken = tokenOrOpts.userId.trim();
|
|
742
|
+
if (!subjectToken) {
|
|
743
|
+
throw new TypeError(
|
|
744
|
+
"Kontext.require() expects a non-empty userId when called with { userId }."
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
} else {
|
|
748
|
+
throw new TypeError(
|
|
749
|
+
"Kontext.require() expects a token string or { userId: string }."
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
const subjectTokenType = isUserIdMode ? TOKEN_TYPE_USER_ID : void 0;
|
|
738
753
|
const now = Date.now();
|
|
739
754
|
this.evictExpiredCredentials(now);
|
|
740
|
-
const cacheKey =
|
|
755
|
+
const cacheKey = isUserIdMode ? `u\0${integration}\0${subjectToken}` : `t\0${integration}\0${subjectToken}`;
|
|
741
756
|
const cached = this.credentialCache.get(cacheKey);
|
|
742
757
|
if (cached && now < cached.expiresAt) {
|
|
743
758
|
this.credentialCache.delete(cacheKey);
|
|
@@ -754,13 +769,25 @@ var Kontext = class _Kontext {
|
|
|
754
769
|
};
|
|
755
770
|
let response;
|
|
756
771
|
try {
|
|
757
|
-
response = await exchangeToken(
|
|
772
|
+
response = await exchangeToken(
|
|
773
|
+
exchangeConfig,
|
|
774
|
+
subjectToken,
|
|
775
|
+
integration,
|
|
776
|
+
void 0,
|
|
777
|
+
subjectTokenType
|
|
778
|
+
);
|
|
758
779
|
} catch (err) {
|
|
759
780
|
if (err instanceof OAuthError) {
|
|
760
781
|
if (err.errorCode === "integration_required" || err.message.includes("not connected") || err.message.includes("expired") && err.message.includes("reconnect")) {
|
|
761
782
|
const integrationId = err.meta.integrationId || integration;
|
|
783
|
+
if (isUserIdMode) {
|
|
784
|
+
throw new IntegrationConnectionRequiredError(integrationId, {
|
|
785
|
+
integrationName: err.meta.integrationName,
|
|
786
|
+
message: err.message
|
|
787
|
+
});
|
|
788
|
+
}
|
|
762
789
|
const connectUrl = await this.fetchConnectUrl(
|
|
763
|
-
|
|
790
|
+
subjectToken,
|
|
764
791
|
integrationId,
|
|
765
792
|
exchangeConfig
|
|
766
793
|
);
|