@go-labs-sg/gosh 0.3.0 → 0.4.1

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/dist/index.js +96 -86
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -372,9 +372,8 @@ var import_dotenv = __toESM(require_main(), 1);
372
372
  import path from "path";
373
373
  import_dotenv.config({ path: path.resolve(process.cwd(), ".env"), quiet: true });
374
374
 
375
- // src/index.ts
376
- import { readFileSync, realpathSync } from "fs";
377
- import { fileURLToPath } from "url";
375
+ // src/cli.ts
376
+ import { readFileSync } from "fs";
378
377
 
379
378
  // ../../cli-auth/src/protocol/constants.ts
380
379
  var CLI_ACCESS_TOKEN_TTL_MS = 15 * 60 * 1000;
@@ -14754,6 +14753,22 @@ var assertBunRuntime = (runtime = globalThis.Bun) => {
14754
14753
  };
14755
14754
 
14756
14755
  // ../../cli-auth/src/client/credential-store.ts
14756
+ class CliCredentialStoreUnavailableError extends Error {
14757
+ code = "CLI_CREDENTIAL_STORE_UNAVAILABLE";
14758
+ constructor(product, options) {
14759
+ super(`Secure credential storage is unavailable for the ${product} CLI. Bun.secrets requires the operating system credential store, including Secret Service on Linux. Browser authentication cannot continue without a supported secure store.`, options);
14760
+ this.name = "CliCredentialStoreUnavailableError";
14761
+ }
14762
+ }
14763
+ var useSecrets = async (product, operation) => {
14764
+ try {
14765
+ return await operation();
14766
+ } catch (cause) {
14767
+ if (cause instanceof CliCredentialStoreUnavailableError)
14768
+ throw cause;
14769
+ throw new CliCredentialStoreUnavailableError(product, { cause });
14770
+ }
14771
+ };
14757
14772
  var defaultSecrets = () => {
14758
14773
  assertBunRuntime();
14759
14774
  return Bun.secrets;
@@ -14766,10 +14781,10 @@ var createBunCredentialStore = ({
14766
14781
  const service = `go-labs-cli:${product}`;
14767
14782
  return {
14768
14783
  delete: async () => {
14769
- await secrets.delete({ name: account, service });
14784
+ await useSecrets(product, () => secrets.delete({ name: account, service }));
14770
14785
  },
14771
14786
  get: async () => {
14772
- const value = await secrets.get({ name: account, service });
14787
+ const value = await useSecrets(product, () => secrets.get({ name: account, service }));
14773
14788
  if (value === null)
14774
14789
  return null;
14775
14790
  try {
@@ -14780,11 +14795,11 @@ var createBunCredentialStore = ({
14780
14795
  },
14781
14796
  set: async (credentials) => {
14782
14797
  const parsed = storedCliCredentialsSchema.parse(credentials);
14783
- await secrets.set({
14798
+ await useSecrets(product, () => secrets.set({
14784
14799
  name: account,
14785
14800
  service,
14786
14801
  value: JSON.stringify(parsed)
14787
- });
14802
+ }));
14788
14803
  }
14789
14804
  };
14790
14805
  };
@@ -14958,7 +14973,7 @@ import {
14958
14973
  } from "@trpc/client";
14959
14974
  import SuperJSON from "superjson";
14960
14975
 
14961
- // src/authenticated-event-source.ts
14976
+ // src/features/authenticated-event-source.ts
14962
14977
  class AuthenticatedEventSource {
14963
14978
  url;
14964
14979
  init;
@@ -15069,7 +15084,7 @@ class AuthenticatedEventSource {
15069
15084
  }
15070
15085
  }
15071
15086
 
15072
- // src/runtime.ts
15087
+ // src/runtime/index.ts
15073
15088
  import { createInterface } from "readline/promises";
15074
15089
  var invocationCodes = new Set([
15075
15090
  "USAGE",
@@ -15304,7 +15319,7 @@ var createProcessRuntime = () => ({
15304
15319
  }
15305
15320
  });
15306
15321
 
15307
- // src/api-client.ts
15322
+ // src/config.ts
15308
15323
  var DEFAULT_GOSH_API_BASE_URL = "https://app.gosh.sg";
15309
15324
  var normalizeApiBaseUrl = (value) => {
15310
15325
  const url2 = new URL(value);
@@ -15315,6 +15330,8 @@ var normalizeApiBaseUrl = (value) => {
15315
15330
  url2.pathname = url2.pathname.replace(/\/$/, "");
15316
15331
  return url2.toString().replace(/\/$/, "");
15317
15332
  };
15333
+
15334
+ // src/api-client.ts
15318
15335
  var createGoshClient = ({
15319
15336
  apiBaseUrl,
15320
15337
  accessToken,
@@ -15919,65 +15936,6 @@ var createGoshCommandClient = (client) => ({
15919
15936
  }
15920
15937
  });
15921
15938
 
15922
- // src/parse-args.ts
15923
- var parseArgs = (argv) => {
15924
- const flags = {};
15925
- const positional = [];
15926
- for (let index = 0;index < argv.length; index += 1) {
15927
- const argument = argv[index];
15928
- if (!argument)
15929
- continue;
15930
- if (argument === "--") {
15931
- positional.push(...argv.slice(index + 1));
15932
- break;
15933
- }
15934
- if (argument === "-q") {
15935
- flags.quiet = true;
15936
- continue;
15937
- }
15938
- if (!argument.startsWith("--")) {
15939
- positional.push(argument);
15940
- continue;
15941
- }
15942
- const equalsIndex = argument.indexOf("=");
15943
- if (equalsIndex > 2) {
15944
- flags[argument.slice(2, equalsIndex)] = argument.slice(equalsIndex + 1);
15945
- continue;
15946
- }
15947
- const name = argument.slice(2);
15948
- const next = argv[index + 1];
15949
- if (next !== undefined && !next.startsWith("-")) {
15950
- flags[name] = next;
15951
- index += 1;
15952
- } else {
15953
- flags[name] = true;
15954
- }
15955
- }
15956
- return { flags, positional };
15957
- };
15958
- var getStringFlag = (flags, name) => {
15959
- const value = flags[name];
15960
- return typeof value === "string" ? value : undefined;
15961
- };
15962
-
15963
- // src/parse-json.ts
15964
- var parseJsonInput = (value) => {
15965
- if (value === undefined) {
15966
- throw new CliError("USAGE", "This command requires --input with a JSON object.");
15967
- }
15968
- try {
15969
- const parsed = JSON.parse(value);
15970
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
15971
- throw new CliError("VALIDATION", "--input must be a JSON object.");
15972
- }
15973
- return parsed;
15974
- } catch (error51) {
15975
- if (error51 instanceof CliError)
15976
- throw error51;
15977
- throw new CliError("VALIDATION", `--input is not valid JSON: ${error51 instanceof Error ? error51.message : String(error51)}`);
15978
- }
15979
- };
15980
-
15981
15939
  // src/registry/index.ts
15982
15940
  var defaultMutationTargetKeys = [
15983
15941
  "id",
@@ -16219,8 +16177,7 @@ var findCommand = (positional) => {
16219
16177
  }
16220
16178
  return;
16221
16179
  };
16222
-
16223
- // src/upload.ts
16180
+ // src/features/upload.ts
16224
16181
  import { open, readFile, stat } from "fs/promises";
16225
16182
  import { basename, extname } from "path";
16226
16183
  var contentTypes = {
@@ -16373,7 +16330,66 @@ var uploadFileForCommand = async ({
16373
16330
  };
16374
16331
  };
16375
16332
 
16376
- // src/index.ts
16333
+ // src/parse-args.ts
16334
+ var parseArgs = (argv) => {
16335
+ const flags = {};
16336
+ const positional = [];
16337
+ for (let index = 0;index < argv.length; index += 1) {
16338
+ const argument = argv[index];
16339
+ if (!argument)
16340
+ continue;
16341
+ if (argument === "--") {
16342
+ positional.push(...argv.slice(index + 1));
16343
+ break;
16344
+ }
16345
+ if (argument === "-q") {
16346
+ flags.quiet = true;
16347
+ continue;
16348
+ }
16349
+ if (!argument.startsWith("--")) {
16350
+ positional.push(argument);
16351
+ continue;
16352
+ }
16353
+ const equalsIndex = argument.indexOf("=");
16354
+ if (equalsIndex > 2) {
16355
+ flags[argument.slice(2, equalsIndex)] = argument.slice(equalsIndex + 1);
16356
+ continue;
16357
+ }
16358
+ const name = argument.slice(2);
16359
+ const next = argv[index + 1];
16360
+ if (next !== undefined && !next.startsWith("-")) {
16361
+ flags[name] = next;
16362
+ index += 1;
16363
+ } else {
16364
+ flags[name] = true;
16365
+ }
16366
+ }
16367
+ return { flags, positional };
16368
+ };
16369
+ var getStringFlag = (flags, name) => {
16370
+ const value = flags[name];
16371
+ return typeof value === "string" ? value : undefined;
16372
+ };
16373
+
16374
+ // src/parse-json.ts
16375
+ var parseJsonInput = (value) => {
16376
+ if (value === undefined) {
16377
+ throw new CliError("USAGE", "This command requires --input with a JSON object.");
16378
+ }
16379
+ try {
16380
+ const parsed = JSON.parse(value);
16381
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
16382
+ throw new CliError("VALIDATION", "--input must be a JSON object.");
16383
+ }
16384
+ return parsed;
16385
+ } catch (error51) {
16386
+ if (error51 instanceof CliError)
16387
+ throw error51;
16388
+ throw new CliError("VALIDATION", `--input is not valid JSON: ${error51 instanceof Error ? error51.message : String(error51)}`);
16389
+ }
16390
+ };
16391
+
16392
+ // src/cli.ts
16377
16393
  var packageManifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
16378
16394
  var GOSH_CLI_VERSION = typeof packageManifest.version === "string" ? packageManifest.version : "0.0.0";
16379
16395
  var allowedFlags = new Set([
@@ -16625,27 +16641,21 @@ Waiting for approval\u2026
16625
16641
  return emitError(dependencies.runtime, requestedCommand, error51);
16626
16642
  }
16627
16643
  };
16628
- var isDirectExecution = () => {
16629
- const executable = process.argv[1];
16630
- if (!executable)
16631
- return false;
16632
- try {
16633
- return realpathSync(executable) === realpathSync(fileURLToPath(import.meta.url));
16634
- } catch {
16635
- return false;
16636
- }
16637
- };
16638
- if (isDirectExecution()) {
16644
+ var runGoshCliFromProcess = async () => {
16639
16645
  const runtime2 = createProcessRuntime();
16640
16646
  try {
16641
16647
  assertBunRuntime();
16642
- process.exitCode = await runGoshCli(process.argv.slice(2), { runtime: runtime2 });
16648
+ return await runGoshCli(process.argv.slice(2), { runtime: runtime2 });
16643
16649
  } catch (error51) {
16644
- process.exitCode = emitError(runtime2, "runtime", error51);
16650
+ return emitError(runtime2, "runtime", error51);
16645
16651
  }
16652
+ };
16653
+
16654
+ // src/index.ts
16655
+ if (import.meta.main) {
16656
+ process.exitCode = await runGoshCliFromProcess();
16646
16657
  }
16647
16658
  export {
16648
- GOSH_CLI_VERSION,
16649
16659
  commands,
16650
16660
  runGoshCli
16651
16661
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-labs-sg/gosh",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "GOSH CLI for organizers and AI agents — manage organizations, events, teams, stations, missions, templates, and live operations through the GOSH API.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",