@mcp-z/client 1.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/AGENTS.md +159 -0
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/cjs/auth/capability-discovery.d.cts +25 -0
- package/dist/cjs/auth/capability-discovery.d.ts +25 -0
- package/dist/cjs/auth/capability-discovery.js +280 -0
- package/dist/cjs/auth/capability-discovery.js.map +1 -0
- package/dist/cjs/auth/index.d.cts +9 -0
- package/dist/cjs/auth/index.d.ts +9 -0
- package/dist/cjs/auth/index.js +28 -0
- package/dist/cjs/auth/index.js.map +1 -0
- package/dist/cjs/auth/interactive-oauth-flow.d.cts +58 -0
- package/dist/cjs/auth/interactive-oauth-flow.d.ts +58 -0
- package/dist/cjs/auth/interactive-oauth-flow.js +537 -0
- package/dist/cjs/auth/interactive-oauth-flow.js.map +1 -0
- package/dist/cjs/auth/oauth-callback-listener.d.cts +56 -0
- package/dist/cjs/auth/oauth-callback-listener.d.ts +56 -0
- package/dist/cjs/auth/oauth-callback-listener.js +333 -0
- package/dist/cjs/auth/oauth-callback-listener.js.map +1 -0
- package/dist/cjs/auth/pkce.d.cts +17 -0
- package/dist/cjs/auth/pkce.d.ts +17 -0
- package/dist/cjs/auth/pkce.js +192 -0
- package/dist/cjs/auth/pkce.js.map +1 -0
- package/dist/cjs/auth/rfc9728-discovery.d.cts +34 -0
- package/dist/cjs/auth/rfc9728-discovery.d.ts +34 -0
- package/dist/cjs/auth/rfc9728-discovery.js +436 -0
- package/dist/cjs/auth/rfc9728-discovery.js.map +1 -0
- package/dist/cjs/auth/types.d.cts +137 -0
- package/dist/cjs/auth/types.d.ts +137 -0
- package/dist/cjs/auth/types.js +9 -0
- package/dist/cjs/auth/types.js.map +1 -0
- package/dist/cjs/client-helpers.d.cts +55 -0
- package/dist/cjs/client-helpers.d.ts +55 -0
- package/dist/cjs/client-helpers.js +128 -0
- package/dist/cjs/client-helpers.js.map +1 -0
- package/dist/cjs/config/server-loader.d.cts +27 -0
- package/dist/cjs/config/server-loader.d.ts +27 -0
- package/dist/cjs/config/server-loader.js +111 -0
- package/dist/cjs/config/server-loader.js.map +1 -0
- package/dist/cjs/config/validate-config.d.cts +15 -0
- package/dist/cjs/config/validate-config.d.ts +15 -0
- package/dist/cjs/config/validate-config.js +128 -0
- package/dist/cjs/config/validate-config.js.map +1 -0
- package/dist/cjs/connection/connect-client.d.cts +59 -0
- package/dist/cjs/connection/connect-client.d.ts +59 -0
- package/dist/cjs/connection/connect-client.js +536 -0
- package/dist/cjs/connection/connect-client.js.map +1 -0
- package/dist/cjs/connection/existing-process-transport.d.cts +40 -0
- package/dist/cjs/connection/existing-process-transport.d.ts +40 -0
- package/dist/cjs/connection/existing-process-transport.js +274 -0
- package/dist/cjs/connection/existing-process-transport.js.map +1 -0
- package/dist/cjs/connection/types.d.cts +61 -0
- package/dist/cjs/connection/types.d.ts +61 -0
- package/dist/cjs/connection/types.js +53 -0
- package/dist/cjs/connection/types.js.map +1 -0
- package/dist/cjs/connection/wait-for-http-ready.d.cts +15 -0
- package/dist/cjs/connection/wait-for-http-ready.d.ts +15 -0
- package/dist/cjs/connection/wait-for-http-ready.js +232 -0
- package/dist/cjs/connection/wait-for-http-ready.js.map +1 -0
- package/dist/cjs/dcr/dcr-authenticator.d.cts +73 -0
- package/dist/cjs/dcr/dcr-authenticator.d.ts +73 -0
- package/dist/cjs/dcr/dcr-authenticator.js +655 -0
- package/dist/cjs/dcr/dcr-authenticator.js.map +1 -0
- package/dist/cjs/dcr/dynamic-client-registrar.d.cts +28 -0
- package/dist/cjs/dcr/dynamic-client-registrar.d.ts +28 -0
- package/dist/cjs/dcr/dynamic-client-registrar.js +245 -0
- package/dist/cjs/dcr/dynamic-client-registrar.js.map +1 -0
- package/dist/cjs/dcr/index.d.cts +8 -0
- package/dist/cjs/dcr/index.d.ts +8 -0
- package/dist/cjs/dcr/index.js +24 -0
- package/dist/cjs/dcr/index.js.map +1 -0
- package/dist/cjs/index.d.cts +21 -0
- package/dist/cjs/index.d.ts +21 -0
- package/dist/cjs/index.js +94 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/monkey-patches.d.cts +6 -0
- package/dist/cjs/monkey-patches.d.ts +6 -0
- package/dist/cjs/monkey-patches.js +236 -0
- package/dist/cjs/monkey-patches.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/response-wrappers.d.cts +41 -0
- package/dist/cjs/response-wrappers.d.ts +41 -0
- package/dist/cjs/response-wrappers.js +443 -0
- package/dist/cjs/response-wrappers.js.map +1 -0
- package/dist/cjs/search/index.d.cts +6 -0
- package/dist/cjs/search/index.d.ts +6 -0
- package/dist/cjs/search/index.js +25 -0
- package/dist/cjs/search/index.js.map +1 -0
- package/dist/cjs/search/search.d.cts +22 -0
- package/dist/cjs/search/search.d.ts +22 -0
- package/dist/cjs/search/search.js +630 -0
- package/dist/cjs/search/search.js.map +1 -0
- package/dist/cjs/search/types.d.cts +122 -0
- package/dist/cjs/search/types.d.ts +122 -0
- package/dist/cjs/search/types.js +10 -0
- package/dist/cjs/search/types.js.map +1 -0
- package/dist/cjs/spawn/spawn-server.d.cts +83 -0
- package/dist/cjs/spawn/spawn-server.d.ts +83 -0
- package/dist/cjs/spawn/spawn-server.js +410 -0
- package/dist/cjs/spawn/spawn-server.js.map +1 -0
- package/dist/cjs/spawn/spawn-servers.d.cts +151 -0
- package/dist/cjs/spawn/spawn-servers.d.ts +151 -0
- package/dist/cjs/spawn/spawn-servers.js +911 -0
- package/dist/cjs/spawn/spawn-servers.js.map +1 -0
- package/dist/cjs/types.d.cts +11 -0
- package/dist/cjs/types.d.ts +11 -0
- package/dist/cjs/types.js +10 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils/logger.d.cts +24 -0
- package/dist/cjs/utils/logger.d.ts +24 -0
- package/dist/cjs/utils/logger.js +80 -0
- package/dist/cjs/utils/logger.js.map +1 -0
- package/dist/cjs/utils/path-utils.d.cts +45 -0
- package/dist/cjs/utils/path-utils.d.ts +45 -0
- package/dist/cjs/utils/path-utils.js +158 -0
- package/dist/cjs/utils/path-utils.js.map +1 -0
- package/dist/cjs/utils/sanitizer.d.cts +30 -0
- package/dist/cjs/utils/sanitizer.d.ts +30 -0
- package/dist/cjs/utils/sanitizer.js +124 -0
- package/dist/cjs/utils/sanitizer.js.map +1 -0
- package/dist/esm/auth/capability-discovery.d.ts +25 -0
- package/dist/esm/auth/capability-discovery.js +110 -0
- package/dist/esm/auth/capability-discovery.js.map +1 -0
- package/dist/esm/auth/index.d.ts +9 -0
- package/dist/esm/auth/index.js +6 -0
- package/dist/esm/auth/index.js.map +1 -0
- package/dist/esm/auth/interactive-oauth-flow.d.ts +58 -0
- package/dist/esm/auth/interactive-oauth-flow.js +217 -0
- package/dist/esm/auth/interactive-oauth-flow.js.map +1 -0
- package/dist/esm/auth/oauth-callback-listener.d.ts +56 -0
- package/dist/esm/auth/oauth-callback-listener.js +166 -0
- package/dist/esm/auth/oauth-callback-listener.js.map +1 -0
- package/dist/esm/auth/pkce.d.ts +17 -0
- package/dist/esm/auth/pkce.js +41 -0
- package/dist/esm/auth/pkce.js.map +1 -0
- package/dist/esm/auth/rfc9728-discovery.d.ts +34 -0
- package/dist/esm/auth/rfc9728-discovery.js +157 -0
- package/dist/esm/auth/rfc9728-discovery.js.map +1 -0
- package/dist/esm/auth/types.d.ts +137 -0
- package/dist/esm/auth/types.js +7 -0
- package/dist/esm/auth/types.js.map +1 -0
- package/dist/esm/client-helpers.d.ts +55 -0
- package/dist/esm/client-helpers.js +81 -0
- package/dist/esm/client-helpers.js.map +1 -0
- package/dist/esm/config/server-loader.d.ts +27 -0
- package/dist/esm/config/server-loader.js +49 -0
- package/dist/esm/config/server-loader.js.map +1 -0
- package/dist/esm/config/validate-config.d.ts +15 -0
- package/dist/esm/config/validate-config.js +76 -0
- package/dist/esm/config/validate-config.js.map +1 -0
- package/dist/esm/connection/connect-client.d.ts +59 -0
- package/dist/esm/connection/connect-client.js +272 -0
- package/dist/esm/connection/connect-client.js.map +1 -0
- package/dist/esm/connection/existing-process-transport.d.ts +40 -0
- package/dist/esm/connection/existing-process-transport.js +103 -0
- package/dist/esm/connection/existing-process-transport.js.map +1 -0
- package/dist/esm/connection/types.d.ts +61 -0
- package/dist/esm/connection/types.js +34 -0
- package/dist/esm/connection/types.js.map +1 -0
- package/dist/esm/connection/wait-for-http-ready.d.ts +15 -0
- package/dist/esm/connection/wait-for-http-ready.js +43 -0
- package/dist/esm/connection/wait-for-http-ready.js.map +1 -0
- package/dist/esm/dcr/dcr-authenticator.d.ts +73 -0
- package/dist/esm/dcr/dcr-authenticator.js +235 -0
- package/dist/esm/dcr/dcr-authenticator.js.map +1 -0
- package/dist/esm/dcr/dynamic-client-registrar.d.ts +28 -0
- package/dist/esm/dcr/dynamic-client-registrar.js +66 -0
- package/dist/esm/dcr/dynamic-client-registrar.js.map +1 -0
- package/dist/esm/dcr/index.d.ts +8 -0
- package/dist/esm/dcr/index.js +5 -0
- package/dist/esm/dcr/index.js.map +1 -0
- package/dist/esm/index.d.ts +21 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/monkey-patches.d.ts +6 -0
- package/dist/esm/monkey-patches.js +32 -0
- package/dist/esm/monkey-patches.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/response-wrappers.d.ts +41 -0
- package/dist/esm/response-wrappers.js +201 -0
- package/dist/esm/response-wrappers.js.map +1 -0
- package/dist/esm/search/index.d.ts +6 -0
- package/dist/esm/search/index.js +3 -0
- package/dist/esm/search/index.js.map +1 -0
- package/dist/esm/search/search.d.ts +22 -0
- package/dist/esm/search/search.js +236 -0
- package/dist/esm/search/search.js.map +1 -0
- package/dist/esm/search/types.d.ts +122 -0
- package/dist/esm/search/types.js +8 -0
- package/dist/esm/search/types.js.map +1 -0
- package/dist/esm/spawn/spawn-server.d.ts +83 -0
- package/dist/esm/spawn/spawn-server.js +145 -0
- package/dist/esm/spawn/spawn-server.js.map +1 -0
- package/dist/esm/spawn/spawn-servers.d.ts +151 -0
- package/dist/esm/spawn/spawn-servers.js +406 -0
- package/dist/esm/spawn/spawn-servers.js.map +1 -0
- package/dist/esm/types.d.ts +11 -0
- package/dist/esm/types.js +9 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils/logger.d.ts +24 -0
- package/dist/esm/utils/logger.js +59 -0
- package/dist/esm/utils/logger.js.map +1 -0
- package/dist/esm/utils/path-utils.d.ts +45 -0
- package/dist/esm/utils/path-utils.js +89 -0
- package/dist/esm/utils/path-utils.js.map +1 -0
- package/dist/esm/utils/sanitizer.d.ts +30 -0
- package/dist/esm/utils/sanitizer.js +43 -0
- package/dist/esm/utils/sanitizer.js.map +1 -0
- package/package.json +92 -0
- package/schemas/servers.d.ts +90 -0
- package/schemas/servers.schema.json +104 -0
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DCR Authenticator
|
|
3
|
+
* Consolidates DCR and OAuth flow logic for MCP HTTP servers
|
|
4
|
+
*/ "use strict";
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "DcrAuthenticator", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function() {
|
|
11
|
+
return DcrAuthenticator;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
var _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
|
|
15
|
+
var _fs = /*#__PURE__*/ _interop_require_wildcard(require("fs"));
|
|
16
|
+
var _keyv = /*#__PURE__*/ _interop_require_default(require("keyv"));
|
|
17
|
+
var _keyvfile = require("keyv-file");
|
|
18
|
+
var _interactiveoauthflowts = require("../auth/interactive-oauth-flow.js");
|
|
19
|
+
var _loggerts = require("../utils/logger.js");
|
|
20
|
+
var _dynamicclientregistrarts = require("./dynamic-client-registrar.js");
|
|
21
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
22
|
+
try {
|
|
23
|
+
var info = gen[key](arg);
|
|
24
|
+
var value = info.value;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
reject(error);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (info.done) {
|
|
30
|
+
resolve(value);
|
|
31
|
+
} else {
|
|
32
|
+
Promise.resolve(value).then(_next, _throw);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function _async_to_generator(fn) {
|
|
36
|
+
return function() {
|
|
37
|
+
var self = this, args = arguments;
|
|
38
|
+
return new Promise(function(resolve, reject) {
|
|
39
|
+
var gen = fn.apply(self, args);
|
|
40
|
+
function _next(value) {
|
|
41
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
42
|
+
}
|
|
43
|
+
function _throw(err) {
|
|
44
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
45
|
+
}
|
|
46
|
+
_next(undefined);
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function _class_call_check(instance, Constructor) {
|
|
51
|
+
if (!(instance instanceof Constructor)) {
|
|
52
|
+
throw new TypeError("Cannot call a class as a function");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function _instanceof(left, right) {
|
|
56
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
57
|
+
return !!right[Symbol.hasInstance](left);
|
|
58
|
+
} else {
|
|
59
|
+
return left instanceof right;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function _interop_require_default(obj) {
|
|
63
|
+
return obj && obj.__esModule ? obj : {
|
|
64
|
+
default: obj
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
68
|
+
if (typeof WeakMap !== "function") return null;
|
|
69
|
+
var cacheBabelInterop = new WeakMap();
|
|
70
|
+
var cacheNodeInterop = new WeakMap();
|
|
71
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
72
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
73
|
+
})(nodeInterop);
|
|
74
|
+
}
|
|
75
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
76
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
77
|
+
return obj;
|
|
78
|
+
}
|
|
79
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
80
|
+
return {
|
|
81
|
+
default: obj
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
85
|
+
if (cache && cache.has(obj)) {
|
|
86
|
+
return cache.get(obj);
|
|
87
|
+
}
|
|
88
|
+
var newObj = {
|
|
89
|
+
__proto__: null
|
|
90
|
+
};
|
|
91
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
92
|
+
for(var key in obj){
|
|
93
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
94
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
95
|
+
if (desc && (desc.get || desc.set)) {
|
|
96
|
+
Object.defineProperty(newObj, key, desc);
|
|
97
|
+
} else {
|
|
98
|
+
newObj[key] = obj[key];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
newObj.default = obj;
|
|
103
|
+
if (cache) {
|
|
104
|
+
cache.set(obj, newObj);
|
|
105
|
+
}
|
|
106
|
+
return newObj;
|
|
107
|
+
}
|
|
108
|
+
function _ts_generator(thisArg, body) {
|
|
109
|
+
var f, y, t, _ = {
|
|
110
|
+
label: 0,
|
|
111
|
+
sent: function() {
|
|
112
|
+
if (t[0] & 1) throw t[1];
|
|
113
|
+
return t[1];
|
|
114
|
+
},
|
|
115
|
+
trys: [],
|
|
116
|
+
ops: []
|
|
117
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
118
|
+
return d(g, "next", {
|
|
119
|
+
value: verb(0)
|
|
120
|
+
}), d(g, "throw", {
|
|
121
|
+
value: verb(1)
|
|
122
|
+
}), d(g, "return", {
|
|
123
|
+
value: verb(2)
|
|
124
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
125
|
+
value: function() {
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
}), g;
|
|
129
|
+
function verb(n) {
|
|
130
|
+
return function(v) {
|
|
131
|
+
return step([
|
|
132
|
+
n,
|
|
133
|
+
v
|
|
134
|
+
]);
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function step(op) {
|
|
138
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
139
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
140
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
141
|
+
if (y = 0, t) op = [
|
|
142
|
+
op[0] & 2,
|
|
143
|
+
t.value
|
|
144
|
+
];
|
|
145
|
+
switch(op[0]){
|
|
146
|
+
case 0:
|
|
147
|
+
case 1:
|
|
148
|
+
t = op;
|
|
149
|
+
break;
|
|
150
|
+
case 4:
|
|
151
|
+
_.label++;
|
|
152
|
+
return {
|
|
153
|
+
value: op[1],
|
|
154
|
+
done: false
|
|
155
|
+
};
|
|
156
|
+
case 5:
|
|
157
|
+
_.label++;
|
|
158
|
+
y = op[1];
|
|
159
|
+
op = [
|
|
160
|
+
0
|
|
161
|
+
];
|
|
162
|
+
continue;
|
|
163
|
+
case 7:
|
|
164
|
+
op = _.ops.pop();
|
|
165
|
+
_.trys.pop();
|
|
166
|
+
continue;
|
|
167
|
+
default:
|
|
168
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
169
|
+
_ = 0;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
173
|
+
_.label = op[1];
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
177
|
+
_.label = t[1];
|
|
178
|
+
t = op;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
if (t && _.label < t[2]) {
|
|
182
|
+
_.label = t[2];
|
|
183
|
+
_.ops.push(op);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
if (t[2]) _.ops.pop();
|
|
187
|
+
_.trys.pop();
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
op = body.call(thisArg, _);
|
|
191
|
+
} catch (e) {
|
|
192
|
+
op = [
|
|
193
|
+
6,
|
|
194
|
+
e
|
|
195
|
+
];
|
|
196
|
+
y = 0;
|
|
197
|
+
} finally{
|
|
198
|
+
f = t = 0;
|
|
199
|
+
}
|
|
200
|
+
if (op[0] & 5) throw op[1];
|
|
201
|
+
return {
|
|
202
|
+
value: op[0] ? op[1] : void 0,
|
|
203
|
+
done: true
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Buffer time before token expiry to trigger proactive refresh (5 minutes)
|
|
209
|
+
*/ var REFRESH_BUFFER_MS = 5 * 60 * 1000;
|
|
210
|
+
var DcrAuthenticator = /*#__PURE__*/ function() {
|
|
211
|
+
"use strict";
|
|
212
|
+
function DcrAuthenticator(options) {
|
|
213
|
+
_class_call_check(this, DcrAuthenticator);
|
|
214
|
+
var _options_logger;
|
|
215
|
+
if (options.tokenStore) {
|
|
216
|
+
this.tokenStore = options.tokenStore;
|
|
217
|
+
} else {
|
|
218
|
+
// Default CLI store in .mcp-z directory (per-project)
|
|
219
|
+
var storePath = _nodepath.default.join(process.cwd(), '.mcp-z', 'tokens.json');
|
|
220
|
+
// Ensure directory exists before creating store
|
|
221
|
+
_fs.mkdirSync(_nodepath.default.dirname(storePath), {
|
|
222
|
+
recursive: true
|
|
223
|
+
});
|
|
224
|
+
this.tokenStore = new _keyv.default({
|
|
225
|
+
store: new _keyvfile.KeyvFile({
|
|
226
|
+
filename: storePath
|
|
227
|
+
})
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
this.dcrClient = new _dynamicclientregistrarts.DynamicClientRegistrar();
|
|
231
|
+
this.oauthFlow = new _interactiveoauthflowts.InteractiveOAuthFlow();
|
|
232
|
+
this.headless = options.headless || false;
|
|
233
|
+
this.redirectUri = options.redirectUri;
|
|
234
|
+
this.logger = (_options_logger = options.logger) !== null && _options_logger !== void 0 ? _options_logger : _loggerts.logger;
|
|
235
|
+
}
|
|
236
|
+
var _proto = DcrAuthenticator.prototype;
|
|
237
|
+
/**
|
|
238
|
+
* Detect if server is self-hosted DCR (vs external OAuth provider)
|
|
239
|
+
* Self-hosted servers have their own OAuth endpoints and manage token storage
|
|
240
|
+
*/ _proto.detectSelfHostedMode = function detectSelfHostedMode(baseUrl) {
|
|
241
|
+
return _async_to_generator(function() {
|
|
242
|
+
return _ts_generator(this, function(_state) {
|
|
243
|
+
try {
|
|
244
|
+
// Self-hosted DCR servers typically run their own OAuth server
|
|
245
|
+
// Check if this is a self-hosted instance by testing OAuth metadata
|
|
246
|
+
// For now, assume self-hosted if baseUrl matches common localhost patterns
|
|
247
|
+
// TODO: Implement proper self-hosted detection logic
|
|
248
|
+
return [
|
|
249
|
+
2,
|
|
250
|
+
baseUrl.includes('localhost') || baseUrl.includes('127.0.0.1')
|
|
251
|
+
];
|
|
252
|
+
} catch (_error) {
|
|
253
|
+
return [
|
|
254
|
+
2,
|
|
255
|
+
false
|
|
256
|
+
]; // Assume external mode if detection fails
|
|
257
|
+
}
|
|
258
|
+
return [
|
|
259
|
+
2
|
|
260
|
+
];
|
|
261
|
+
});
|
|
262
|
+
})();
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* Ensure server is authenticated, performing DCR and OAuth if needed
|
|
266
|
+
* Proactively refreshes tokens if they're within 5 minutes of expiry
|
|
267
|
+
*
|
|
268
|
+
* @param baseUrl - Base URL of the server (e.g., https://example.com)
|
|
269
|
+
* @param capabilities - Auth capabilities from .well-known endpoint
|
|
270
|
+
* @returns Valid token set ready to use
|
|
271
|
+
*
|
|
272
|
+
* @throws Error if authentication fails
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* const authenticator = new DcrAuthenticator({ redirectUri: 'http://localhost:3000/callback' });
|
|
276
|
+
* const tokens = await authenticator.ensureAuthenticated(
|
|
277
|
+
* 'https://example.com',
|
|
278
|
+
* capabilities
|
|
279
|
+
* );
|
|
280
|
+
*/ _proto.ensureAuthenticated = function ensureAuthenticated(baseUrl, capabilities) {
|
|
281
|
+
return _async_to_generator(function() {
|
|
282
|
+
var isSelfHosted;
|
|
283
|
+
return _ts_generator(this, function(_state) {
|
|
284
|
+
switch(_state.label){
|
|
285
|
+
case 0:
|
|
286
|
+
return [
|
|
287
|
+
4,
|
|
288
|
+
this.detectSelfHostedMode(baseUrl)
|
|
289
|
+
];
|
|
290
|
+
case 1:
|
|
291
|
+
isSelfHosted = _state.sent();
|
|
292
|
+
if (isSelfHosted) {
|
|
293
|
+
return [
|
|
294
|
+
2,
|
|
295
|
+
this.ensureAuthenticatedSelfHosted(baseUrl, capabilities)
|
|
296
|
+
];
|
|
297
|
+
}
|
|
298
|
+
return [
|
|
299
|
+
2,
|
|
300
|
+
this.ensureAuthenticatedExternal(baseUrl, capabilities)
|
|
301
|
+
];
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
}).call(this);
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* Handle authentication for self-hosted DCR servers
|
|
308
|
+
* Self-hosted servers manage their own token storage via /oauth/verify
|
|
309
|
+
*/ _proto.ensureAuthenticatedSelfHosted = function ensureAuthenticatedSelfHosted(baseUrl, capabilities) {
|
|
310
|
+
return _async_to_generator(function() {
|
|
311
|
+
var dcrTokenKey, tokens, verifyUrl, verifyResponse, verifyData, _error, port, client, flowOptions, verifyUrl1, verifyResponse1, verifyData1, error;
|
|
312
|
+
return _ts_generator(this, function(_state) {
|
|
313
|
+
switch(_state.label){
|
|
314
|
+
case 0:
|
|
315
|
+
dcrTokenKey = "dcr-tokens:".concat(baseUrl);
|
|
316
|
+
return [
|
|
317
|
+
4,
|
|
318
|
+
this.tokenStore.get(dcrTokenKey)
|
|
319
|
+
];
|
|
320
|
+
case 1:
|
|
321
|
+
tokens = _state.sent();
|
|
322
|
+
if (!tokens) return [
|
|
323
|
+
3,
|
|
324
|
+
9
|
|
325
|
+
];
|
|
326
|
+
_state.label = 2;
|
|
327
|
+
case 2:
|
|
328
|
+
_state.trys.push([
|
|
329
|
+
2,
|
|
330
|
+
6,
|
|
331
|
+
,
|
|
332
|
+
7
|
|
333
|
+
]);
|
|
334
|
+
verifyUrl = "".concat(baseUrl, "/oauth/verify");
|
|
335
|
+
return [
|
|
336
|
+
4,
|
|
337
|
+
fetch(verifyUrl, {
|
|
338
|
+
headers: {
|
|
339
|
+
Authorization: "Bearer ".concat(tokens.accessToken),
|
|
340
|
+
Connection: 'close'
|
|
341
|
+
}
|
|
342
|
+
})
|
|
343
|
+
];
|
|
344
|
+
case 3:
|
|
345
|
+
verifyResponse = _state.sent();
|
|
346
|
+
if (!verifyResponse.ok) return [
|
|
347
|
+
3,
|
|
348
|
+
5
|
|
349
|
+
];
|
|
350
|
+
return [
|
|
351
|
+
4,
|
|
352
|
+
verifyResponse.json()
|
|
353
|
+
];
|
|
354
|
+
case 4:
|
|
355
|
+
verifyData = _state.sent();
|
|
356
|
+
if (verifyData.token === tokens.accessToken) {
|
|
357
|
+
// Token is still valid with the self-hosted server
|
|
358
|
+
return [
|
|
359
|
+
2,
|
|
360
|
+
tokens
|
|
361
|
+
];
|
|
362
|
+
}
|
|
363
|
+
_state.label = 5;
|
|
364
|
+
case 5:
|
|
365
|
+
return [
|
|
366
|
+
3,
|
|
367
|
+
7
|
|
368
|
+
];
|
|
369
|
+
case 6:
|
|
370
|
+
_error = _state.sent();
|
|
371
|
+
return [
|
|
372
|
+
3,
|
|
373
|
+
7
|
|
374
|
+
];
|
|
375
|
+
case 7:
|
|
376
|
+
// Token is expired or invalid
|
|
377
|
+
return [
|
|
378
|
+
4,
|
|
379
|
+
this.tokenStore.delete(dcrTokenKey)
|
|
380
|
+
];
|
|
381
|
+
case 8:
|
|
382
|
+
_state.sent();
|
|
383
|
+
tokens = undefined;
|
|
384
|
+
_state.label = 9;
|
|
385
|
+
case 9:
|
|
386
|
+
// 3. No valid tokens - perform full DCR + OAuth flow
|
|
387
|
+
if (!capabilities.registrationEndpoint || !capabilities.authorizationEndpoint || !capabilities.tokenEndpoint) {
|
|
388
|
+
throw new Error('Server does not provide required OAuth endpoints');
|
|
389
|
+
}
|
|
390
|
+
this.logger.debug('🔐 No valid tokens found, starting self-hosted DCR authentication...');
|
|
391
|
+
// Extract port from pre-resolved redirectUri
|
|
392
|
+
port = parseInt(new URL(this.redirectUri).port, 10) || (this.redirectUri.startsWith('https:') ? 443 : 80);
|
|
393
|
+
// Register OAuth client via DCR
|
|
394
|
+
this.logger.debug('📝 Registering OAuth client with self-hosted server...');
|
|
395
|
+
return [
|
|
396
|
+
4,
|
|
397
|
+
this.dcrClient.registerClient(capabilities.registrationEndpoint, {
|
|
398
|
+
redirectUri: this.redirectUri
|
|
399
|
+
})
|
|
400
|
+
];
|
|
401
|
+
case 10:
|
|
402
|
+
client = _state.sent();
|
|
403
|
+
// Perform OAuth authorization flow with PKCE (RFC 7636)
|
|
404
|
+
flowOptions = {
|
|
405
|
+
port: port,
|
|
406
|
+
headless: this.headless,
|
|
407
|
+
redirectUri: this.redirectUri,
|
|
408
|
+
pkce: true,
|
|
409
|
+
logger: this.logger
|
|
410
|
+
};
|
|
411
|
+
if (capabilities.scopes) {
|
|
412
|
+
flowOptions.scopes = capabilities.scopes;
|
|
413
|
+
}
|
|
414
|
+
return [
|
|
415
|
+
4,
|
|
416
|
+
this.oauthFlow.performAuthFlow(capabilities.authorizationEndpoint, capabilities.tokenEndpoint, client.clientId, client.clientSecret, flowOptions)
|
|
417
|
+
];
|
|
418
|
+
case 11:
|
|
419
|
+
tokens = _state.sent();
|
|
420
|
+
_state.label = 12;
|
|
421
|
+
case 12:
|
|
422
|
+
_state.trys.push([
|
|
423
|
+
12,
|
|
424
|
+
15,
|
|
425
|
+
,
|
|
426
|
+
16
|
|
427
|
+
]);
|
|
428
|
+
verifyUrl1 = "".concat(baseUrl, "/oauth/verify");
|
|
429
|
+
return [
|
|
430
|
+
4,
|
|
431
|
+
fetch(verifyUrl1, {
|
|
432
|
+
headers: {
|
|
433
|
+
Authorization: "Bearer ".concat(tokens.accessToken),
|
|
434
|
+
Connection: 'close'
|
|
435
|
+
}
|
|
436
|
+
})
|
|
437
|
+
];
|
|
438
|
+
case 13:
|
|
439
|
+
verifyResponse1 = _state.sent();
|
|
440
|
+
if (!verifyResponse1.ok) {
|
|
441
|
+
throw new Error("DCR token verification failed after authentication: ".concat(verifyResponse1.status));
|
|
442
|
+
}
|
|
443
|
+
return [
|
|
444
|
+
4,
|
|
445
|
+
verifyResponse1.json()
|
|
446
|
+
];
|
|
447
|
+
case 14:
|
|
448
|
+
verifyData1 = _state.sent();
|
|
449
|
+
if (verifyData1.token !== tokens.accessToken) {
|
|
450
|
+
throw new Error('DCR server returned different token in verification');
|
|
451
|
+
}
|
|
452
|
+
this.logger.debug('✅ DCR token verified with self-hosted server');
|
|
453
|
+
return [
|
|
454
|
+
3,
|
|
455
|
+
16
|
|
456
|
+
];
|
|
457
|
+
case 15:
|
|
458
|
+
error = _state.sent();
|
|
459
|
+
this.logger.error('❌ DCR token verification failed:', _instanceof(error, Error) ? error.message : String(error));
|
|
460
|
+
throw new Error('Self-hosted DCR authentication completed but token verification failed');
|
|
461
|
+
case 16:
|
|
462
|
+
// Save tokens for future use
|
|
463
|
+
return [
|
|
464
|
+
4,
|
|
465
|
+
this.tokenStore.set(dcrTokenKey, tokens)
|
|
466
|
+
];
|
|
467
|
+
case 17:
|
|
468
|
+
_state.sent();
|
|
469
|
+
this.logger.debug('✅ Self-hosted DCR authentication successful, tokens saved');
|
|
470
|
+
return [
|
|
471
|
+
2,
|
|
472
|
+
tokens
|
|
473
|
+
];
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
}).call(this);
|
|
477
|
+
};
|
|
478
|
+
/**
|
|
479
|
+
* Handle authentication for external OAuth providers (original implementation)
|
|
480
|
+
*/ _proto.ensureAuthenticatedExternal = function ensureAuthenticatedExternal(baseUrl, capabilities) {
|
|
481
|
+
return _async_to_generator(function() {
|
|
482
|
+
var tokenKey, tokens, _error, port, client, flowOptions;
|
|
483
|
+
return _ts_generator(this, function(_state) {
|
|
484
|
+
switch(_state.label){
|
|
485
|
+
case 0:
|
|
486
|
+
tokenKey = "tokens:".concat(baseUrl);
|
|
487
|
+
return [
|
|
488
|
+
4,
|
|
489
|
+
this.tokenStore.get(tokenKey)
|
|
490
|
+
];
|
|
491
|
+
case 1:
|
|
492
|
+
tokens = _state.sent();
|
|
493
|
+
if (!tokens) return [
|
|
494
|
+
3,
|
|
495
|
+
8
|
|
496
|
+
];
|
|
497
|
+
if (!(tokens.expiresAt < Date.now() + REFRESH_BUFFER_MS)) return [
|
|
498
|
+
3,
|
|
499
|
+
7
|
|
500
|
+
];
|
|
501
|
+
this.logger.debug('🔄 Refreshing access token...');
|
|
502
|
+
_state.label = 2;
|
|
503
|
+
case 2:
|
|
504
|
+
_state.trys.push([
|
|
505
|
+
2,
|
|
506
|
+
5,
|
|
507
|
+
,
|
|
508
|
+
7
|
|
509
|
+
]);
|
|
510
|
+
return [
|
|
511
|
+
4,
|
|
512
|
+
this.refreshTokens(tokens, capabilities.tokenEndpoint)
|
|
513
|
+
];
|
|
514
|
+
case 3:
|
|
515
|
+
tokens = _state.sent();
|
|
516
|
+
return [
|
|
517
|
+
4,
|
|
518
|
+
this.tokenStore.set(tokenKey, tokens)
|
|
519
|
+
];
|
|
520
|
+
case 4:
|
|
521
|
+
_state.sent();
|
|
522
|
+
this.logger.debug('✅ Token refreshed successfully');
|
|
523
|
+
return [
|
|
524
|
+
3,
|
|
525
|
+
7
|
|
526
|
+
];
|
|
527
|
+
case 5:
|
|
528
|
+
_error = _state.sent();
|
|
529
|
+
// Refresh failed - clear tokens and re-authenticate
|
|
530
|
+
this.logger.warn('⚠️ Token refresh failed, re-authenticating...');
|
|
531
|
+
return [
|
|
532
|
+
4,
|
|
533
|
+
this.tokenStore.delete(tokenKey)
|
|
534
|
+
];
|
|
535
|
+
case 6:
|
|
536
|
+
_state.sent();
|
|
537
|
+
tokens = undefined;
|
|
538
|
+
return [
|
|
539
|
+
3,
|
|
540
|
+
7
|
|
541
|
+
];
|
|
542
|
+
case 7:
|
|
543
|
+
if (tokens) {
|
|
544
|
+
return [
|
|
545
|
+
2,
|
|
546
|
+
tokens
|
|
547
|
+
];
|
|
548
|
+
}
|
|
549
|
+
_state.label = 8;
|
|
550
|
+
case 8:
|
|
551
|
+
// 3. No valid tokens - perform DCR + OAuth flow
|
|
552
|
+
if (!capabilities.registrationEndpoint || !capabilities.authorizationEndpoint || !capabilities.tokenEndpoint) {
|
|
553
|
+
throw new Error('Server does not provide required OAuth endpoints');
|
|
554
|
+
}
|
|
555
|
+
this.logger.debug('🔐 No valid tokens found, starting external OAuth authentication...');
|
|
556
|
+
// Extract port from pre-resolved redirectUri
|
|
557
|
+
port = parseInt(new URL(this.redirectUri).port, 10) || (this.redirectUri.startsWith('https:') ? 443 : 80);
|
|
558
|
+
// Register OAuth client via DCR
|
|
559
|
+
this.logger.debug('📝 Registering OAuth client...');
|
|
560
|
+
return [
|
|
561
|
+
4,
|
|
562
|
+
this.dcrClient.registerClient(capabilities.registrationEndpoint, {
|
|
563
|
+
redirectUri: this.redirectUri
|
|
564
|
+
})
|
|
565
|
+
];
|
|
566
|
+
case 9:
|
|
567
|
+
client = _state.sent();
|
|
568
|
+
// Perform OAuth authorization flow with PKCE (RFC 7636)
|
|
569
|
+
flowOptions = {
|
|
570
|
+
port: port,
|
|
571
|
+
headless: this.headless,
|
|
572
|
+
redirectUri: this.redirectUri,
|
|
573
|
+
pkce: true,
|
|
574
|
+
logger: this.logger
|
|
575
|
+
};
|
|
576
|
+
if (capabilities.scopes) {
|
|
577
|
+
flowOptions.scopes = capabilities.scopes;
|
|
578
|
+
}
|
|
579
|
+
return [
|
|
580
|
+
4,
|
|
581
|
+
this.oauthFlow.performAuthFlow(capabilities.authorizationEndpoint, capabilities.tokenEndpoint, client.clientId, client.clientSecret, flowOptions)
|
|
582
|
+
];
|
|
583
|
+
case 10:
|
|
584
|
+
tokens = _state.sent();
|
|
585
|
+
// Save tokens for future use
|
|
586
|
+
return [
|
|
587
|
+
4,
|
|
588
|
+
this.tokenStore.set(tokenKey, tokens)
|
|
589
|
+
];
|
|
590
|
+
case 11:
|
|
591
|
+
_state.sent();
|
|
592
|
+
this.logger.debug('✅ Authentication successful, tokens saved');
|
|
593
|
+
return [
|
|
594
|
+
2,
|
|
595
|
+
tokens
|
|
596
|
+
];
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
}).call(this);
|
|
600
|
+
};
|
|
601
|
+
/**
|
|
602
|
+
* Refresh access token using refresh token
|
|
603
|
+
*/ _proto.refreshTokens = function refreshTokens(tokens, tokenEndpoint) {
|
|
604
|
+
return _async_to_generator(function() {
|
|
605
|
+
return _ts_generator(this, function(_state) {
|
|
606
|
+
switch(_state.label){
|
|
607
|
+
case 0:
|
|
608
|
+
if (!tokenEndpoint) {
|
|
609
|
+
throw new Error('Token endpoint not available for refresh');
|
|
610
|
+
}
|
|
611
|
+
if (!tokens.refreshToken) {
|
|
612
|
+
throw new Error('No refresh token available');
|
|
613
|
+
}
|
|
614
|
+
if (!tokens.clientId || !tokens.clientSecret) {
|
|
615
|
+
throw new Error('Client credentials not available for refresh');
|
|
616
|
+
}
|
|
617
|
+
return [
|
|
618
|
+
4,
|
|
619
|
+
this.oauthFlow.refreshTokens(tokenEndpoint, tokens.refreshToken, tokens.clientId, tokens.clientSecret)
|
|
620
|
+
];
|
|
621
|
+
case 1:
|
|
622
|
+
return [
|
|
623
|
+
2,
|
|
624
|
+
_state.sent()
|
|
625
|
+
];
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
}).call(this);
|
|
629
|
+
};
|
|
630
|
+
/**
|
|
631
|
+
* Delete stored tokens for a server
|
|
632
|
+
*/ _proto.deleteTokens = function deleteTokens(baseUrl) {
|
|
633
|
+
return _async_to_generator(function() {
|
|
634
|
+
var tokenKey;
|
|
635
|
+
return _ts_generator(this, function(_state) {
|
|
636
|
+
switch(_state.label){
|
|
637
|
+
case 0:
|
|
638
|
+
tokenKey = "tokens:".concat(baseUrl);
|
|
639
|
+
return [
|
|
640
|
+
4,
|
|
641
|
+
this.tokenStore.delete(tokenKey)
|
|
642
|
+
];
|
|
643
|
+
case 1:
|
|
644
|
+
_state.sent();
|
|
645
|
+
this.logger.debug("\uD83D\uDDD1️ Deleted tokens for ".concat(baseUrl));
|
|
646
|
+
return [
|
|
647
|
+
2
|
|
648
|
+
];
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
}).call(this);
|
|
652
|
+
};
|
|
653
|
+
return DcrAuthenticator;
|
|
654
|
+
}();
|
|
655
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|