@unkey/api 2.1.1 → 2.1.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.
Files changed (32) hide show
  1. package/bin/mcp-server.js +233 -176
  2. package/bin/mcp-server.js.map +9 -8
  3. package/dist/commonjs/hooks/custom/vercel-edge-fetcher.d.ts +5 -0
  4. package/dist/commonjs/hooks/custom/vercel-edge-fetcher.d.ts.map +1 -0
  5. package/dist/commonjs/hooks/custom/vercel-edge-fetcher.js +63 -0
  6. package/dist/commonjs/hooks/custom/vercel-edge-fetcher.js.map +1 -0
  7. package/dist/commonjs/hooks/registration.d.ts.map +1 -1
  8. package/dist/commonjs/hooks/registration.js +3 -4
  9. package/dist/commonjs/hooks/registration.js.map +1 -1
  10. package/dist/commonjs/lib/config.d.ts +3 -3
  11. package/dist/commonjs/lib/config.js +3 -3
  12. package/dist/commonjs/mcp-server/mcp-server.js +1 -1
  13. package/dist/commonjs/mcp-server/server.js +1 -1
  14. package/dist/esm/hooks/custom/vercel-edge-fetcher.d.ts +5 -0
  15. package/dist/esm/hooks/custom/vercel-edge-fetcher.d.ts.map +1 -0
  16. package/dist/esm/hooks/custom/vercel-edge-fetcher.js +59 -0
  17. package/dist/esm/hooks/custom/vercel-edge-fetcher.js.map +1 -0
  18. package/dist/esm/hooks/registration.d.ts.map +1 -1
  19. package/dist/esm/hooks/registration.js +3 -4
  20. package/dist/esm/hooks/registration.js.map +1 -1
  21. package/dist/esm/lib/config.d.ts +3 -3
  22. package/dist/esm/lib/config.js +3 -3
  23. package/dist/esm/mcp-server/mcp-server.js +1 -1
  24. package/dist/esm/mcp-server/server.js +1 -1
  25. package/examples/package-lock.json +1 -1
  26. package/jsr.json +1 -1
  27. package/package.json +1 -1
  28. package/src/hooks/custom/vercel-edge-fetcher.ts +64 -0
  29. package/src/hooks/registration.ts +3 -4
  30. package/src/lib/config.ts +3 -3
  31. package/src/mcp-server/mcp-server.ts +1 -1
  32. package/src/mcp-server/server.ts +1 -1
package/bin/mcp-server.js CHANGED
@@ -34085,8 +34085,231 @@ var init_mcp = __esm(() => {
34085
34085
  };
34086
34086
  });
34087
34087
 
34088
+ // src/lib/http.ts
34089
+ class HTTPClient {
34090
+ options;
34091
+ fetcher;
34092
+ requestHooks = [];
34093
+ requestErrorHooks = [];
34094
+ responseHooks = [];
34095
+ constructor(options = {}) {
34096
+ this.options = options;
34097
+ this.fetcher = options.fetcher || DEFAULT_FETCHER;
34098
+ }
34099
+ async request(request) {
34100
+ let req = request;
34101
+ for (const hook of this.requestHooks) {
34102
+ const nextRequest = await hook(req);
34103
+ if (nextRequest) {
34104
+ req = nextRequest;
34105
+ }
34106
+ }
34107
+ try {
34108
+ const res = await this.fetcher(req);
34109
+ for (const hook of this.responseHooks) {
34110
+ await hook(res, req);
34111
+ }
34112
+ return res;
34113
+ } catch (err) {
34114
+ for (const hook of this.requestErrorHooks) {
34115
+ await hook(err, req);
34116
+ }
34117
+ throw err;
34118
+ }
34119
+ }
34120
+ addHook(...args) {
34121
+ if (args[0] === "beforeRequest") {
34122
+ this.requestHooks.push(args[1]);
34123
+ } else if (args[0] === "requestError") {
34124
+ this.requestErrorHooks.push(args[1]);
34125
+ } else if (args[0] === "response") {
34126
+ this.responseHooks.push(args[1]);
34127
+ } else {
34128
+ throw new Error(`Invalid hook type: ${args[0]}`);
34129
+ }
34130
+ return this;
34131
+ }
34132
+ removeHook(...args) {
34133
+ let target;
34134
+ if (args[0] === "beforeRequest") {
34135
+ target = this.requestHooks;
34136
+ } else if (args[0] === "requestError") {
34137
+ target = this.requestErrorHooks;
34138
+ } else if (args[0] === "response") {
34139
+ target = this.responseHooks;
34140
+ } else {
34141
+ throw new Error(`Invalid hook type: ${args[0]}`);
34142
+ }
34143
+ const index = target.findIndex((v2) => v2 === args[1]);
34144
+ if (index >= 0) {
34145
+ target.splice(index, 1);
34146
+ }
34147
+ return this;
34148
+ }
34149
+ clone() {
34150
+ const child = new HTTPClient(this.options);
34151
+ child.requestHooks = this.requestHooks.slice();
34152
+ child.requestErrorHooks = this.requestErrorHooks.slice();
34153
+ child.responseHooks = this.responseHooks.slice();
34154
+ return child;
34155
+ }
34156
+ }
34157
+ function matchContentType(response, pattern) {
34158
+ if (pattern === "*") {
34159
+ return true;
34160
+ }
34161
+ let contentType2 = response.headers.get("content-type")?.trim() || "application/octet-stream";
34162
+ contentType2 = contentType2.toLowerCase();
34163
+ const wantParts = pattern.toLowerCase().trim().split(mediaParamSeparator);
34164
+ const [wantType = "", ...wantParams] = wantParts;
34165
+ if (wantType.split("/").length !== 2) {
34166
+ return false;
34167
+ }
34168
+ const gotParts = contentType2.split(mediaParamSeparator);
34169
+ const [gotType = "", ...gotParams] = gotParts;
34170
+ const [type = "", subtype = ""] = gotType.split("/");
34171
+ if (!type || !subtype) {
34172
+ return false;
34173
+ }
34174
+ if (wantType !== "*/*" && gotType !== wantType && `${type}/*` !== wantType && `*/${subtype}` !== wantType) {
34175
+ return false;
34176
+ }
34177
+ if (gotParams.length < wantParams.length) {
34178
+ return false;
34179
+ }
34180
+ const params = new Set(gotParams);
34181
+ for (const wantParam of wantParams) {
34182
+ if (!params.has(wantParam)) {
34183
+ return false;
34184
+ }
34185
+ }
34186
+ return true;
34187
+ }
34188
+ function matchStatusCode(response, codes) {
34189
+ const actual = `${response.status}`;
34190
+ const expectedCodes = Array.isArray(codes) ? codes : [codes];
34191
+ if (!expectedCodes.length) {
34192
+ return false;
34193
+ }
34194
+ return expectedCodes.some((ec) => {
34195
+ const code = `${ec}`;
34196
+ if (code === "default") {
34197
+ return true;
34198
+ }
34199
+ if (!codeRangeRE.test(`${code}`)) {
34200
+ return code === actual;
34201
+ }
34202
+ const expectFamily = code.charAt(0);
34203
+ if (!expectFamily) {
34204
+ throw new Error("Invalid status code range");
34205
+ }
34206
+ const actualFamily = actual.charAt(0);
34207
+ if (!actualFamily) {
34208
+ throw new Error(`Invalid response status code: ${actual}`);
34209
+ }
34210
+ return actualFamily === expectFamily;
34211
+ });
34212
+ }
34213
+ function matchResponse(response, code, contentTypePattern) {
34214
+ return matchStatusCode(response, code) && matchContentType(response, contentTypePattern);
34215
+ }
34216
+ function isConnectionError(err) {
34217
+ if (typeof err !== "object" || err == null) {
34218
+ return false;
34219
+ }
34220
+ const isBrowserErr = err instanceof TypeError && err.message.toLowerCase().startsWith("failed to fetch");
34221
+ const isNodeErr = err instanceof TypeError && err.message.toLowerCase().startsWith("fetch failed");
34222
+ const isBunErr = "name" in err && err.name === "ConnectionError";
34223
+ const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnreset";
34224
+ return isBrowserErr || isNodeErr || isGenericErr || isBunErr;
34225
+ }
34226
+ function isTimeoutError(err) {
34227
+ if (typeof err !== "object" || err == null) {
34228
+ return false;
34229
+ }
34230
+ const isNative = "name" in err && err.name === "TimeoutError";
34231
+ const isLegacyNative = "code" in err && err.code === 23;
34232
+ const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnaborted";
34233
+ return isNative || isLegacyNative || isGenericErr;
34234
+ }
34235
+ function isAbortError(err) {
34236
+ if (typeof err !== "object" || err == null) {
34237
+ return false;
34238
+ }
34239
+ const isNative = "name" in err && err.name === "AbortError";
34240
+ const isLegacyNative = "code" in err && err.code === 20;
34241
+ const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnaborted";
34242
+ return isNative || isLegacyNative || isGenericErr;
34243
+ }
34244
+ var DEFAULT_FETCHER = (input, init) => {
34245
+ if (init == null) {
34246
+ return fetch(input);
34247
+ } else {
34248
+ return fetch(input, init);
34249
+ }
34250
+ }, mediaParamSeparator, codeRangeRE;
34251
+ var init_http = __esm(() => {
34252
+ mediaParamSeparator = /\s*;\s*/g;
34253
+ codeRangeRE = new RegExp("^[0-9]xx$", "i");
34254
+ });
34255
+
34256
+ // src/hooks/custom/vercel-edge-fetcher.ts
34257
+ function isVercelEdgeRuntime() {
34258
+ if ("EdgeRuntime" in globalThis)
34259
+ return true;
34260
+ if (process.env["NEXT_RUNTIME"] === "edge")
34261
+ return true;
34262
+ return false;
34263
+ }
34264
+
34265
+ class FetcherOverrideForVercelEdgeHook {
34266
+ sdkInit(opts) {
34267
+ if (!isVercelEdgeRuntime()) {
34268
+ return opts;
34269
+ }
34270
+ const client = new HTTPClient({
34271
+ fetcher: vercelEdgeFetcher
34272
+ });
34273
+ return {
34274
+ ...opts,
34275
+ client
34276
+ };
34277
+ }
34278
+ }
34279
+ var vercelEdgeFetcher = (input, init) => {
34280
+ const isRequestLike = typeof input === "object" && input !== null && "url" in input && "method" in input && "headers" in input;
34281
+ if (isRequestLike && !init) {
34282
+ const req = input;
34283
+ return fetch(req.url, {
34284
+ method: req.method,
34285
+ headers: req.headers,
34286
+ body: req.body,
34287
+ mode: req.mode,
34288
+ credentials: req.credentials,
34289
+ cache: req.cache,
34290
+ redirect: req.redirect,
34291
+ referrer: req.referrer,
34292
+ integrity: req.integrity,
34293
+ signal: req.signal
34294
+ });
34295
+ }
34296
+ if (init == null) {
34297
+ return fetch(input);
34298
+ } else {
34299
+ return fetch(input, init);
34300
+ }
34301
+ };
34302
+ var init_vercel_edge_fetcher = __esm(() => {
34303
+ init_http();
34304
+ });
34305
+
34088
34306
  // src/hooks/registration.ts
34089
- function initHooks(hooks) {}
34307
+ function initHooks(hooks) {
34308
+ hooks.registerSDKInitHook(new FetcherOverrideForVercelEdgeHook);
34309
+ }
34310
+ var init_registration = __esm(() => {
34311
+ init_vercel_edge_fetcher();
34312
+ });
34090
34313
 
34091
34314
  // src/hooks/hooks.ts
34092
34315
  class SDKHooks {
@@ -34166,7 +34389,9 @@ class SDKHooks {
34166
34389
  return { response: res, error: err };
34167
34390
  }
34168
34391
  }
34169
- var init_hooks = () => {};
34392
+ var init_hooks = __esm(() => {
34393
+ init_registration();
34394
+ });
34170
34395
 
34171
34396
  // src/models/errors/httpclienterrors.ts
34172
34397
  var HTTPClientError, UnexpectedClientError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, ConnectionError;
@@ -34274,9 +34499,9 @@ var init_config = __esm(() => {
34274
34499
  SDK_METADATA = {
34275
34500
  language: "typescript",
34276
34501
  openapiDocVersion: "2.0.0",
34277
- sdkVersion: "2.1.1",
34278
- genVersion: "2.753.1",
34279
- userAgent: "speakeasy-sdk/typescript 2.1.1 2.753.1 2.0.0 @unkey/api"
34502
+ sdkVersion: "2.1.2",
34503
+ genVersion: "2.753.6",
34504
+ userAgent: "speakeasy-sdk/typescript 2.1.2 2.753.6 2.0.0 @unkey/api"
34280
34505
  };
34281
34506
  });
34282
34507
 
@@ -34508,174 +34733,6 @@ var init_env = __esm(() => {
34508
34733
  });
34509
34734
  });
34510
34735
 
34511
- // src/lib/http.ts
34512
- class HTTPClient {
34513
- options;
34514
- fetcher;
34515
- requestHooks = [];
34516
- requestErrorHooks = [];
34517
- responseHooks = [];
34518
- constructor(options = {}) {
34519
- this.options = options;
34520
- this.fetcher = options.fetcher || DEFAULT_FETCHER;
34521
- }
34522
- async request(request) {
34523
- let req = request;
34524
- for (const hook of this.requestHooks) {
34525
- const nextRequest = await hook(req);
34526
- if (nextRequest) {
34527
- req = nextRequest;
34528
- }
34529
- }
34530
- try {
34531
- const res = await this.fetcher(req);
34532
- for (const hook of this.responseHooks) {
34533
- await hook(res, req);
34534
- }
34535
- return res;
34536
- } catch (err) {
34537
- for (const hook of this.requestErrorHooks) {
34538
- await hook(err, req);
34539
- }
34540
- throw err;
34541
- }
34542
- }
34543
- addHook(...args) {
34544
- if (args[0] === "beforeRequest") {
34545
- this.requestHooks.push(args[1]);
34546
- } else if (args[0] === "requestError") {
34547
- this.requestErrorHooks.push(args[1]);
34548
- } else if (args[0] === "response") {
34549
- this.responseHooks.push(args[1]);
34550
- } else {
34551
- throw new Error(`Invalid hook type: ${args[0]}`);
34552
- }
34553
- return this;
34554
- }
34555
- removeHook(...args) {
34556
- let target;
34557
- if (args[0] === "beforeRequest") {
34558
- target = this.requestHooks;
34559
- } else if (args[0] === "requestError") {
34560
- target = this.requestErrorHooks;
34561
- } else if (args[0] === "response") {
34562
- target = this.responseHooks;
34563
- } else {
34564
- throw new Error(`Invalid hook type: ${args[0]}`);
34565
- }
34566
- const index = target.findIndex((v2) => v2 === args[1]);
34567
- if (index >= 0) {
34568
- target.splice(index, 1);
34569
- }
34570
- return this;
34571
- }
34572
- clone() {
34573
- const child = new HTTPClient(this.options);
34574
- child.requestHooks = this.requestHooks.slice();
34575
- child.requestErrorHooks = this.requestErrorHooks.slice();
34576
- child.responseHooks = this.responseHooks.slice();
34577
- return child;
34578
- }
34579
- }
34580
- function matchContentType(response, pattern) {
34581
- if (pattern === "*") {
34582
- return true;
34583
- }
34584
- let contentType2 = response.headers.get("content-type")?.trim() || "application/octet-stream";
34585
- contentType2 = contentType2.toLowerCase();
34586
- const wantParts = pattern.toLowerCase().trim().split(mediaParamSeparator);
34587
- const [wantType = "", ...wantParams] = wantParts;
34588
- if (wantType.split("/").length !== 2) {
34589
- return false;
34590
- }
34591
- const gotParts = contentType2.split(mediaParamSeparator);
34592
- const [gotType = "", ...gotParams] = gotParts;
34593
- const [type = "", subtype = ""] = gotType.split("/");
34594
- if (!type || !subtype) {
34595
- return false;
34596
- }
34597
- if (wantType !== "*/*" && gotType !== wantType && `${type}/*` !== wantType && `*/${subtype}` !== wantType) {
34598
- return false;
34599
- }
34600
- if (gotParams.length < wantParams.length) {
34601
- return false;
34602
- }
34603
- const params = new Set(gotParams);
34604
- for (const wantParam of wantParams) {
34605
- if (!params.has(wantParam)) {
34606
- return false;
34607
- }
34608
- }
34609
- return true;
34610
- }
34611
- function matchStatusCode(response, codes) {
34612
- const actual = `${response.status}`;
34613
- const expectedCodes = Array.isArray(codes) ? codes : [codes];
34614
- if (!expectedCodes.length) {
34615
- return false;
34616
- }
34617
- return expectedCodes.some((ec) => {
34618
- const code = `${ec}`;
34619
- if (code === "default") {
34620
- return true;
34621
- }
34622
- if (!codeRangeRE.test(`${code}`)) {
34623
- return code === actual;
34624
- }
34625
- const expectFamily = code.charAt(0);
34626
- if (!expectFamily) {
34627
- throw new Error("Invalid status code range");
34628
- }
34629
- const actualFamily = actual.charAt(0);
34630
- if (!actualFamily) {
34631
- throw new Error(`Invalid response status code: ${actual}`);
34632
- }
34633
- return actualFamily === expectFamily;
34634
- });
34635
- }
34636
- function matchResponse(response, code, contentTypePattern) {
34637
- return matchStatusCode(response, code) && matchContentType(response, contentTypePattern);
34638
- }
34639
- function isConnectionError(err) {
34640
- if (typeof err !== "object" || err == null) {
34641
- return false;
34642
- }
34643
- const isBrowserErr = err instanceof TypeError && err.message.toLowerCase().startsWith("failed to fetch");
34644
- const isNodeErr = err instanceof TypeError && err.message.toLowerCase().startsWith("fetch failed");
34645
- const isBunErr = "name" in err && err.name === "ConnectionError";
34646
- const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnreset";
34647
- return isBrowserErr || isNodeErr || isGenericErr || isBunErr;
34648
- }
34649
- function isTimeoutError(err) {
34650
- if (typeof err !== "object" || err == null) {
34651
- return false;
34652
- }
34653
- const isNative = "name" in err && err.name === "TimeoutError";
34654
- const isLegacyNative = "code" in err && err.code === 23;
34655
- const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnaborted";
34656
- return isNative || isLegacyNative || isGenericErr;
34657
- }
34658
- function isAbortError(err) {
34659
- if (typeof err !== "object" || err == null) {
34660
- return false;
34661
- }
34662
- const isNative = "name" in err && err.name === "AbortError";
34663
- const isLegacyNative = "code" in err && err.code === 20;
34664
- const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnaborted";
34665
- return isNative || isLegacyNative || isGenericErr;
34666
- }
34667
- var DEFAULT_FETCHER = (input, init) => {
34668
- if (init == null) {
34669
- return fetch(input);
34670
- } else {
34671
- return fetch(input, init);
34672
- }
34673
- }, mediaParamSeparator, codeRangeRE;
34674
- var init_http = __esm(() => {
34675
- mediaParamSeparator = /\s*;\s*/g;
34676
- codeRangeRE = new RegExp("^[0-9]xx$", "i");
34677
- });
34678
-
34679
34736
  // src/lib/retries.ts
34680
34737
  async function retry(fetchFn, options) {
34681
34738
  switch (options.config.strategy) {
@@ -43104,7 +43161,7 @@ Use this to create premium tiers with higher limits, apply stricter limits to sp
43104
43161
  function createMCPServer(deps) {
43105
43162
  const server = new McpServer({
43106
43163
  name: "Unkey",
43107
- version: "2.1.1"
43164
+ version: "2.1.2"
43108
43165
  });
43109
43166
  const client = new UnkeyCore({
43110
43167
  rootKey: deps.rootKey,
@@ -44398,7 +44455,7 @@ var routes = ln({
44398
44455
  var app = _e(routes, {
44399
44456
  name: "mcp",
44400
44457
  versionInfo: {
44401
- currentVersion: "2.1.1"
44458
+ currentVersion: "2.1.2"
44402
44459
  }
44403
44460
  });
44404
44461
  Yt(app, process3.argv.slice(2), buildContext(process3));
@@ -44406,5 +44463,5 @@ export {
44406
44463
  app
44407
44464
  };
44408
44465
 
44409
- //# debugId=8A332BD30B1038DF64756E2164756E21
44466
+ //# debugId=77A6B0E086C5EA3664756E2164756E21
44410
44467
  //# sourceMappingURL=mcp-server.js.map