@gapi/gcli 1.8.196 → 1.8.197

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 (2) hide show
  1. package/package.json +1 -1
  2. package/release/index.js +50 -30
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gapi/gcli",
3
- "version": "1.8.196",
3
+ "version": "1.8.197",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/Stradivario/gapi.git"
package/release/index.js CHANGED
@@ -36388,7 +36388,7 @@ var init_gql_client = __esm({
36388
36388
  }
36389
36389
  }).pipe((0, import_operators2.map)((res) => res.updateEnvironmentByName));
36390
36390
  }
36391
- static getConfig() {
36391
+ static getConfig(force = false) {
36392
36392
  return (0, import_rxjs3.combineLatest)([
36393
36393
  readFileAsObservable(tokenDirectory),
36394
36394
  readFileAsObservable(urlDirectory),
@@ -36405,7 +36405,7 @@ var init_gql_client = __esm({
36405
36405
  refresh,
36406
36406
  key,
36407
36407
  timeGenerated,
36408
- expired: (Date.now() - timeGenerated) / 1e3 > 1800,
36408
+ expired: force || (Date.now() - timeGenerated) / 1e3 > 1800,
36409
36409
  uploadUrl
36410
36410
  })),
36411
36411
  (0, import_operators2.switchMap)(
@@ -316820,24 +316820,21 @@ async function startProxy(cmd) {
316820
316820
  `
316821
316821
  );
316822
316822
  }),
316823
- (0, import_operators23.map)((config2) => {
316824
- const client = new Client({
316823
+ (0, import_operators23.map)((config2) => ({
316824
+ ...config2,
316825
+ transport: new StreamableHTTPClientTransport(config2.mcpUrl, {
316826
+ requestInit: {
316827
+ headers: {
316828
+ Authorization: config2.token
316829
+ }
316830
+ },
316831
+ fetch: (input, init) => (0, import_rxjs17.lastValueFrom)(performFetch(input, init))
316832
+ }),
316833
+ client: new Client({
316825
316834
  name: "gapi-proxy-client",
316826
316835
  version: "1.0.0"
316827
- });
316828
- return {
316829
- ...config2,
316830
- transport: new StreamableHTTPClientTransport(config2.mcpUrl, {
316831
- requestInit: {
316832
- headers: {
316833
- Authorization: config2.token
316834
- }
316835
- },
316836
- fetch: fetchLogger
316837
- }),
316838
- client
316839
- };
316840
- }),
316836
+ })
316837
+ })),
316841
316838
  (0, import_operators23.tap)(() => {
316842
316839
  process.stderr.write("Connecting to upstream...\n");
316843
316840
  }),
@@ -316905,7 +316902,7 @@ async function startProxy(cmd) {
316905
316902
  }))
316906
316903
  ).toPromise();
316907
316904
  }
316908
- var import_rxjs17, import_operators23, import_stream2, fetchLogger;
316905
+ var import_rxjs17, import_operators23, import_stream2, performFetch;
316909
316906
  var init_start = __esm({
316910
316907
  "src/commands/proxy/start.ts"() {
316911
316908
  init_client2();
@@ -316917,11 +316914,33 @@ var init_start = __esm({
316917
316914
  import_stream2 = require("stream");
316918
316915
  init_zod();
316919
316916
  init_gql_client();
316920
- fetchLogger = async (input, init) => {
316921
- try {
316922
- const res = await fetch(input, init);
316923
- if (res.body) {
316924
- if (typeof res.body.pipeThrough !== "function") {
316917
+ performFetch = (input, init) => {
316918
+ return (0, import_rxjs17.from)(fetch(input, init)).pipe(
316919
+ (0, import_operators23.switchMap)((res) => {
316920
+ if (res.status === 401 || res.status === 403) {
316921
+ process.stderr.write(
316922
+ `[DEBUG] Request failed with ${res.status}. Refreshing token...
316923
+ `
316924
+ );
316925
+ return GraphqlClienAPI.getConfig(true).pipe(
316926
+ (0, import_operators23.take)(1),
316927
+ (0, import_operators23.switchMap)((config2) => {
316928
+ process.stderr.write(
316929
+ "[DEBUG] Token refreshed. Retrying request...\n"
316930
+ );
316931
+ const headers = new Headers(init?.headers);
316932
+ headers.set("Authorization", config2.token);
316933
+ return fetch(input, {
316934
+ ...init,
316935
+ headers
316936
+ });
316937
+ })
316938
+ );
316939
+ }
316940
+ return (0, import_rxjs17.of)(res);
316941
+ }),
316942
+ (0, import_operators23.map)((res) => {
316943
+ if (typeof res?.body?.pipeThrough !== "function") {
316925
316944
  try {
316926
316945
  const webStream = import_stream2.Readable.toWeb(res.body);
316927
316946
  Object.defineProperty(res, "body", { value: webStream });
@@ -316932,13 +316951,14 @@ var init_start = __esm({
316932
316951
  );
316933
316952
  }
316934
316953
  }
316935
- }
316936
- return res;
316937
- } catch (e) {
316938
- process.stderr.write(`[ERROR] Fetch error: ${e.message}
316954
+ return res;
316955
+ }),
316956
+ (0, import_operators23.catchError)((e) => {
316957
+ process.stderr.write(`[ERROR] Fetch error: ${e.message}
316939
316958
  `);
316940
- throw e;
316941
- }
316959
+ return (0, import_rxjs17.throwError)(() => e);
316960
+ })
316961
+ );
316942
316962
  };
316943
316963
  }
316944
316964
  });