@go-labs-sg/gosh 0.2.0 → 0.4.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.
Files changed (2) hide show
  1. package/dist/index.js +728 -732
  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;
@@ -14958,7 +14957,7 @@ import {
14958
14957
  } from "@trpc/client";
14959
14958
  import SuperJSON from "superjson";
14960
14959
 
14961
- // src/authenticated-event-source.ts
14960
+ // src/features/authenticated-event-source.ts
14962
14961
  class AuthenticatedEventSource {
14963
14962
  url;
14964
14963
  init;
@@ -15069,261 +15068,548 @@ class AuthenticatedEventSource {
15069
15068
  }
15070
15069
  }
15071
15070
 
15072
- // src/registry/typed-operations.ts
15073
- var typedOperations = {
15074
- "health.status": {
15075
- kind: "query",
15076
- invoke: (client, input) => client.health.status.query(input)
15077
- },
15078
- "user.getProfile": {
15079
- kind: "query",
15080
- invoke: (client, input) => client.user.getProfile.query(input)
15081
- },
15082
- "organization.listMine": {
15083
- kind: "query",
15084
- invoke: (client, input) => client.organization.listMine.query(input)
15085
- },
15086
- "organization.getById": {
15087
- kind: "query",
15088
- invoke: (client, input) => client.organization.getById.query(input)
15089
- },
15090
- "organization.listMembers": {
15091
- kind: "query",
15092
- invoke: (client, input) => client.organization.listMembers.query(input)
15093
- },
15094
- "event.list": {
15095
- kind: "query",
15096
- invoke: (client, input) => client.event.list.query(input)
15097
- },
15098
- "event.getById": {
15099
- kind: "query",
15100
- invoke: (client, input) => client.event.getById.query(input)
15101
- },
15102
- "event.getAdminSetup": {
15103
- kind: "query",
15104
- invoke: (client, input) => client.event.getAdminSetup.query(input)
15105
- },
15106
- "event.getAdminParticipants": {
15107
- kind: "query",
15108
- invoke: (client, input) => client.event.getAdminParticipants.query(input)
15109
- },
15110
- "event.getAdminStationsWorkspace": {
15111
- kind: "query",
15112
- invoke: (client, input) => client.event.getAdminStationsWorkspace.query(input)
15113
- },
15114
- "event.getAdminTeams": {
15115
- kind: "query",
15116
- invoke: (client, input) => client.event.getAdminTeams.query(input)
15117
- },
15118
- "event.listSubmissionReviewQueue": {
15119
- kind: "query",
15120
- invoke: (client, input) => client.event.listSubmissionReviewQueue.query(input)
15121
- },
15122
- "event.requestSubmissionImageExport": {
15123
- kind: "mutation",
15124
- invoke: (client, input) => client.event.requestSubmissionImageExport.mutate(input)
15125
- },
15126
- "event.listSubmissionImageExports": {
15127
- kind: "query",
15128
- invoke: (client, input) => client.event.listSubmissionImageExports.query(input)
15129
- },
15130
- "event.getSubmissionImageExportDownload": {
15131
- kind: "mutation",
15132
- invoke: (client, input) => client.event.getSubmissionImageExportDownload.mutate(input)
15133
- },
15134
- "event.listCompletionAnalytics": {
15135
- kind: "query",
15136
- invoke: (client, input) => client.event.listCompletionAnalytics.query(input)
15137
- },
15138
- "event.listActivityTimeline": {
15139
- kind: "query",
15140
- invoke: (client, input) => client.event.listActivityTimeline.query(input)
15141
- },
15142
- "event.listBroadcasts": {
15143
- kind: "query",
15144
- invoke: (client, input) => client.event.listBroadcasts.query(input)
15145
- },
15146
- "event.listRewards": {
15147
- kind: "query",
15148
- invoke: (client, input) => client.event.listRewards.query(input)
15149
- },
15150
- "event.listScoreAdjustments": {
15151
- kind: "query",
15152
- invoke: (client, input) => client.event.listScoreAdjustments.query(input)
15153
- },
15154
- "event.listEventVersions": {
15155
- kind: "query",
15156
- invoke: (client, input) => client.event.listEventVersions.query(input)
15157
- },
15158
- "event.listResultsExport": {
15159
- kind: "query",
15160
- invoke: (client, input) => client.event.listResultsExport.query(input)
15161
- },
15162
- "event.create": {
15163
- kind: "mutation",
15164
- invoke: (client, input) => client.event.create.mutate(input)
15165
- },
15166
- "event.createFromTemplate": {
15167
- kind: "mutation",
15168
- invoke: (client, input) => client.event.createFromTemplate.mutate(input)
15169
- },
15170
- "event.update": {
15171
- kind: "mutation",
15172
- invoke: (client, input) => client.event.update.mutate(input)
15173
- },
15174
- "event.updateStatus": {
15175
- kind: "mutation",
15176
- invoke: (client, input) => client.event.updateStatus.mutate(input)
15177
- },
15178
- "event.addParticipant": {
15179
- kind: "mutation",
15180
- invoke: (client, input) => client.event.addParticipant.mutate(input)
15181
- },
15182
- "event.addParticipants": {
15183
- kind: "mutation",
15184
- invoke: (client, input) => client.event.addParticipants.mutate(input)
15185
- },
15186
- "event.deleteParticipants": {
15187
- kind: "mutation",
15188
- invoke: (client, input) => client.event.deleteParticipants.mutate(input)
15189
- },
15190
- "event.sendParticipantMagicLink": {
15191
- kind: "mutation",
15192
- invoke: (client, input) => client.event.sendParticipantMagicLink.mutate(input)
15193
- },
15194
- "event.sendParticipantMagicLinks": {
15195
- kind: "mutation",
15196
- invoke: (client, input) => client.event.sendParticipantMagicLinks.mutate(input)
15197
- },
15198
- "event.upsertCollaborator": {
15199
- kind: "mutation",
15200
- invoke: (client, input) => client.event.upsertCollaborator.mutate(input)
15201
- },
15202
- "event.removeCollaborator": {
15203
- kind: "mutation",
15204
- invoke: (client, input) => client.event.removeCollaborator.mutate(input)
15205
- },
15206
- "event.createEventVersion": {
15207
- kind: "mutation",
15208
- invoke: (client, input) => client.event.createEventVersion.mutate(input)
15209
- },
15210
- "event.rollbackEventVersion": {
15211
- kind: "mutation",
15212
- invoke: (client, input) => client.event.rollbackEventVersion.mutate(input)
15213
- },
15214
- "event.createStation": {
15215
- kind: "mutation",
15216
- invoke: (client, input) => client.event.createStation.mutate(input)
15217
- },
15218
- "event.updateStation": {
15219
- kind: "mutation",
15220
- invoke: (client, input) => client.event.updateStation.mutate(input)
15221
- },
15222
- "event.cloneStation": {
15223
- kind: "mutation",
15224
- invoke: (client, input) => client.event.cloneStation.mutate(input)
15225
- },
15226
- "event.archiveStation": {
15227
- kind: "mutation",
15228
- invoke: (client, input) => client.event.archiveStation.mutate(input)
15229
- },
15230
- "event.reorderStations": {
15231
- kind: "mutation",
15232
- invoke: (client, input) => client.event.reorderStations.mutate(input)
15233
- },
15234
- "event.createMission": {
15235
- kind: "mutation",
15236
- invoke: (client, input) => client.event.createMission.mutate(input)
15237
- },
15238
- "event.updateMission": {
15239
- kind: "mutation",
15240
- invoke: (client, input) => client.event.updateMission.mutate(input)
15241
- },
15242
- "event.archiveMission": {
15243
- kind: "mutation",
15244
- invoke: (client, input) => client.event.archiveMission.mutate(input)
15245
- },
15246
- "event.reorderMissions": {
15247
- kind: "mutation",
15248
- invoke: (client, input) => client.event.reorderMissions.mutate(input)
15249
- },
15250
- "team.list": {
15251
- kind: "query",
15252
- invoke: (client, input) => client.team.list.query(input)
15253
- },
15254
- "team.create": {
15255
- kind: "mutation",
15256
- invoke: (client, input) => client.team.create.mutate(input)
15257
- },
15258
- "team.update": {
15259
- kind: "mutation",
15260
- invoke: (client, input) => client.team.update.mutate(input)
15261
- },
15262
- "team.assignMember": {
15263
- kind: "mutation",
15264
- invoke: (client, input) => client.team.assignMember.mutate(input)
15265
- },
15266
- "team.removeMember": {
15267
- kind: "mutation",
15268
- invoke: (client, input) => client.team.removeMember.mutate(input)
15269
- },
15270
- "team.setPlayMode": {
15271
- kind: "mutation",
15272
- invoke: (client, input) => client.team.setPlayMode.mutate(input)
15273
- },
15274
- "team.setSubmissionAccess": {
15275
- kind: "mutation",
15276
- invoke: (client, input) => client.team.setSubmissionAccess.mutate(input)
15277
- },
15278
- "template.list": {
15279
- kind: "query",
15280
- invoke: (client, input) => client.template.list.query(input)
15281
- },
15282
- "template.getById": {
15283
- kind: "query",
15284
- invoke: (client, input) => client.template.getById.query(input)
15285
- },
15286
- "template.create": {
15287
- kind: "mutation",
15288
- invoke: (client, input) => client.template.create.mutate(input)
15289
- },
15290
- "template.update": {
15291
- kind: "mutation",
15292
- invoke: (client, input) => client.template.update.mutate(input)
15293
- },
15294
- "template.updateMetadata": {
15295
- kind: "mutation",
15296
- invoke: (client, input) => client.template.updateMetadata.mutate(input)
15297
- },
15298
- "template.delete": {
15299
- kind: "mutation",
15300
- invoke: (client, input) => client.template.delete.mutate(input)
15301
- },
15302
- "event.createBroadcast": {
15303
- kind: "mutation",
15304
- invoke: (client, input) => client.event.createBroadcast.mutate(input)
15305
- },
15306
- "event.cancelBroadcast": {
15307
- kind: "mutation",
15308
- invoke: (client, input) => client.event.cancelBroadcast.mutate(input)
15309
- },
15310
- "event.deleteBroadcast": {
15311
- kind: "mutation",
15312
- invoke: (client, input) => client.event.deleteBroadcast.mutate(input)
15313
- },
15314
- "event.deliverDueBroadcasts": {
15315
- kind: "mutation",
15316
- invoke: (client, input) => client.event.deliverDueBroadcasts.mutate(input)
15317
- },
15318
- "event.createReward": {
15319
- kind: "mutation",
15320
- invoke: (client, input) => client.event.createReward.mutate(input)
15321
- },
15322
- "event.updateReward": {
15323
- kind: "mutation",
15324
- invoke: (client, input) => client.event.updateReward.mutate(input)
15325
- },
15326
- "event.createScoreAdjustment": {
15071
+ // src/runtime/index.ts
15072
+ import { createInterface } from "readline/promises";
15073
+ var invocationCodes = new Set([
15074
+ "USAGE",
15075
+ "VALIDATION",
15076
+ "CONFIRMATION_REQUIRED",
15077
+ "ABORTED"
15078
+ ]);
15079
+ var trpcCodeMap = {
15080
+ BAD_REQUEST: "VALIDATION",
15081
+ CONFLICT: "CONFLICT",
15082
+ FORBIDDEN: "AUTHORIZATION",
15083
+ INTERNAL_SERVER_ERROR: "API",
15084
+ NOT_FOUND: "NOT_FOUND",
15085
+ PARSE_ERROR: "VALIDATION",
15086
+ TIMEOUT: "NETWORK",
15087
+ TOO_MANY_REQUESTS: "API",
15088
+ UNAUTHORIZED: "AUTHENTICATION",
15089
+ UNPROCESSABLE_CONTENT: "VALIDATION"
15090
+ };
15091
+ var networkMessagePattern = /\b(fetch failed|network error|unable to connect|econnrefused|econnreset|enotfound|etimedout|socket hang up)\b/i;
15092
+ var isNetworkError = (error51, depth = 0) => {
15093
+ if (depth > 3 || !isRecord(error51))
15094
+ return false;
15095
+ const message = typeof error51.message === "string" ? error51.message : undefined;
15096
+ const code = typeof error51.code === "string" ? error51.code : undefined;
15097
+ if (message && networkMessagePattern.test(message) || code && networkMessagePattern.test(code)) {
15098
+ return true;
15099
+ }
15100
+ return isNetworkError(error51.cause, depth + 1);
15101
+ };
15102
+
15103
+ class CliError extends Error {
15104
+ code;
15105
+ details;
15106
+ constructor(code, message, details) {
15107
+ super(message);
15108
+ this.name = "CliError";
15109
+ this.code = code;
15110
+ this.details = details;
15111
+ }
15112
+ }
15113
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
15114
+ var isJsonValue = (value) => {
15115
+ if (value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number") {
15116
+ return true;
15117
+ }
15118
+ if (Array.isArray(value))
15119
+ return value.every(isJsonValue);
15120
+ return isRecord(value) && Object.values(value).every(isJsonValue);
15121
+ };
15122
+ var toJsonValue = (value) => {
15123
+ const serialized = JSON.stringify(value, (_key, nestedValue) => {
15124
+ if (typeof nestedValue === "bigint")
15125
+ return nestedValue.toString();
15126
+ return nestedValue;
15127
+ });
15128
+ if (serialized === undefined)
15129
+ return null;
15130
+ return JSON.parse(serialized);
15131
+ };
15132
+ var sensitiveKeyPattern = /(api.?key|authorization|join.?code|password|secret|share.?token|token|payload|proof|receipt)/i;
15133
+ var presignedUrlPattern = /[?&](?:X-Amz|X-Goog)-(?:Credential|Signature)=/i;
15134
+ var sanitizeValue = (value, seen = new WeakSet) => {
15135
+ if (value === null || typeof value === "boolean" || typeof value === "number") {
15136
+ return value;
15137
+ }
15138
+ if (typeof value === "string") {
15139
+ return presignedUrlPattern.test(value) ? "[redacted]" : value;
15140
+ }
15141
+ if (typeof value === "bigint")
15142
+ return value.toString();
15143
+ if (value instanceof Date)
15144
+ return value.toISOString();
15145
+ if (typeof value !== "object" || value === null)
15146
+ return String(value);
15147
+ if (seen.has(value))
15148
+ return "[circular]";
15149
+ seen.add(value);
15150
+ if (Array.isArray(value)) {
15151
+ return value.map((item) => sanitizeValue(item, seen));
15152
+ }
15153
+ if (!isRecord(value))
15154
+ return String(value);
15155
+ return Object.fromEntries(Object.entries(value).map(([key, nestedValue]) => [
15156
+ key,
15157
+ sensitiveKeyPattern.test(key) ? "[redacted]" : sanitizeValue(nestedValue, seen)
15158
+ ]));
15159
+ };
15160
+ var normalizeError = (error51) => {
15161
+ if (error51 instanceof CliError) {
15162
+ return {
15163
+ code: error51.code,
15164
+ message: error51.message,
15165
+ ...error51.details ? { details: error51.details } : {}
15166
+ };
15167
+ }
15168
+ if (isNetworkError(error51)) {
15169
+ return {
15170
+ code: "NETWORK",
15171
+ message: error51 instanceof Error ? error51.message : "The GOSH API could not be reached."
15172
+ };
15173
+ }
15174
+ if (isRecord(error51)) {
15175
+ const data = isRecord(error51.data) ? error51.data : undefined;
15176
+ const rawCode = typeof data?.code === "string" ? data.code : undefined;
15177
+ const code = rawCode ? trpcCodeMap[rawCode] ?? "API" : "INTERNAL";
15178
+ const message = typeof error51.message === "string" ? error51.message : "The GOSH API request failed.";
15179
+ const details = isRecord(data?.zodError) && isJsonValue(data.zodError) ? { validation: data.zodError } : undefined;
15180
+ return { code, message, ...details ? { details } : {} };
15181
+ }
15182
+ return {
15183
+ code: "INTERNAL",
15184
+ message: error51 instanceof Error ? error51.message : String(error51)
15185
+ };
15186
+ };
15187
+ var serialize = (value) => `${JSON.stringify(value, null, 2)}
15188
+ `;
15189
+ var redactKnownSecrets = (value, _runtime) => {
15190
+ return value.replace(/\bBearer\s+\S+/giu, "Bearer [redacted]");
15191
+ };
15192
+ var emitSuccess = (runtime2, invocation, data) => {
15193
+ runtime2.stdout.write(serialize({
15194
+ ok: true,
15195
+ data: toJsonValue(data),
15196
+ meta: {
15197
+ apiBaseUrl: invocation.apiBaseUrl,
15198
+ cliVersion: invocation.cliVersion,
15199
+ command: invocation.command
15200
+ }
15201
+ }));
15202
+ return 0;
15203
+ };
15204
+ var emitSubscriptionEvent = (runtime2, invocation, data) => {
15205
+ runtime2.stdout.write(`${JSON.stringify({
15206
+ ok: true,
15207
+ data: toJsonValue(data),
15208
+ meta: {
15209
+ apiBaseUrl: invocation.apiBaseUrl,
15210
+ cliVersion: invocation.cliVersion,
15211
+ command: invocation.command,
15212
+ stream: true
15213
+ }
15214
+ })}
15215
+ `);
15216
+ };
15217
+ var emitError = (runtime2, command, error51) => {
15218
+ const normalized = normalizeError(error51);
15219
+ runtime2.stderr.write(redactKnownSecrets(serialize({ ok: false, error: normalized, meta: { command } }), runtime2));
15220
+ return invocationCodes.has(normalized.code) ? 2 : 1;
15221
+ };
15222
+ var effectLabels = {
15223
+ delete: "deletes or permanently revokes data",
15224
+ email: "sends email",
15225
+ "external-write": "writes to an external delivery surface",
15226
+ "state-change": "changes GOSH state"
15227
+ };
15228
+ var permissionFlag = {
15229
+ delete: "allow-delete",
15230
+ email: "allow-email",
15231
+ "external-write": "allow-external-write",
15232
+ "state-change": "allow-state-change"
15233
+ };
15234
+ var getTargetCandidates = (input, targetKeys) => {
15235
+ for (const key of targetKeys) {
15236
+ if (key === "$self")
15237
+ return new Set(["self"]);
15238
+ if (!isRecord(input) || !(key in input))
15239
+ continue;
15240
+ const rawValue = input[key];
15241
+ const values = Array.isArray(rawValue) ? rawValue : [rawValue];
15242
+ const candidates = new Set(values.filter((value) => typeof value === "string" || typeof value === "number").map(String));
15243
+ if (candidates.size > 0)
15244
+ return candidates;
15245
+ }
15246
+ return new Set;
15247
+ };
15248
+ var confirmCommand = async ({
15249
+ action,
15250
+ effects,
15251
+ flags,
15252
+ input,
15253
+ runtime: runtime2,
15254
+ target,
15255
+ targetKeys = []
15256
+ }) => {
15257
+ if (effects.length === 0)
15258
+ return;
15259
+ if (!target?.trim()) {
15260
+ throw new CliError("CONFIRMATION_REQUIRED", "Sensitive commands require --target with the exact resource being changed.", { target: "required" });
15261
+ }
15262
+ if (!getTargetCandidates(input, targetKeys).has(target.trim())) {
15263
+ throw new CliError("CONFIRMATION_REQUIRED", `--target must exactly match the command's primary resource (${targetKeys.map((key) => key === "$self" ? "self" : key).join(", ")}).`);
15264
+ }
15265
+ const uniqueEffects = [...new Set(effects)];
15266
+ const missingFlags = uniqueEffects.map((effect) => permissionFlag[effect]).filter((flag) => flags[flag] !== true).map((flag) => `--${flag}`);
15267
+ if (missingFlags.length === 0)
15268
+ return;
15269
+ if (!runtime2.isTTY) {
15270
+ throw new CliError("CONFIRMATION_REQUIRED", "Non-interactive sensitive commands require every applicable allow flag.", { missingFlags });
15271
+ }
15272
+ runtime2.stderr.write(`${[
15273
+ "GOSH workflow preview",
15274
+ `Action: ${action}`,
15275
+ `Target: ${target}`,
15276
+ `Effects: ${uniqueEffects.map((effect) => effectLabels[effect]).join("; ")}`
15277
+ ].join(`
15278
+ `)}
15279
+ `);
15280
+ if (!runtime2.prompt) {
15281
+ throw new CliError("CONFIRMATION_REQUIRED", "This command needs an interactive confirmation prompt.");
15282
+ }
15283
+ const answer = await runtime2.prompt("Type CONFIRM to continue: ");
15284
+ if (answer !== "CONFIRM") {
15285
+ throw new CliError("ABORTED", "Command aborted by user.");
15286
+ }
15287
+ };
15288
+ var createProcessRuntime = () => ({
15289
+ stdout: { write: (value) => process.stdout.write(value) },
15290
+ stderr: { write: (value) => process.stderr.write(value) },
15291
+ isTTY: Boolean(process.stdin.isTTY && process.stderr.isTTY),
15292
+ env: process.env,
15293
+ prompt: async (message) => {
15294
+ const prompt = createInterface({
15295
+ input: process.stdin,
15296
+ output: process.stderr
15297
+ });
15298
+ try {
15299
+ return await prompt.question(message);
15300
+ } finally {
15301
+ prompt.close();
15302
+ }
15303
+ }
15304
+ });
15305
+
15306
+ // src/config.ts
15307
+ var DEFAULT_GOSH_API_BASE_URL = "https://app.gosh.sg";
15308
+ var normalizeApiBaseUrl = (value) => {
15309
+ const url2 = new URL(value);
15310
+ const isLocalHttp = url2.protocol === "http:" && (url2.hostname === "localhost" || url2.hostname === "127.0.0.1");
15311
+ if (url2.protocol !== "https:" && !isLocalHttp) {
15312
+ throw new Error("GOSH API URL must use HTTPS, except for localhost development.");
15313
+ }
15314
+ url2.pathname = url2.pathname.replace(/\/$/, "");
15315
+ return url2.toString().replace(/\/$/, "");
15316
+ };
15317
+
15318
+ // src/api-client.ts
15319
+ var createGoshClient = ({
15320
+ apiBaseUrl,
15321
+ accessToken,
15322
+ debug = false,
15323
+ quiet = false
15324
+ }) => {
15325
+ const headers = () => ({
15326
+ "x-trpc-source": "gosh-cli",
15327
+ ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {}
15328
+ });
15329
+ return createTRPCProxyClient({
15330
+ links: [
15331
+ loggerLink({
15332
+ enabled: () => debug && !quiet,
15333
+ colorMode: "ansi",
15334
+ withContext: false,
15335
+ console: {
15336
+ log: (...args) => console.error(...args.map((argument) => sanitizeValue(argument))),
15337
+ error: (...args) => console.error(...args.map((argument) => sanitizeValue(argument)))
15338
+ }
15339
+ }),
15340
+ splitLink({
15341
+ condition: (operation) => operation.type === "subscription",
15342
+ true: httpSubscriptionLink({
15343
+ EventSource: AuthenticatedEventSource,
15344
+ eventSourceOptions: { headers: headers() },
15345
+ transformer: SuperJSON,
15346
+ url: `${apiBaseUrl}/api/trpc`
15347
+ }),
15348
+ false: httpBatchLink({
15349
+ headers,
15350
+ transformer: SuperJSON,
15351
+ url: `${apiBaseUrl}/api/trpc`
15352
+ })
15353
+ })
15354
+ ]
15355
+ });
15356
+ };
15357
+
15358
+ // src/registry/typed-operations.ts
15359
+ var typedOperations = {
15360
+ "health.status": {
15361
+ kind: "query",
15362
+ invoke: (client, input) => client.health.status.query(input)
15363
+ },
15364
+ "user.getProfile": {
15365
+ kind: "query",
15366
+ invoke: (client, input) => client.user.getProfile.query(input)
15367
+ },
15368
+ "organization.listMine": {
15369
+ kind: "query",
15370
+ invoke: (client, input) => client.organization.listMine.query(input)
15371
+ },
15372
+ "organization.getById": {
15373
+ kind: "query",
15374
+ invoke: (client, input) => client.organization.getById.query(input)
15375
+ },
15376
+ "organization.listMembers": {
15377
+ kind: "query",
15378
+ invoke: (client, input) => client.organization.listMembers.query(input)
15379
+ },
15380
+ "event.list": {
15381
+ kind: "query",
15382
+ invoke: (client, input) => client.event.list.query(input)
15383
+ },
15384
+ "event.getById": {
15385
+ kind: "query",
15386
+ invoke: (client, input) => client.event.getById.query(input)
15387
+ },
15388
+ "event.getAdminSetup": {
15389
+ kind: "query",
15390
+ invoke: (client, input) => client.event.getAdminSetup.query(input)
15391
+ },
15392
+ "event.getAdminParticipants": {
15393
+ kind: "query",
15394
+ invoke: (client, input) => client.event.getAdminParticipants.query(input)
15395
+ },
15396
+ "event.getAdminStationsWorkspace": {
15397
+ kind: "query",
15398
+ invoke: (client, input) => client.event.getAdminStationsWorkspace.query(input)
15399
+ },
15400
+ "event.getAdminTeams": {
15401
+ kind: "query",
15402
+ invoke: (client, input) => client.event.getAdminTeams.query(input)
15403
+ },
15404
+ "event.listSubmissionReviewQueue": {
15405
+ kind: "query",
15406
+ invoke: (client, input) => client.event.listSubmissionReviewQueue.query(input)
15407
+ },
15408
+ "event.requestSubmissionImageExport": {
15409
+ kind: "mutation",
15410
+ invoke: (client, input) => client.event.requestSubmissionImageExport.mutate(input)
15411
+ },
15412
+ "event.listSubmissionImageExports": {
15413
+ kind: "query",
15414
+ invoke: (client, input) => client.event.listSubmissionImageExports.query(input)
15415
+ },
15416
+ "event.getSubmissionImageExportDownload": {
15417
+ kind: "mutation",
15418
+ invoke: (client, input) => client.event.getSubmissionImageExportDownload.mutate(input)
15419
+ },
15420
+ "event.listCompletionAnalytics": {
15421
+ kind: "query",
15422
+ invoke: (client, input) => client.event.listCompletionAnalytics.query(input)
15423
+ },
15424
+ "event.listActivityTimeline": {
15425
+ kind: "query",
15426
+ invoke: (client, input) => client.event.listActivityTimeline.query(input)
15427
+ },
15428
+ "event.listBroadcasts": {
15429
+ kind: "query",
15430
+ invoke: (client, input) => client.event.listBroadcasts.query(input)
15431
+ },
15432
+ "event.listRewards": {
15433
+ kind: "query",
15434
+ invoke: (client, input) => client.event.listRewards.query(input)
15435
+ },
15436
+ "event.listScoreAdjustments": {
15437
+ kind: "query",
15438
+ invoke: (client, input) => client.event.listScoreAdjustments.query(input)
15439
+ },
15440
+ "event.listEventVersions": {
15441
+ kind: "query",
15442
+ invoke: (client, input) => client.event.listEventVersions.query(input)
15443
+ },
15444
+ "event.listResultsExport": {
15445
+ kind: "query",
15446
+ invoke: (client, input) => client.event.listResultsExport.query(input)
15447
+ },
15448
+ "event.create": {
15449
+ kind: "mutation",
15450
+ invoke: (client, input) => client.event.create.mutate(input)
15451
+ },
15452
+ "event.createFromTemplate": {
15453
+ kind: "mutation",
15454
+ invoke: (client, input) => client.event.createFromTemplate.mutate(input)
15455
+ },
15456
+ "event.update": {
15457
+ kind: "mutation",
15458
+ invoke: (client, input) => client.event.update.mutate(input)
15459
+ },
15460
+ "event.updateStatus": {
15461
+ kind: "mutation",
15462
+ invoke: (client, input) => client.event.updateStatus.mutate(input)
15463
+ },
15464
+ "event.addParticipant": {
15465
+ kind: "mutation",
15466
+ invoke: (client, input) => client.event.addParticipant.mutate(input)
15467
+ },
15468
+ "event.addParticipants": {
15469
+ kind: "mutation",
15470
+ invoke: (client, input) => client.event.addParticipants.mutate(input)
15471
+ },
15472
+ "event.deleteParticipants": {
15473
+ kind: "mutation",
15474
+ invoke: (client, input) => client.event.deleteParticipants.mutate(input)
15475
+ },
15476
+ "event.sendParticipantMagicLink": {
15477
+ kind: "mutation",
15478
+ invoke: (client, input) => client.event.sendParticipantMagicLink.mutate(input)
15479
+ },
15480
+ "event.sendParticipantMagicLinks": {
15481
+ kind: "mutation",
15482
+ invoke: (client, input) => client.event.sendParticipantMagicLinks.mutate(input)
15483
+ },
15484
+ "event.upsertCollaborator": {
15485
+ kind: "mutation",
15486
+ invoke: (client, input) => client.event.upsertCollaborator.mutate(input)
15487
+ },
15488
+ "event.removeCollaborator": {
15489
+ kind: "mutation",
15490
+ invoke: (client, input) => client.event.removeCollaborator.mutate(input)
15491
+ },
15492
+ "event.createEventVersion": {
15493
+ kind: "mutation",
15494
+ invoke: (client, input) => client.event.createEventVersion.mutate(input)
15495
+ },
15496
+ "event.rollbackEventVersion": {
15497
+ kind: "mutation",
15498
+ invoke: (client, input) => client.event.rollbackEventVersion.mutate(input)
15499
+ },
15500
+ "event.createStation": {
15501
+ kind: "mutation",
15502
+ invoke: (client, input) => client.event.createStation.mutate(input)
15503
+ },
15504
+ "event.updateStation": {
15505
+ kind: "mutation",
15506
+ invoke: (client, input) => client.event.updateStation.mutate(input)
15507
+ },
15508
+ "event.cloneStation": {
15509
+ kind: "mutation",
15510
+ invoke: (client, input) => client.event.cloneStation.mutate(input)
15511
+ },
15512
+ "event.archiveStation": {
15513
+ kind: "mutation",
15514
+ invoke: (client, input) => client.event.archiveStation.mutate(input)
15515
+ },
15516
+ "event.reorderStations": {
15517
+ kind: "mutation",
15518
+ invoke: (client, input) => client.event.reorderStations.mutate(input)
15519
+ },
15520
+ "event.createMission": {
15521
+ kind: "mutation",
15522
+ invoke: (client, input) => client.event.createMission.mutate(input)
15523
+ },
15524
+ "event.updateMission": {
15525
+ kind: "mutation",
15526
+ invoke: (client, input) => client.event.updateMission.mutate(input)
15527
+ },
15528
+ "event.archiveMission": {
15529
+ kind: "mutation",
15530
+ invoke: (client, input) => client.event.archiveMission.mutate(input)
15531
+ },
15532
+ "event.reorderMissions": {
15533
+ kind: "mutation",
15534
+ invoke: (client, input) => client.event.reorderMissions.mutate(input)
15535
+ },
15536
+ "team.list": {
15537
+ kind: "query",
15538
+ invoke: (client, input) => client.team.list.query(input)
15539
+ },
15540
+ "team.create": {
15541
+ kind: "mutation",
15542
+ invoke: (client, input) => client.team.create.mutate(input)
15543
+ },
15544
+ "team.update": {
15545
+ kind: "mutation",
15546
+ invoke: (client, input) => client.team.update.mutate(input)
15547
+ },
15548
+ "team.assignMember": {
15549
+ kind: "mutation",
15550
+ invoke: (client, input) => client.team.assignMember.mutate(input)
15551
+ },
15552
+ "team.removeMember": {
15553
+ kind: "mutation",
15554
+ invoke: (client, input) => client.team.removeMember.mutate(input)
15555
+ },
15556
+ "team.setPlayMode": {
15557
+ kind: "mutation",
15558
+ invoke: (client, input) => client.team.setPlayMode.mutate(input)
15559
+ },
15560
+ "team.setSubmissionAccess": {
15561
+ kind: "mutation",
15562
+ invoke: (client, input) => client.team.setSubmissionAccess.mutate(input)
15563
+ },
15564
+ "template.list": {
15565
+ kind: "query",
15566
+ invoke: (client, input) => client.template.list.query(input)
15567
+ },
15568
+ "template.getById": {
15569
+ kind: "query",
15570
+ invoke: (client, input) => client.template.getById.query(input)
15571
+ },
15572
+ "template.create": {
15573
+ kind: "mutation",
15574
+ invoke: (client, input) => client.template.create.mutate(input)
15575
+ },
15576
+ "template.update": {
15577
+ kind: "mutation",
15578
+ invoke: (client, input) => client.template.update.mutate(input)
15579
+ },
15580
+ "template.updateMetadata": {
15581
+ kind: "mutation",
15582
+ invoke: (client, input) => client.template.updateMetadata.mutate(input)
15583
+ },
15584
+ "template.delete": {
15585
+ kind: "mutation",
15586
+ invoke: (client, input) => client.template.delete.mutate(input)
15587
+ },
15588
+ "event.createBroadcast": {
15589
+ kind: "mutation",
15590
+ invoke: (client, input) => client.event.createBroadcast.mutate(input)
15591
+ },
15592
+ "event.cancelBroadcast": {
15593
+ kind: "mutation",
15594
+ invoke: (client, input) => client.event.cancelBroadcast.mutate(input)
15595
+ },
15596
+ "event.deleteBroadcast": {
15597
+ kind: "mutation",
15598
+ invoke: (client, input) => client.event.deleteBroadcast.mutate(input)
15599
+ },
15600
+ "event.deliverDueBroadcasts": {
15601
+ kind: "mutation",
15602
+ invoke: (client, input) => client.event.deliverDueBroadcasts.mutate(input)
15603
+ },
15604
+ "event.createReward": {
15605
+ kind: "mutation",
15606
+ invoke: (client, input) => client.event.createReward.mutate(input)
15607
+ },
15608
+ "event.updateReward": {
15609
+ kind: "mutation",
15610
+ invoke: (client, input) => client.event.updateReward.mutate(input)
15611
+ },
15612
+ "event.createScoreAdjustment": {
15327
15613
  kind: "mutation",
15328
15614
  invoke: (client, input) => client.event.createScoreAdjustment.mutate(input)
15329
15615
  },
@@ -15515,466 +15801,124 @@ var typedOperations = {
15515
15801
  kind: "mutation",
15516
15802
  invoke: (client, input) => client.event.completeMissionMediaMultipartUpload.mutate(input)
15517
15803
  },
15518
- "event.abortMissionMediaMultipartUpload": {
15519
- kind: "mutation",
15520
- invoke: (client, input) => client.event.abortMissionMediaMultipartUpload.mutate(input)
15521
- },
15522
- "event.onPlayerEventChanged": {
15523
- kind: "subscription",
15524
- subscribe: (client, input, observer) => client.event.onPlayerEventChanged.subscribe(input, {
15525
- onComplete: observer.complete,
15526
- onData: observer.next,
15527
- onError: observer.error
15528
- })
15529
- },
15530
- "event.onSubmissionReviewQueueChanged": {
15531
- kind: "subscription",
15532
- subscribe: (client, input, observer) => client.event.onSubmissionReviewQueueChanged.subscribe(input, {
15533
- onComplete: observer.complete,
15534
- onData: observer.next,
15535
- onError: observer.error
15536
- })
15537
- },
15538
- "organization.create": {
15539
- kind: "mutation",
15540
- invoke: (client, input) => client.organization.create.mutate(input)
15541
- },
15542
- "organization.update": {
15543
- kind: "mutation",
15544
- invoke: (client, input) => client.organization.update.mutate(input)
15545
- },
15546
- "organization.checkSlug": {
15547
- kind: "mutation",
15548
- invoke: (client, input) => client.organization.checkSlug.mutate(input)
15549
- },
15550
- "organization.checkOrganizationAccess": {
15551
- kind: "query",
15552
- invoke: (client, input) => client.organization.checkOrganizationAccess.query(input)
15553
- },
15554
- "organization.getOnboardingState": {
15555
- kind: "query",
15556
- invoke: (client, input) => client.organization.getOnboardingState.query(input)
15557
- },
15558
- "organization.getInvitation": {
15559
- kind: "query",
15560
- invoke: (client, input) => client.organization.getInvitation.query(input)
15561
- },
15562
- "organization.acceptInvitation": {
15563
- kind: "mutation",
15564
- invoke: (client, input) => client.organization.acceptInvitation.mutate(input)
15565
- },
15566
- "organization.rejectInvitation": {
15567
- kind: "mutation",
15568
- invoke: (client, input) => client.organization.rejectInvitation.mutate(input)
15569
- },
15570
- "organization.cancelInvitation": {
15571
- kind: "mutation",
15572
- invoke: (client, input) => client.organization.cancelInvitation.mutate(input)
15573
- },
15574
- "organization.inviteMember": {
15575
- kind: "mutation",
15576
- invoke: (client, input) => client.organization.inviteMember.mutate(input)
15577
- },
15578
- "organization.removeMember": {
15579
- kind: "mutation",
15580
- invoke: (client, input) => client.organization.removeMember.mutate(input)
15581
- },
15582
- "organization.updateMemberRole": {
15583
- kind: "mutation",
15584
- invoke: (client, input) => client.organization.updateMemberRole.mutate(input)
15585
- },
15586
- "organization.listAllForAdmin": {
15587
- kind: "query",
15588
- invoke: (client, input) => client.organization.listAllForAdmin.query(input)
15589
- },
15590
- "template.createSystem": {
15591
- kind: "mutation",
15592
- invoke: (client, input) => client.template.createSystem.mutate(input)
15593
- },
15594
- "user.listAdmin": {
15595
- kind: "query",
15596
- invoke: (client, input) => client.user.listAdmin.query(input)
15597
- },
15598
- "user.updateGlobalRole": {
15599
- kind: "mutation",
15600
- invoke: (client, input) => client.user.updateGlobalRole.mutate(input)
15601
- },
15602
- "user.ban": {
15603
- kind: "mutation",
15604
- invoke: (client, input) => client.user.ban.mutate(input)
15605
- },
15606
- "user.unban": {
15804
+ "event.abortMissionMediaMultipartUpload": {
15607
15805
  kind: "mutation",
15608
- invoke: (client, input) => client.user.unban.mutate(input)
15609
- }
15610
- };
15611
-
15612
- // src/runtime.ts
15613
- import { createInterface } from "readline/promises";
15614
- var invocationCodes = new Set([
15615
- "USAGE",
15616
- "VALIDATION",
15617
- "CONFIRMATION_REQUIRED",
15618
- "ABORTED"
15619
- ]);
15620
- var trpcCodeMap = {
15621
- BAD_REQUEST: "VALIDATION",
15622
- CONFLICT: "CONFLICT",
15623
- FORBIDDEN: "AUTHORIZATION",
15624
- INTERNAL_SERVER_ERROR: "API",
15625
- NOT_FOUND: "NOT_FOUND",
15626
- PARSE_ERROR: "VALIDATION",
15627
- TIMEOUT: "NETWORK",
15628
- TOO_MANY_REQUESTS: "API",
15629
- UNAUTHORIZED: "AUTHENTICATION",
15630
- UNPROCESSABLE_CONTENT: "VALIDATION"
15631
- };
15632
- var networkMessagePattern = /\b(fetch failed|network error|unable to connect|econnrefused|econnreset|enotfound|etimedout|socket hang up)\b/i;
15633
- var isNetworkError = (error51, depth = 0) => {
15634
- if (depth > 3 || !isRecord(error51))
15635
- return false;
15636
- const message = typeof error51.message === "string" ? error51.message : undefined;
15637
- const code = typeof error51.code === "string" ? error51.code : undefined;
15638
- if (message && networkMessagePattern.test(message) || code && networkMessagePattern.test(code)) {
15639
- return true;
15640
- }
15641
- return isNetworkError(error51.cause, depth + 1);
15642
- };
15643
-
15644
- class CliError extends Error {
15645
- code;
15646
- details;
15647
- constructor(code, message, details) {
15648
- super(message);
15649
- this.name = "CliError";
15650
- this.code = code;
15651
- this.details = details;
15652
- }
15653
- }
15654
- var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
15655
- var isJsonValue = (value) => {
15656
- if (value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number") {
15657
- return true;
15658
- }
15659
- if (Array.isArray(value))
15660
- return value.every(isJsonValue);
15661
- return isRecord(value) && Object.values(value).every(isJsonValue);
15662
- };
15663
- var toJsonValue = (value) => {
15664
- const serialized = JSON.stringify(value, (_key, nestedValue) => {
15665
- if (typeof nestedValue === "bigint")
15666
- return nestedValue.toString();
15667
- return nestedValue;
15668
- });
15669
- if (serialized === undefined)
15670
- return null;
15671
- return JSON.parse(serialized);
15672
- };
15673
- var sensitiveKeyPattern = /(api.?key|authorization|join.?code|password|secret|share.?token|token|payload|proof|receipt)/i;
15674
- var presignedUrlPattern = /[?&](?:X-Amz|X-Goog)-(?:Credential|Signature)=/i;
15675
- var sanitizeValue = (value, seen = new WeakSet) => {
15676
- if (value === null || typeof value === "boolean" || typeof value === "number") {
15677
- return value;
15678
- }
15679
- if (typeof value === "string") {
15680
- return presignedUrlPattern.test(value) ? "[redacted]" : value;
15681
- }
15682
- if (typeof value === "bigint")
15683
- return value.toString();
15684
- if (value instanceof Date)
15685
- return value.toISOString();
15686
- if (typeof value !== "object" || value === null)
15687
- return String(value);
15688
- if (seen.has(value))
15689
- return "[circular]";
15690
- seen.add(value);
15691
- if (Array.isArray(value)) {
15692
- return value.map((item) => sanitizeValue(item, seen));
15693
- }
15694
- if (!isRecord(value))
15695
- return String(value);
15696
- return Object.fromEntries(Object.entries(value).map(([key, nestedValue]) => [
15697
- key,
15698
- sensitiveKeyPattern.test(key) ? "[redacted]" : sanitizeValue(nestedValue, seen)
15699
- ]));
15700
- };
15701
- var normalizeError = (error51) => {
15702
- if (error51 instanceof CliError) {
15703
- return {
15704
- code: error51.code,
15705
- message: error51.message,
15706
- ...error51.details ? { details: error51.details } : {}
15707
- };
15708
- }
15709
- if (isNetworkError(error51)) {
15710
- return {
15711
- code: "NETWORK",
15712
- message: error51 instanceof Error ? error51.message : "The GOSH API could not be reached."
15713
- };
15714
- }
15715
- if (isRecord(error51)) {
15716
- const data = isRecord(error51.data) ? error51.data : undefined;
15717
- const rawCode = typeof data?.code === "string" ? data.code : undefined;
15718
- const code = rawCode ? trpcCodeMap[rawCode] ?? "API" : "INTERNAL";
15719
- const message = typeof error51.message === "string" ? error51.message : "The GOSH API request failed.";
15720
- const details = isRecord(data?.zodError) && isJsonValue(data.zodError) ? { validation: data.zodError } : undefined;
15721
- return { code, message, ...details ? { details } : {} };
15722
- }
15723
- return {
15724
- code: "INTERNAL",
15725
- message: error51 instanceof Error ? error51.message : String(error51)
15726
- };
15727
- };
15728
- var serialize = (value) => `${JSON.stringify(value, null, 2)}
15729
- `;
15730
- var redactKnownSecrets = (value, _runtime) => {
15731
- return value.replace(/\bBearer\s+\S+/giu, "Bearer [redacted]");
15732
- };
15733
- var emitSuccess = (runtime2, invocation, data) => {
15734
- runtime2.stdout.write(serialize({
15735
- ok: true,
15736
- data: toJsonValue(data),
15737
- meta: {
15738
- apiBaseUrl: invocation.apiBaseUrl,
15739
- cliVersion: invocation.cliVersion,
15740
- command: invocation.command
15741
- }
15742
- }));
15743
- return 0;
15744
- };
15745
- var emitSubscriptionEvent = (runtime2, invocation, data) => {
15746
- runtime2.stdout.write(`${JSON.stringify({
15747
- ok: true,
15748
- data: toJsonValue(data),
15749
- meta: {
15750
- apiBaseUrl: invocation.apiBaseUrl,
15751
- cliVersion: invocation.cliVersion,
15752
- command: invocation.command,
15753
- stream: true
15754
- }
15755
- })}
15756
- `);
15757
- };
15758
- var emitError = (runtime2, command, error51) => {
15759
- const normalized = normalizeError(error51);
15760
- runtime2.stderr.write(redactKnownSecrets(serialize({ ok: false, error: normalized, meta: { command } }), runtime2));
15761
- return invocationCodes.has(normalized.code) ? 2 : 1;
15762
- };
15763
- var effectLabels = {
15764
- delete: "deletes or permanently revokes data",
15765
- email: "sends email",
15766
- "external-write": "writes to an external delivery surface",
15767
- "state-change": "changes GOSH state"
15768
- };
15769
- var permissionFlag = {
15770
- delete: "allow-delete",
15771
- email: "allow-email",
15772
- "external-write": "allow-external-write",
15773
- "state-change": "allow-state-change"
15774
- };
15775
- var getTargetCandidates = (input, targetKeys) => {
15776
- for (const key of targetKeys) {
15777
- if (key === "$self")
15778
- return new Set(["self"]);
15779
- if (!isRecord(input) || !(key in input))
15780
- continue;
15781
- const rawValue = input[key];
15782
- const values = Array.isArray(rawValue) ? rawValue : [rawValue];
15783
- const candidates = new Set(values.filter((value) => typeof value === "string" || typeof value === "number").map(String));
15784
- if (candidates.size > 0)
15785
- return candidates;
15786
- }
15787
- return new Set;
15788
- };
15789
- var confirmCommand = async ({
15790
- action,
15791
- effects,
15792
- flags,
15793
- input,
15794
- runtime: runtime2,
15795
- target,
15796
- targetKeys = []
15797
- }) => {
15798
- if (effects.length === 0)
15799
- return;
15800
- if (!target?.trim()) {
15801
- throw new CliError("CONFIRMATION_REQUIRED", "Sensitive commands require --target with the exact resource being changed.", { target: "required" });
15802
- }
15803
- if (!getTargetCandidates(input, targetKeys).has(target.trim())) {
15804
- throw new CliError("CONFIRMATION_REQUIRED", `--target must exactly match the command's primary resource (${targetKeys.map((key) => key === "$self" ? "self" : key).join(", ")}).`);
15805
- }
15806
- const uniqueEffects = [...new Set(effects)];
15807
- const missingFlags = uniqueEffects.map((effect) => permissionFlag[effect]).filter((flag) => flags[flag] !== true).map((flag) => `--${flag}`);
15808
- if (missingFlags.length === 0)
15809
- return;
15810
- if (!runtime2.isTTY) {
15811
- throw new CliError("CONFIRMATION_REQUIRED", "Non-interactive sensitive commands require every applicable allow flag.", { missingFlags });
15812
- }
15813
- runtime2.stderr.write(`${[
15814
- "GOSH workflow preview",
15815
- `Action: ${action}`,
15816
- `Target: ${target}`,
15817
- `Effects: ${uniqueEffects.map((effect) => effectLabels[effect]).join("; ")}`
15818
- ].join(`
15819
- `)}
15820
- `);
15821
- if (!runtime2.prompt) {
15822
- throw new CliError("CONFIRMATION_REQUIRED", "This command needs an interactive confirmation prompt.");
15823
- }
15824
- const answer = await runtime2.prompt("Type CONFIRM to continue: ");
15825
- if (answer !== "CONFIRM") {
15826
- throw new CliError("ABORTED", "Command aborted by user.");
15827
- }
15828
- };
15829
- var createProcessRuntime = () => ({
15830
- stdout: { write: (value) => process.stdout.write(value) },
15831
- stderr: { write: (value) => process.stderr.write(value) },
15832
- isTTY: Boolean(process.stdin.isTTY && process.stderr.isTTY),
15833
- env: process.env,
15834
- prompt: async (message) => {
15835
- const prompt = createInterface({
15836
- input: process.stdin,
15837
- output: process.stderr
15838
- });
15839
- try {
15840
- return await prompt.question(message);
15841
- } finally {
15842
- prompt.close();
15843
- }
15844
- }
15845
- });
15846
-
15847
- // src/api-client.ts
15848
- var DEFAULT_GOSH_API_BASE_URL = "https://app.gosh.sg";
15849
- var normalizeApiBaseUrl = (value) => {
15850
- const url2 = new URL(value);
15851
- const isLocalHttp = url2.protocol === "http:" && (url2.hostname === "localhost" || url2.hostname === "127.0.0.1");
15852
- if (url2.protocol !== "https:" && !isLocalHttp) {
15853
- throw new Error("GOSH API URL must use HTTPS, except for localhost development.");
15806
+ invoke: (client, input) => client.event.abortMissionMediaMultipartUpload.mutate(input)
15807
+ },
15808
+ "event.onPlayerEventChanged": {
15809
+ kind: "subscription",
15810
+ subscribe: (client, input, observer) => client.event.onPlayerEventChanged.subscribe(input, {
15811
+ onComplete: observer.complete,
15812
+ onData: observer.next,
15813
+ onError: observer.error
15814
+ })
15815
+ },
15816
+ "event.onSubmissionReviewQueueChanged": {
15817
+ kind: "subscription",
15818
+ subscribe: (client, input, observer) => client.event.onSubmissionReviewQueueChanged.subscribe(input, {
15819
+ onComplete: observer.complete,
15820
+ onData: observer.next,
15821
+ onError: observer.error
15822
+ })
15823
+ },
15824
+ "organization.create": {
15825
+ kind: "mutation",
15826
+ invoke: (client, input) => client.organization.create.mutate(input)
15827
+ },
15828
+ "organization.update": {
15829
+ kind: "mutation",
15830
+ invoke: (client, input) => client.organization.update.mutate(input)
15831
+ },
15832
+ "organization.checkSlug": {
15833
+ kind: "mutation",
15834
+ invoke: (client, input) => client.organization.checkSlug.mutate(input)
15835
+ },
15836
+ "organization.checkOrganizationAccess": {
15837
+ kind: "query",
15838
+ invoke: (client, input) => client.organization.checkOrganizationAccess.query(input)
15839
+ },
15840
+ "organization.getOnboardingState": {
15841
+ kind: "query",
15842
+ invoke: (client, input) => client.organization.getOnboardingState.query(input)
15843
+ },
15844
+ "organization.getInvitation": {
15845
+ kind: "query",
15846
+ invoke: (client, input) => client.organization.getInvitation.query(input)
15847
+ },
15848
+ "organization.acceptInvitation": {
15849
+ kind: "mutation",
15850
+ invoke: (client, input) => client.organization.acceptInvitation.mutate(input)
15851
+ },
15852
+ "organization.rejectInvitation": {
15853
+ kind: "mutation",
15854
+ invoke: (client, input) => client.organization.rejectInvitation.mutate(input)
15855
+ },
15856
+ "organization.cancelInvitation": {
15857
+ kind: "mutation",
15858
+ invoke: (client, input) => client.organization.cancelInvitation.mutate(input)
15859
+ },
15860
+ "organization.inviteMember": {
15861
+ kind: "mutation",
15862
+ invoke: (client, input) => client.organization.inviteMember.mutate(input)
15863
+ },
15864
+ "organization.removeMember": {
15865
+ kind: "mutation",
15866
+ invoke: (client, input) => client.organization.removeMember.mutate(input)
15867
+ },
15868
+ "organization.updateMemberRole": {
15869
+ kind: "mutation",
15870
+ invoke: (client, input) => client.organization.updateMemberRole.mutate(input)
15871
+ },
15872
+ "organization.listAllForAdmin": {
15873
+ kind: "query",
15874
+ invoke: (client, input) => client.organization.listAllForAdmin.query(input)
15875
+ },
15876
+ "template.createSystem": {
15877
+ kind: "mutation",
15878
+ invoke: (client, input) => client.template.createSystem.mutate(input)
15879
+ },
15880
+ "user.listAdmin": {
15881
+ kind: "query",
15882
+ invoke: (client, input) => client.user.listAdmin.query(input)
15883
+ },
15884
+ "user.updateGlobalRole": {
15885
+ kind: "mutation",
15886
+ invoke: (client, input) => client.user.updateGlobalRole.mutate(input)
15887
+ },
15888
+ "user.ban": {
15889
+ kind: "mutation",
15890
+ invoke: (client, input) => client.user.ban.mutate(input)
15891
+ },
15892
+ "user.unban": {
15893
+ kind: "mutation",
15894
+ invoke: (client, input) => client.user.unban.mutate(input)
15854
15895
  }
15855
- url2.pathname = url2.pathname.replace(/\/$/, "");
15856
- return url2.toString().replace(/\/$/, "");
15857
- };
15858
- var createGoshClient = ({
15859
- apiBaseUrl,
15860
- accessToken,
15861
- debug = false,
15862
- quiet = false
15863
- }) => {
15864
- const headers = () => ({
15865
- "x-trpc-source": "gosh-cli",
15866
- ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {}
15867
- });
15868
- const typedClient = createTRPCProxyClient({
15869
- links: [
15870
- loggerLink({
15871
- enabled: () => debug && !quiet,
15872
- colorMode: "ansi",
15873
- withContext: false,
15874
- console: {
15875
- log: (...args) => console.error(...args.map((argument) => sanitizeValue(argument))),
15876
- error: (...args) => console.error(...args.map((argument) => sanitizeValue(argument)))
15877
- }
15878
- }),
15879
- splitLink({
15880
- condition: (operation) => operation.type === "subscription",
15881
- true: httpSubscriptionLink({
15882
- EventSource: AuthenticatedEventSource,
15883
- eventSourceOptions: { headers: headers() },
15884
- transformer: SuperJSON,
15885
- url: `${apiBaseUrl}/api/trpc`
15886
- }),
15887
- false: httpBatchLink({
15888
- headers,
15889
- transformer: SuperJSON,
15890
- url: `${apiBaseUrl}/api/trpc`
15891
- })
15892
- })
15893
- ]
15894
- });
15895
- return Object.assign(typedClient, {
15896
- mutation: (path2, input) => {
15897
- const operation = typedOperations[path2];
15898
- if (operation.kind !== "mutation") {
15899
- throw new Error(`Expected mutation procedure, received ${path2}.`);
15900
- }
15901
- return operation.invoke(typedClient, input);
15902
- },
15903
- query: (path2, input) => {
15904
- const operation = typedOperations[path2];
15905
- if (operation.kind !== "query") {
15906
- throw new Error(`Expected query procedure, received ${path2}.`);
15907
- }
15908
- return operation.invoke(typedClient, input);
15909
- },
15910
- subscription: (path2, input, observer) => {
15911
- const operation = typedOperations[path2];
15912
- if (operation.kind !== "subscription") {
15913
- throw new Error(`Expected subscription procedure, received ${path2}.`);
15914
- }
15915
- return operation.subscribe(typedClient, input, observer);
15916
- }
15917
- });
15918
15896
  };
15919
15897
 
15920
- // src/parse-args.ts
15921
- var parseArgs = (argv) => {
15922
- const flags = {};
15923
- const positional = [];
15924
- for (let index = 0;index < argv.length; index += 1) {
15925
- const argument = argv[index];
15926
- if (!argument)
15927
- continue;
15928
- if (argument === "--") {
15929
- positional.push(...argv.slice(index + 1));
15930
- break;
15931
- }
15932
- if (argument === "-q") {
15933
- flags.quiet = true;
15934
- continue;
15935
- }
15936
- if (!argument.startsWith("--")) {
15937
- positional.push(argument);
15938
- continue;
15939
- }
15940
- const equalsIndex = argument.indexOf("=");
15941
- if (equalsIndex > 2) {
15942
- flags[argument.slice(2, equalsIndex)] = argument.slice(equalsIndex + 1);
15943
- continue;
15944
- }
15945
- const name = argument.slice(2);
15946
- const next = argv[index + 1];
15947
- if (next !== undefined && !next.startsWith("-")) {
15948
- flags[name] = next;
15949
- index += 1;
15950
- } else {
15951
- flags[name] = true;
15898
+ // src/command-client.ts
15899
+ var createGoshCommandClient = (client) => ({
15900
+ mutation: (path2, input) => {
15901
+ const operation = typedOperations[path2];
15902
+ if (operation.kind !== "mutation") {
15903
+ throw new Error(`Expected mutation procedure, received ${path2}.`);
15904
+ }
15905
+ return operation.invoke(client, input);
15906
+ },
15907
+ query: (path2, input) => {
15908
+ const operation = typedOperations[path2];
15909
+ if (operation.kind !== "query") {
15910
+ throw new Error(`Expected query procedure, received ${path2}.`);
15952
15911
  }
15953
- }
15954
- return { flags, positional };
15955
- };
15956
- var getStringFlag = (flags, name) => {
15957
- const value = flags[name];
15958
- return typeof value === "string" ? value : undefined;
15959
- };
15960
-
15961
- // src/parse-json.ts
15962
- var parseJsonInput = (value) => {
15963
- if (value === undefined) {
15964
- throw new CliError("USAGE", "This command requires --input with a JSON object.");
15965
- }
15966
- try {
15967
- const parsed = JSON.parse(value);
15968
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
15969
- throw new CliError("VALIDATION", "--input must be a JSON object.");
15912
+ return operation.invoke(client, input);
15913
+ },
15914
+ subscription: (path2, input, observer) => {
15915
+ const operation = typedOperations[path2];
15916
+ if (operation.kind !== "subscription") {
15917
+ throw new Error(`Expected subscription procedure, received ${path2}.`);
15970
15918
  }
15971
- return parsed;
15972
- } catch (error51) {
15973
- if (error51 instanceof CliError)
15974
- throw error51;
15975
- throw new CliError("VALIDATION", `--input is not valid JSON: ${error51 instanceof Error ? error51.message : String(error51)}`);
15919
+ return operation.subscribe(client, input, observer);
15976
15920
  }
15977
- };
15921
+ });
15978
15922
 
15979
15923
  // src/registry/index.ts
15980
15924
  var defaultMutationTargetKeys = [
@@ -16217,8 +16161,7 @@ var findCommand = (positional) => {
16217
16161
  }
16218
16162
  return;
16219
16163
  };
16220
-
16221
- // src/upload.ts
16164
+ // src/features/upload.ts
16222
16165
  import { open, readFile, stat } from "fs/promises";
16223
16166
  import { basename, extname } from "path";
16224
16167
  var contentTypes = {
@@ -16371,7 +16314,66 @@ var uploadFileForCommand = async ({
16371
16314
  };
16372
16315
  };
16373
16316
 
16374
- // src/index.ts
16317
+ // src/parse-args.ts
16318
+ var parseArgs = (argv) => {
16319
+ const flags = {};
16320
+ const positional = [];
16321
+ for (let index = 0;index < argv.length; index += 1) {
16322
+ const argument = argv[index];
16323
+ if (!argument)
16324
+ continue;
16325
+ if (argument === "--") {
16326
+ positional.push(...argv.slice(index + 1));
16327
+ break;
16328
+ }
16329
+ if (argument === "-q") {
16330
+ flags.quiet = true;
16331
+ continue;
16332
+ }
16333
+ if (!argument.startsWith("--")) {
16334
+ positional.push(argument);
16335
+ continue;
16336
+ }
16337
+ const equalsIndex = argument.indexOf("=");
16338
+ if (equalsIndex > 2) {
16339
+ flags[argument.slice(2, equalsIndex)] = argument.slice(equalsIndex + 1);
16340
+ continue;
16341
+ }
16342
+ const name = argument.slice(2);
16343
+ const next = argv[index + 1];
16344
+ if (next !== undefined && !next.startsWith("-")) {
16345
+ flags[name] = next;
16346
+ index += 1;
16347
+ } else {
16348
+ flags[name] = true;
16349
+ }
16350
+ }
16351
+ return { flags, positional };
16352
+ };
16353
+ var getStringFlag = (flags, name) => {
16354
+ const value = flags[name];
16355
+ return typeof value === "string" ? value : undefined;
16356
+ };
16357
+
16358
+ // src/parse-json.ts
16359
+ var parseJsonInput = (value) => {
16360
+ if (value === undefined) {
16361
+ throw new CliError("USAGE", "This command requires --input with a JSON object.");
16362
+ }
16363
+ try {
16364
+ const parsed = JSON.parse(value);
16365
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
16366
+ throw new CliError("VALIDATION", "--input must be a JSON object.");
16367
+ }
16368
+ return parsed;
16369
+ } catch (error51) {
16370
+ if (error51 instanceof CliError)
16371
+ throw error51;
16372
+ throw new CliError("VALIDATION", `--input is not valid JSON: ${error51 instanceof Error ? error51.message : String(error51)}`);
16373
+ }
16374
+ };
16375
+
16376
+ // src/cli.ts
16375
16377
  var packageManifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
16376
16378
  var GOSH_CLI_VERSION = typeof packageManifest.version === "string" ? packageManifest.version : "0.0.0";
16377
16379
  var allowedFlags = new Set([
@@ -16556,13 +16558,13 @@ Waiting for approval\u2026
16556
16558
  apiBaseUrl,
16557
16559
  store: credentialStore
16558
16560
  }) : undefined;
16559
- const clientFactory = dependencies.createClient ?? createGoshClient;
16560
- const client = clientFactory({
16561
+ const clientOptions = {
16561
16562
  accessToken,
16562
16563
  apiBaseUrl,
16563
16564
  debug: flags.debug === true,
16564
16565
  quiet: flags.quiet === true
16565
- });
16566
+ };
16567
+ const client = dependencies.createClient ? dependencies.createClient(clientOptions) : createGoshCommandClient(createGoshClient(clientOptions));
16566
16568
  if (command.operation === "subscription") {
16567
16569
  const invocation = {
16568
16570
  apiBaseUrl,
@@ -16623,27 +16625,21 @@ Waiting for approval\u2026
16623
16625
  return emitError(dependencies.runtime, requestedCommand, error51);
16624
16626
  }
16625
16627
  };
16626
- var isDirectExecution = () => {
16627
- const executable = process.argv[1];
16628
- if (!executable)
16629
- return false;
16630
- try {
16631
- return realpathSync(executable) === realpathSync(fileURLToPath(import.meta.url));
16632
- } catch {
16633
- return false;
16634
- }
16635
- };
16636
- if (isDirectExecution()) {
16628
+ var runGoshCliFromProcess = async () => {
16637
16629
  const runtime2 = createProcessRuntime();
16638
16630
  try {
16639
16631
  assertBunRuntime();
16640
- process.exitCode = await runGoshCli(process.argv.slice(2), { runtime: runtime2 });
16632
+ return await runGoshCli(process.argv.slice(2), { runtime: runtime2 });
16641
16633
  } catch (error51) {
16642
- process.exitCode = emitError(runtime2, "runtime", error51);
16634
+ return emitError(runtime2, "runtime", error51);
16643
16635
  }
16636
+ };
16637
+
16638
+ // src/index.ts
16639
+ if (import.meta.main) {
16640
+ process.exitCode = await runGoshCliFromProcess();
16644
16641
  }
16645
16642
  export {
16646
- GOSH_CLI_VERSION,
16647
16643
  commands,
16648
16644
  runGoshCli
16649
16645
  };