farseer-cli 1.0.5 → 1.0.8

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 (92) hide show
  1. package/docs/api-reference.md +372 -0
  2. package/docs/arquero-patterns.md +158 -0
  3. package/docs/cli-guide.md +160 -0
  4. package/docs/how-farseer-works.md +113 -0
  5. package/docs/import-workflows.md +306 -0
  6. package/docs/model-export.md +95 -0
  7. package/docs/new-app-template.md +240 -0
  8. package/docs/query-formulas.md +97 -0
  9. package/docs/troubleshooting.md +140 -0
  10. package/package.json +3 -3
  11. package/dist/commands/app.js +0 -349
  12. package/dist/commands/app.js.map +0 -7
  13. package/dist/commands/apps.js +0 -111
  14. package/dist/commands/apps.js.map +0 -7
  15. package/dist/commands/checkout.js +0 -166
  16. package/dist/commands/checkout.js.map +0 -7
  17. package/dist/commands/config.js +0 -139
  18. package/dist/commands/config.js.map +0 -7
  19. package/dist/commands/diff.js +0 -183
  20. package/dist/commands/diff.js.map +0 -7
  21. package/dist/commands/dimensions.js +0 -145
  22. package/dist/commands/dimensions.js.map +0 -7
  23. package/dist/commands/files.js +0 -99
  24. package/dist/commands/files.js.map +0 -7
  25. package/dist/commands/install.js +0 -79
  26. package/dist/commands/install.js.map +0 -7
  27. package/dist/commands/list.js +0 -92
  28. package/dist/commands/list.js.map +0 -7
  29. package/dist/commands/login.js +0 -134
  30. package/dist/commands/login.js.map +0 -7
  31. package/dist/commands/logout.js +0 -59
  32. package/dist/commands/logout.js.map +0 -7
  33. package/dist/commands/mcp-server.js +0 -41
  34. package/dist/commands/mcp-server.js.map +0 -7
  35. package/dist/commands/model.js +0 -189
  36. package/dist/commands/model.js.map +0 -7
  37. package/dist/commands/pull.js +0 -287
  38. package/dist/commands/pull.js.map +0 -7
  39. package/dist/commands/push.js +0 -251
  40. package/dist/commands/push.js.map +0 -7
  41. package/dist/commands/run.js +0 -288
  42. package/dist/commands/run.js.map +0 -7
  43. package/dist/commands/status.js +0 -145
  44. package/dist/commands/status.js.map +0 -7
  45. package/dist/commands/variables.js +0 -176
  46. package/dist/commands/variables.js.map +0 -7
  47. package/dist/commands/whoami.js +0 -63
  48. package/dist/commands/whoami.js.map +0 -7
  49. package/dist/index.js +0 -153
  50. package/dist/index.js.map +0 -7
  51. package/dist/mcp/index.js +0 -35
  52. package/dist/mcp/index.js.map +0 -7
  53. package/dist/mcp/prompts/workflows.js +0 -437
  54. package/dist/mcp/prompts/workflows.js.map +0 -7
  55. package/dist/mcp/resources/documentation.js +0 -167
  56. package/dist/mcp/resources/documentation.js.map +0 -7
  57. package/dist/mcp/server.js +0 -52
  58. package/dist/mcp/server.js.map +0 -7
  59. package/dist/mcp/tools/appTools.js +0 -377
  60. package/dist/mcp/tools/appTools.js.map +0 -7
  61. package/dist/mcp/tools/authTools.js +0 -158
  62. package/dist/mcp/tools/authTools.js.map +0 -7
  63. package/dist/mcp/tools/dataTools.js +0 -366
  64. package/dist/mcp/tools/dataTools.js.map +0 -7
  65. package/dist/mcp/tools/modelTools.js +0 -331
  66. package/dist/mcp/tools/modelTools.js.map +0 -7
  67. package/dist/mcp/tools/runTools.js +0 -231
  68. package/dist/mcp/tools/runTools.js.map +0 -7
  69. package/dist/mcp/tools/syncTools.js +0 -382
  70. package/dist/mcp/tools/syncTools.js.map +0 -7
  71. package/dist/mcp/utils/helpers.js +0 -113
  72. package/dist/mcp/utils/helpers.js.map +0 -7
  73. package/dist/services/appSyncService.js +0 -399
  74. package/dist/services/appSyncService.js.map +0 -7
  75. package/dist/services/configService.js +0 -196
  76. package/dist/services/configService.js.map +0 -7
  77. package/dist/services/farseerApi.js +0 -426
  78. package/dist/services/farseerApi.js.map +0 -7
  79. package/dist/services/farseerFactory.js +0 -231
  80. package/dist/services/farseerFactory.js.map +0 -7
  81. package/dist/services/farseerService.js +0 -614
  82. package/dist/services/farseerService.js.map +0 -7
  83. package/dist/services/gitService.js +0 -134
  84. package/dist/services/gitService.js.map +0 -7
  85. package/dist/services/syncService.js +0 -415
  86. package/dist/services/syncService.js.map +0 -7
  87. package/dist/utils/constants.js +0 -49
  88. package/dist/utils/constants.js.map +0 -7
  89. package/dist/utils/helpers.js +0 -433
  90. package/dist/utils/helpers.js.map +0 -7
  91. package/dist/utils/logger.js +0 -76
  92. package/dist/utils/logger.js.map +0 -7
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/commands/pull.ts"],
4
- "sourcesContent": ["import { Command } from 'commander';\nimport chalk from 'chalk';\nimport { logger } from '../utils/logger';\nimport { getFarseerClientWithFallback, showLoginPrompt } from '../services/farseerFactory';\nimport { SyncService } from '../services/syncService';\nimport { AppSyncService } from '../services/appSyncService';\nimport { GitService } from '../services/gitService';\nimport { getTenantDir, ensureDirectoryExists, resolveTenantWithOrgMapping, isInRemotejobsRepo, appendToAuditLog, AuditLogEntry } from '../utils/helpers';\nimport { CLI_GIT_AUTHOR } from '../utils/constants';\n\nexport function registerPullCommand(program: Command): void {\n program\n .command('pull [arg1] [arg2]')\n .description('Pull files from Farseer instance to local\\n\\nUsage: pull <org> <tenant> OR pull <tenant> (if org is known)')\n .option('--git', 'Enable git operations (commit & push) - internal use only')\n .option('--all', 'Pull all files (default: only scripts .ts, .js)')\n .action(async (arg1, arg2, options) => {\n const { organisation, tenant } = resolveTenantWithOrgMapping(arg1, arg2);\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n\n if (!clientResult) {\n showLoginPrompt(tenant);\n process.exit(1);\n }\n\n const gitService = new GitService();\n const syncService = new SyncService(tenant, clientResult.client);\n\n // Git operations are opt-in with --git flag (internal developer feature)\n const inRemotejobsRepo = isInRemotejobsRepo();\n\n // Git enabled ONLY if:\n // 1. User explicitly requested it (--git flag)\n // 2. We're in remotejobs repo (safety check)\n // 3. FARSEER_NO_GIT env var is not set\n const gitEnabled = options.git === true && inRemotejobsRepo && !process.env.FARSEER_NO_GIT;\n\n // Show error if --git requested but not in remotejobs repo\n if (options.git === true && !inRemotejobsRepo) {\n logger.error('Git operations are only available in remotejobs repository.');\n process.exit(1);\n }\n\n // Step 1: Git pull\n if (gitEnabled) {\n logger.info('Pulling latest changes from git...');\n const gitPullResult = await gitService.pull();\n\n if (!gitPullResult.success) {\n logger.error('Git pull failed.');\n logger.dim(gitPullResult.message);\n process.exit(1);\n }\n\n logger.dim(gitPullResult.message);\n }\n\n // Step 2: Ensure tenant folder exists\n const tenantDir = getTenantDir(tenant);\n ensureDirectoryExists(tenantDir);\n\n // Create default package.json if it doesn't exist\n await createDefaultPackageJson(tenantDir, tenant);\n\n // Step 3: Pull files from Farseer\n console.log();\n console.log(chalk.bold('\u2550\u2550\u2550 Files \u2550\u2550\u2550'));\n logger.info(`Pulling files from ${tenant}...`);\n\n try {\n const result = await syncService.pull({ all: options.all });\n\n if (result.downloaded.length > 0) {\n console.log(chalk.green('Downloaded:'));\n for (const file of result.downloaded) {\n console.log(chalk.green(` + ${file}`));\n }\n }\n\n if (result.deleted.length > 0) {\n console.log(chalk.red('Deleted (removed from remote):'));\n for (const file of result.deleted) {\n console.log(chalk.red(` - ${file}`));\n }\n }\n\n logger.dim(`Files: +${result.downloaded.length} -${result.deleted.length} (${result.unchanged.length} unchanged)`);\n\n // Create audit log entries for downloaded files\n if (result.downloaded.length > 0) {\n const syncState = syncService.loadSyncState();\n const auditEntries: AuditLogEntry[] = result.downloaded.map(filePath => ({\n operation: 'pulled' as const,\n filePath,\n uploadTime: syncState.files[filePath]?.metadata?.uploadTime,\n uploaderEmail: syncState.files[filePath]?.metadata?.uploaderEmail,\n uploaderName: syncState.files[filePath]?.metadata?.uploaderName,\n }));\n\n appendToAuditLog(tenant, auditEntries);\n }\n\n let hasChanges = result.downloaded.length > 0 || result.deleted.length > 0;\n\n // Step 4: Pull apps (works with both JWT and API key)\n let appResult = { created: [] as string[], updated: [] as string[], deleted: [] as string[], unchanged: [] as string[] };\n\n console.log();\n console.log(chalk.bold('\u2550\u2550\u2550 Apps \u2550\u2550\u2550'));\n logger.info(`Pulling apps from ${tenant}...`);\n\n const appSyncService = new AppSyncService(tenant, clientResult.client);\n appResult = await appSyncService.pull();\n\n if (appResult.created.length > 0) {\n console.log(chalk.green('New apps:'));\n for (const app of appResult.created) {\n console.log(chalk.green(` + ${app}`));\n }\n }\n\n if (appResult.updated.length > 0) {\n console.log(chalk.yellow('Updated apps:'));\n for (const app of appResult.updated) {\n console.log(chalk.yellow(` ~ ${app}`));\n }\n }\n\n if (appResult.deleted.length > 0) {\n console.log(chalk.red('Deleted apps (removed from remote):'));\n for (const app of appResult.deleted) {\n console.log(chalk.red(` - ${app}`));\n }\n }\n\n logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length} (${appResult.unchanged.length} unchanged)`);\n\n hasChanges = hasChanges || appResult.created.length > 0 || appResult.updated.length > 0 || appResult.deleted.length > 0;\n\n // Step 5: Git commit & push\n if (gitEnabled) {\n const appsPath = `apps/${tenant}`;\n\n // Check for any uncommitted changes (including from previous pulls without --git)\n const gitStatus = await gitService.status();\n const hasUncommittedChanges =\n gitStatus.modified.some(f => f.startsWith(appsPath)) ||\n gitStatus.added.some(f => f.startsWith(appsPath)) ||\n gitStatus.deleted.some(f => f.startsWith(appsPath)) ||\n gitStatus.untracked.some(f => f.startsWith(appsPath));\n\n if (hasChanges || hasUncommittedChanges) {\n logger.info('Committing changes to git...');\n\n await gitService.add([appsPath]);\n\n // Build detailed commit message with metadata\n const syncState = syncService.loadSyncState();\n let commitMessage = `Sync with remote ${tenant}\\n\\n`;\n\n if (result.downloaded.length > 0) {\n commitMessage += 'Modified files:\\n';\n for (const file of result.downloaded) {\n const metadata = syncState.files[file]?.metadata;\n const author = metadata?.uploaderName || metadata?.uploaderEmail || 'Unknown';\n commitMessage += `- ${file} (${author})\\n`;\n }\n }\n\n if (result.deleted.length > 0) {\n commitMessage += '\\nDeleted files:\\n';\n result.deleted.forEach(f => commitMessage += `- ${f}\\n`);\n }\n\n if (appResult.created.length > 0 || appResult.updated.length > 0) {\n commitMessage += '\\nModified apps:\\n';\n appResult.created.forEach(a => commitMessage += `- ${a} (new)\\n`);\n appResult.updated.forEach(a => commitMessage += `- ${a} (updated)\\n`);\n }\n\n if (appResult.deleted.length > 0) {\n commitMessage += '\\nDeleted apps:\\n';\n appResult.deleted.forEach(a => commitMessage += `- ${a}\\n`);\n }\n\n const commitResult = await gitService.commit(commitMessage, CLI_GIT_AUTHOR);\n\n if (commitResult.success) {\n logger.dim(`Committed: ${commitResult.commitHash}`);\n\n logger.info('Pushing to remote...');\n const pushResult = await gitService.push();\n\n if (pushResult.success) {\n logger.dim(pushResult.message);\n } else {\n logger.warning('Failed to push to remote.');\n logger.dim(pushResult.message);\n logger.dim('You may need to push manually.');\n }\n } else {\n logger.warning('Nothing to commit.');\n }\n } else {\n logger.success('Already up to date (no changes to commit).');\n return;\n }\n } else if (!hasChanges) {\n logger.success('Already up to date.');\n return;\n }\n\n console.log();\n console.log(chalk.bold('\u2550\u2550\u2550 Summary \u2550\u2550\u2550'));\n logger.success('Pull complete!');\n logger.dim(`Files: +${result.downloaded.length} -${result.deleted.length} (${result.unchanged.length} unchanged)`);\n logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length} (${appResult.unchanged.length} unchanged)`);\n } catch (error) {\n logger.error('Pull failed.');\n if (error instanceof Error) {\n logger.dim(error.message);\n }\n process.exit(1);\n }\n });\n}\n\nasync function createDefaultPackageJson(tenantDir: string, tenant: string): Promise<void> {\n const fs = await import('fs');\n const path = await import('path');\n\n const packageJsonPath = path.join(tenantDir, 'package.json');\n\n if (fs.existsSync(packageJsonPath)) {\n return;\n }\n\n const packageJson = {\n name: `farseer-scripts-${tenant}`,\n version: '1.0.0',\n description: `Farseer App scripts for ${tenant}`,\n main: 'src/index.ts',\n scripts: {},\n keywords: ['farseer', 'scripts', tenant],\n author: 'Farseer',\n license: 'ISC',\n dependencies: {\n '@google-cloud/bigquery': '^7.9.0',\n '@google-cloud/storage': '^7.12.1',\n '@googleapis/sheets': '^5.0.5',\n '@sendgrid/mail': '^7.7.0',\n '@types/node-forge': '^1.3.11',\n '@xmldom/xmldom': '^0.9.8',\n 'arquero': '^5.4.1',\n 'axios': '^1.10.0',\n 'axios-retry': '^3.9.1',\n 'basic-ftp': '^5.0.5',\n 'client-oauth2': '^4.3.3',\n 'csv-parser': '^3.0.0',\n 'dotenv': '^16.4.5',\n 'draft-js': '^0.11.7',\n 'exceljs': '^4.4.0',\n 'farseer-client': 'https://storage.googleapis.com/farseer-remote-jobs-results/farseer-client/release-1.4.5.tar',\n 'farseer-client-axios': 'https://storage.googleapis.com/farseer-remote-jobs-results/farseer-client-axios/6898c0cb-5dca-4b2f-b325-119efc7f099e/v1.0.1.tar',\n 'fast-xml-parser': '^4.5.0',\n 'form-data': '^4.0.0',\n 'googleapis': '^144.0.0',\n 'heapdump': '^0.3.15',\n 'image-size': '^1.1.1',\n 'jszip': '^3.10.1',\n 'lossless-json': '^4.0.1',\n 'mssql': '^10.0.4',\n 'node-fetch': '^2.7.0',\n 'node-forge': '^1.3.1',\n 'node-sp-auth': '^3.0.8',\n 'numeral': '^2.0.6',\n 'oracledb': '^6.6.0',\n 'papaparse': '^5.5.1',\n 'pdfkit': '^0.14.0',\n 'pdfmake': '^0.2.20',\n 'soap': '^1.1.11',\n 'ssh2-sftp-client': '^11.0.0',\n 'strong-soap': '^4.1.13',\n 'ts-node': '^10.9.2',\n 'typescript': '^5.5.4',\n 'undici': '^6.19.8',\n 'uuid': '^11.1.0',\n 'winston': '^3.17.0',\n 'xlsx': 'https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz',\n 'xml-crypto': '^6.1.2',\n },\n devDependencies: {\n '@types/draft-js': '^0.11.18',\n '@types/heapdump': '^0.3.4',\n '@types/mssql': '^9.1.5',\n '@types/node': '^18.19.50',\n '@types/node-fetch': '^2.6.11',\n '@types/numeral': '^2.0.5',\n '@types/oracledb': '^6.5.3',\n '@types/papaparse': '^5.3.15',\n '@types/pdfmake': '^0.2.11',\n '@types/soap': '^0.18.0',\n '@types/ssh2-sftp-client': '^9.0.4',\n '@types/tough-cookie': '^4.0.5',\n '@types/uuid': '^10.0.0',\n '@types/xmldom': '^0.1.34',\n 'ts-node': '^10.9.2',\n 'typescript': '^5.5.4',\n },\n };\n\n fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');\n logger.dim(`Created package.json for ${tenant}`);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,oBAAuB;AACvB,4BAA8D;AAC9D,yBAA4B;AAC5B,4BAA+B;AAC/B,wBAA2B;AAC3B,qBAAsI;AACtI,uBAA+B;AAExB,SAAS,oBAAoB,SAAwB;AACxD,UACK,QAAQ,oBAAoB,EAC5B,YAAY,4GAA4G,EACxH,OAAO,SAAS,2DAA2D,EAC3E,OAAO,SAAS,iDAAiD,EACjE,OAAO,OAAO,MAAM,MAAM,YAAY;AACnC,UAAM,EAAE,cAAc,OAAO,QAAI,4CAA4B,MAAM,IAAI;AACvE,UAAM,eAAe,UAAM,oDAA6B,cAAc,MAAM;AAE5E,QAAI,CAAC,cAAc;AACf,iDAAgB,MAAM;AACtB,cAAQ,KAAK,CAAC;AAAA,IAClB;AAEA,UAAM,aAAa,IAAI,6BAAW;AAClC,UAAM,cAAc,IAAI,+BAAY,QAAQ,aAAa,MAAM;AAG/D,UAAM,uBAAmB,mCAAmB;AAM5C,UAAM,aAAa,QAAQ,QAAQ,QAAQ,oBAAoB,CAAC,QAAQ,IAAI;AAG5E,QAAI,QAAQ,QAAQ,QAAQ,CAAC,kBAAkB;AAC3C,2BAAO,MAAM,6DAA6D;AAC1E,cAAQ,KAAK,CAAC;AAAA,IAClB;AAGA,QAAI,YAAY;AACZ,2BAAO,KAAK,oCAAoC;AAChD,YAAM,gBAAgB,MAAM,WAAW,KAAK;AAE5C,UAAI,CAAC,cAAc,SAAS;AACxB,6BAA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kBAAkB;AAAA,MAClB,mBAAmB;AAAA,MACnB,oBAAoB;AAAA,MACpB,kBAAkB;AAAA,MAClB,eAAe;AAAA,MACf,2BAA2B;AAAA,MAC3B,uBAAuB;AAAA,MACvB,eAAe;AAAA,MACf,iBAAiB;AAAA,MACjB,WAAW;AAAA,MACX,cAAc;AAAA,IAClB;AAAA,EACJ;AAEA,KAAG,cAAc,iBAAiB,KAAK,UAAU,aAAa,MAAM,CAAC,GAAG,OAAO;AAC/E,uBAAO,IAAI,4BAA4B,MAAM,EAAE;AACnD;",
6
- "names": ["chalk"]
7
- }
@@ -1,251 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var push_exports = {};
29
- __export(push_exports, {
30
- registerPushCommand: () => registerPushCommand
31
- });
32
- module.exports = __toCommonJS(push_exports);
33
- var import_chalk = __toESM(require("chalk"));
34
- var import_inquirer = __toESM(require("inquirer"));
35
- var import_logger = require("../utils/logger");
36
- var import_farseerFactory = require("../services/farseerFactory");
37
- var import_syncService = require("../services/syncService");
38
- var import_appSyncService = require("../services/appSyncService");
39
- var import_gitService = require("../services/gitService");
40
- var import_helpers = require("../utils/helpers");
41
- var import_constants = require("../utils/constants");
42
- var fs = __toESM(require("fs"));
43
- function registerPushCommand(program) {
44
- program.command("push [arg1] [arg2]").description("Push local files to Farseer instance\n\nUsage: push <org> <tenant> OR push <tenant> (if org is known)").option("--git", "Enable git operations (commit & push) - internal use only").option("-m, --message <message>", "Commit message (required when using --git)").option("--force", "Force push even if remote has changes").action(async (arg1, arg2, options) => {
45
- const { organisation, tenant } = (0, import_helpers.resolveTenantWithOrgMapping)(arg1, arg2);
46
- const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
47
- if (!clientResult) {
48
- (0, import_farseerFactory.showLoginPrompt)(tenant);
49
- process.exit(1);
50
- }
51
- const filesDir = (0, import_helpers.getTenantFilesDir)(tenant);
52
- if (!fs.existsSync(filesDir)) {
53
- import_logger.logger.error(`Local folder not found: apps/${tenant}/files/`);
54
- import_logger.logger.dim('Run "farseer pull <tenant>" first to initialize the folder.');
55
- process.exit(1);
56
- }
57
- const inRemotejobsRepo = (0, import_helpers.isInRemotejobsRepo)();
58
- const gitDisabledByEnv = !!process.env.FARSEER_NO_GIT;
59
- const gitEnabled = options.git === true && inRemotejobsRepo && !gitDisabledByEnv;
60
- if (options.git === true && !inRemotejobsRepo) {
61
- import_logger.logger.error("Git operations are only available in remotejobs repository.");
62
- process.exit(1);
63
- }
64
- if (gitEnabled && !options.message) {
65
- import_logger.logger.error("Commit message is required when using git.");
66
- import_logger.logger.dim('Use: farseer push <tenant> --git -m "Your message"');
67
- process.exit(1);
68
- }
69
- const gitService = new import_gitService.GitService();
70
- const syncService = new import_syncService.SyncService(tenant, clientResult.client);
71
- if (gitEnabled) {
72
- import_logger.logger.info("Pulling latest changes from git...");
73
- const gitPullResult = await gitService.pull();
74
- if (!gitPullResult.success) {
75
- import_logger.logger.error("Git pull failed.");
76
- import_logger.logger.dim(gitPullResult.message);
77
- process.exit(1);
78
- }
79
- import_logger.logger.dim(gitPullResult.message);
80
- }
81
- if (!options.force) {
82
- import_logger.logger.info("Checking for remote changes...");
83
- const hasRemoteChanges = await syncService.checkRemoteChanges();
84
- if (hasRemoteChanges) {
85
- import_logger.logger.error("Remote has changes that are not synced locally.");
86
- import_logger.logger.dim(`Run 'farseer pull ${tenant}' first, then try pushing again.`);
87
- import_logger.logger.dim("Or use --force to push anyway (will overwrite remote changes).");
88
- process.exit(1);
89
- }
90
- import_logger.logger.dim("Remote is in sync.");
91
- }
92
- const status = await syncService.getStatusFast();
93
- const filesToPush = [
94
- ...status.modifiedLocally,
95
- ...status.onlyLocal
96
- ];
97
- const filesToDelete = status.modifiedRemotely.filter(
98
- (f) => !fs.existsSync(`${filesDir}/${f}`)
99
- );
100
- let appStatus = { newLocal: [], modified: [], newRemote: [], synced: [] };
101
- const appSyncService = new import_appSyncService.AppSyncService(tenant, clientResult.client);
102
- appStatus = await appSyncService.getStatus();
103
- const hasFileChanges = filesToPush.length > 0 || filesToDelete.length > 0;
104
- const hasAppChanges = appStatus.newLocal.length > 0 || appStatus.modified.length > 0;
105
- if (!hasFileChanges && !hasAppChanges) {
106
- import_logger.logger.success("Nothing to push. Everything is in sync.");
107
- return;
108
- }
109
- console.log();
110
- import_logger.logger.header("Changes to push:");
111
- if (filesToPush.length > 0) {
112
- for (const file of filesToPush) {
113
- const isNew = status.onlyLocal.includes(file);
114
- if (isNew) {
115
- console.log(import_chalk.default.green(` + ${file}`));
116
- } else {
117
- console.log(import_chalk.default.yellow(` M ${file}`));
118
- }
119
- }
120
- }
121
- if (filesToDelete.length > 0) {
122
- for (const file of filesToDelete) {
123
- console.log(import_chalk.default.red(` - ${file}`));
124
- }
125
- }
126
- if (appStatus.newLocal.length > 0) {
127
- console.log(import_chalk.default.green("New apps:"));
128
- for (const app of appStatus.newLocal) {
129
- console.log(import_chalk.default.green(` + ${app}`));
130
- }
131
- }
132
- if (appStatus.modified.length > 0) {
133
- console.log(import_chalk.default.yellow("Modified apps:"));
134
- for (const app of appStatus.modified) {
135
- console.log(import_chalk.default.yellow(` ~ ${app}`));
136
- }
137
- }
138
- console.log();
139
- const totalChanges = filesToPush.length + filesToDelete.length + appStatus.newLocal.length + appStatus.modified.length;
140
- const confirm = await import_inquirer.default.prompt([
141
- {
142
- type: "confirm",
143
- name: "proceed",
144
- message: `Push ${totalChanges} change(s) to ${tenant}?`,
145
- default: true
146
- }
147
- ]);
148
- if (!confirm.proceed) {
149
- import_logger.logger.info("Push cancelled.");
150
- return;
151
- }
152
- await (0, import_farseerFactory.ensureFreshToken)(clientResult.client);
153
- try {
154
- let result = { uploaded: [], updated: [], deleted: [], unchanged: [] };
155
- if (hasFileChanges) {
156
- import_logger.logger.info(`Pushing files to ${tenant}...`);
157
- result = await syncService.push();
158
- console.log();
159
- if (result.uploaded.length > 0) {
160
- console.log(import_chalk.default.green("Uploaded files (new):"));
161
- for (const file of result.uploaded) {
162
- console.log(import_chalk.default.green(` + ${file}`));
163
- }
164
- console.log();
165
- }
166
- if (result.updated.length > 0) {
167
- console.log(import_chalk.default.yellow("Updated files:"));
168
- for (const file of result.updated) {
169
- console.log(import_chalk.default.yellow(` M ${file}`));
170
- }
171
- console.log();
172
- }
173
- if (result.deleted.length > 0) {
174
- console.log(import_chalk.default.red("Deleted files:"));
175
- for (const file of result.deleted) {
176
- console.log(import_chalk.default.red(` - ${file}`));
177
- }
178
- console.log();
179
- }
180
- }
181
- let appResult = { created: [], updated: [], deleted: [], unchanged: [] };
182
- if (hasAppChanges) {
183
- import_logger.logger.info(`Pushing apps to ${tenant}...`);
184
- appResult = await appSyncService.push();
185
- if (appResult.created.length > 0) {
186
- console.log(import_chalk.default.green("Created apps:"));
187
- for (const app of appResult.created) {
188
- console.log(import_chalk.default.green(` + ${app}`));
189
- }
190
- console.log();
191
- }
192
- if (appResult.updated.length > 0) {
193
- console.log(import_chalk.default.yellow("Updated apps:"));
194
- for (const app of appResult.updated) {
195
- console.log(import_chalk.default.yellow(` ~ ${app}`));
196
- }
197
- console.log();
198
- }
199
- if (appResult.deleted.length > 0) {
200
- console.log(import_chalk.default.red("Deleted apps:"));
201
- for (const app of appResult.deleted) {
202
- console.log(import_chalk.default.red(` - ${app}`));
203
- }
204
- console.log();
205
- }
206
- }
207
- if (gitEnabled) {
208
- import_logger.logger.info("Committing changes to git...");
209
- const appsPath = `apps/${tenant}`;
210
- await gitService.add([appsPath]);
211
- const commitMessage = `[${tenant}] ${options.message}
212
-
213
- Files: +${result.uploaded.length} ~${result.updated.length} -${result.deleted.length}
214
- Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length}
215
-
216
- \u{1F916} Generated with Farseer CLI`;
217
- const commitResult = await gitService.commit(commitMessage, import_constants.CLI_GIT_AUTHOR);
218
- if (commitResult.success) {
219
- import_logger.logger.dim(`Committed: ${commitResult.commitHash}`);
220
- import_logger.logger.info("Pushing to git remote...");
221
- const pushResult = await gitService.push();
222
- if (pushResult.success) {
223
- import_logger.logger.dim(pushResult.message);
224
- } else {
225
- import_logger.logger.warning("Failed to push to git remote.");
226
- import_logger.logger.dim(pushResult.message);
227
- import_logger.logger.dim("You may need to push manually.");
228
- }
229
- } else {
230
- import_logger.logger.warning("Failed to commit changes.");
231
- import_logger.logger.dim(commitResult.message);
232
- }
233
- }
234
- console.log();
235
- import_logger.logger.success("Push complete!");
236
- import_logger.logger.dim(`Files: +${result.uploaded.length} ~${result.updated.length} -${result.deleted.length}`);
237
- import_logger.logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length}`);
238
- } catch (error) {
239
- import_logger.logger.error("Push failed.");
240
- if (error instanceof Error) {
241
- import_logger.logger.dim(error.message);
242
- }
243
- process.exit(1);
244
- }
245
- });
246
- }
247
- // Annotate the CommonJS export names for ESM import in node:
248
- 0 && (module.exports = {
249
- registerPushCommand
250
- });
251
- //# sourceMappingURL=push.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/commands/push.ts"],
4
- "sourcesContent": ["import { Command } from 'commander';\nimport chalk from 'chalk';\nimport inquirer from 'inquirer';\nimport { logger } from '../utils/logger';\nimport { getFarseerClientWithFallback, showLoginPrompt, ensureFreshToken } from '../services/farseerFactory';\nimport { SyncService } from '../services/syncService';\nimport { AppSyncService } from '../services/appSyncService';\nimport { GitService } from '../services/gitService';\nimport { getTenantFilesDir, resolveTenantWithOrgMapping, isInRemotejobsRepo } from '../utils/helpers';\nimport { CLI_GIT_AUTHOR } from '../utils/constants';\nimport * as fs from 'fs';\n\nexport function registerPushCommand(program: Command): void {\n program\n .command('push [arg1] [arg2]')\n .description('Push local files to Farseer instance\\n\\nUsage: push <org> <tenant> OR push <tenant> (if org is known)')\n .option('--git', 'Enable git operations (commit & push) - internal use only')\n .option('-m, --message <message>', 'Commit message (required when using --git)')\n .option('--force', 'Force push even if remote has changes')\n .action(async (arg1, arg2, options) => {\n const { organisation, tenant } = resolveTenantWithOrgMapping(arg1, arg2);\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n\n if (!clientResult) {\n showLoginPrompt(tenant);\n process.exit(1);\n }\n\n const filesDir = getTenantFilesDir(tenant);\n\n if (!fs.existsSync(filesDir)) {\n logger.error(`Local folder not found: apps/${tenant}/files/`);\n logger.dim('Run \"farseer pull <tenant>\" first to initialize the folder.');\n process.exit(1);\n }\n\n // Git operations are opt-in with --git flag (internal developer feature)\n const inRemotejobsRepo = isInRemotejobsRepo();\n const gitDisabledByEnv = !!process.env.FARSEER_NO_GIT;\n\n // Git enabled ONLY if:\n // 1. User explicitly requested it (--git flag)\n // 2. We're in remotejobs repo (safety check)\n // 3. FARSEER_NO_GIT env var is not set\n const gitEnabled = options.git === true && inRemotejobsRepo && !gitDisabledByEnv;\n\n // Show error if --git requested but not in remotejobs repo\n if (options.git === true && !inRemotejobsRepo) {\n logger.error('Git operations are only available in remotejobs repository.');\n process.exit(1);\n }\n\n // Validate message is provided when using git\n if (gitEnabled && !options.message) {\n logger.error('Commit message is required when using git.');\n logger.dim('Use: farseer push <tenant> --git -m \"Your message\"');\n process.exit(1);\n }\n\n const gitService = new GitService();\n const syncService = new SyncService(tenant, clientResult.client);\n\n // Step 1: Git pull to ensure we're up to date\n if (gitEnabled) {\n logger.info('Pulling latest changes from git...');\n const gitPullResult = await gitService.pull();\n\n if (!gitPullResult.success) {\n logger.error('Git pull failed.');\n logger.dim(gitPullResult.message);\n process.exit(1);\n }\n\n logger.dim(gitPullResult.message);\n }\n\n // Step 2: Check if remote has unpulled changes\n if (!options.force) {\n logger.info('Checking for remote changes...');\n\n const hasRemoteChanges = await syncService.checkRemoteChanges();\n\n if (hasRemoteChanges) {\n logger.error('Remote has changes that are not synced locally.');\n logger.dim(`Run 'farseer pull ${tenant}' first, then try pushing again.`);\n logger.dim('Or use --force to push anyway (will overwrite remote changes).');\n process.exit(1);\n }\n\n logger.dim('Remote is in sync.');\n }\n\n // Step 3: Show what will be pushed (using fast status check that doesn't download remote content)\n const status = await syncService.getStatusFast();\n\n const filesToPush = [\n ...status.modifiedLocally,\n ...status.onlyLocal,\n ];\n\n const filesToDelete = status.modifiedRemotely.filter((f) =>\n !fs.existsSync(`${filesDir}/${f}`)\n );\n\n // Check app changes too (works with both JWT and API key)\n let appStatus = { newLocal: [] as string[], modified: [] as string[], newRemote: [] as string[], synced: [] as string[] };\n const appSyncService = new AppSyncService(tenant, clientResult.client);\n appStatus = await appSyncService.getStatus();\n\n const hasFileChanges = filesToPush.length > 0 || filesToDelete.length > 0;\n const hasAppChanges = appStatus.newLocal.length > 0 || appStatus.modified.length > 0;\n\n if (!hasFileChanges && !hasAppChanges) {\n logger.success('Nothing to push. Everything is in sync.');\n return;\n }\n\n console.log();\n logger.header('Changes to push:');\n\n if (filesToPush.length > 0) {\n for (const file of filesToPush) {\n const isNew = status.onlyLocal.includes(file);\n if (isNew) {\n console.log(chalk.green(` + ${file}`));\n } else {\n console.log(chalk.yellow(` M ${file}`));\n }\n }\n }\n\n if (filesToDelete.length > 0) {\n for (const file of filesToDelete) {\n console.log(chalk.red(` - ${file}`));\n }\n }\n\n // Show app changes\n if (appStatus.newLocal.length > 0) {\n console.log(chalk.green('New apps:'));\n for (const app of appStatus.newLocal) {\n console.log(chalk.green(` + ${app}`));\n }\n }\n\n if (appStatus.modified.length > 0) {\n console.log(chalk.yellow('Modified apps:'));\n for (const app of appStatus.modified) {\n console.log(chalk.yellow(` ~ ${app}`));\n }\n }\n\n console.log();\n\n const totalChanges = filesToPush.length + filesToDelete.length + appStatus.newLocal.length + appStatus.modified.length;\n\n // Step 4: Confirm push\n const confirm = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'proceed',\n message: `Push ${totalChanges} change(s) to ${tenant}?`,\n default: true,\n },\n ]);\n\n if (!confirm.proceed) {\n logger.info('Push cancelled.');\n return;\n }\n\n // Ensure token is fresh before push operations (may have expired during user input)\n await ensureFreshToken(clientResult.client);\n\n try {\n // Step 5: Push files only if there are file changes\n let result = { uploaded: [] as string[], updated: [] as string[], deleted: [] as string[], unchanged: [] as string[] };\n\n if (hasFileChanges) {\n logger.info(`Pushing files to ${tenant}...`);\n result = await syncService.push();\n\n console.log();\n\n if (result.uploaded.length > 0) {\n console.log(chalk.green('Uploaded files (new):'));\n for (const file of result.uploaded) {\n console.log(chalk.green(` + ${file}`));\n }\n console.log();\n }\n\n if (result.updated.length > 0) {\n console.log(chalk.yellow('Updated files:'));\n for (const file of result.updated) {\n console.log(chalk.yellow(` M ${file}`));\n }\n console.log();\n }\n\n if (result.deleted.length > 0) {\n console.log(chalk.red('Deleted files:'));\n for (const file of result.deleted) {\n console.log(chalk.red(` - ${file}`));\n }\n console.log();\n }\n }\n\n // Step 6: Push apps only if there are app changes\n let appResult = { created: [] as string[], updated: [] as string[], deleted: [] as string[], unchanged: [] as string[] };\n\n if (hasAppChanges) {\n logger.info(`Pushing apps to ${tenant}...`);\n appResult = await appSyncService.push();\n\n if (appResult.created.length > 0) {\n console.log(chalk.green('Created apps:'));\n for (const app of appResult.created) {\n console.log(chalk.green(` + ${app}`));\n }\n console.log();\n }\n\n if (appResult.updated.length > 0) {\n console.log(chalk.yellow('Updated apps:'));\n for (const app of appResult.updated) {\n console.log(chalk.yellow(` ~ ${app}`));\n }\n console.log();\n }\n\n if (appResult.deleted.length > 0) {\n console.log(chalk.red('Deleted apps:'));\n for (const app of appResult.deleted) {\n console.log(chalk.red(` - ${app}`));\n }\n console.log();\n }\n }\n\n // Step 7: Git commit & push\n if (gitEnabled) {\n logger.info('Committing changes to git...');\n\n const appsPath = `apps/${tenant}`;\n await gitService.add([appsPath]);\n\n const commitMessage = `[${tenant}] ${options.message}\n\nFiles: +${result.uploaded.length} ~${result.updated.length} -${result.deleted.length}\nApps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length}\n\n\uD83E\uDD16 Generated with Farseer CLI`;\n\n const commitResult = await gitService.commit(commitMessage, CLI_GIT_AUTHOR);\n\n if (commitResult.success) {\n logger.dim(`Committed: ${commitResult.commitHash}`);\n\n logger.info('Pushing to git remote...');\n const pushResult = await gitService.push();\n\n if (pushResult.success) {\n logger.dim(pushResult.message);\n } else {\n logger.warning('Failed to push to git remote.');\n logger.dim(pushResult.message);\n logger.dim('You may need to push manually.');\n }\n } else {\n logger.warning('Failed to commit changes.');\n logger.dim(commitResult.message);\n }\n }\n\n console.log();\n logger.success('Push complete!');\n logger.dim(`Files: +${result.uploaded.length} ~${result.updated.length} -${result.deleted.length}`);\n logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length}`);\n } catch (error) {\n logger.error('Push failed.');\n if (error instanceof Error) {\n logger.dim(error.message);\n }\n process.exit(1);\n }\n });\n}\n"],
5
- "mappings": ";;;;;;;;;;;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AA+B;AAC9C,iCAAO,IAAI,WAAW,OAAO;AAC7B,iCAAO,IAAI,gCAAgC;AAAA,UAC/C;AAAA,QACJ,OAAO;AACH,+BAAO,QAAQ,2BAA2B;AAC1C,+BAAO,IAAI,aAAa,OAAO;AAAA,QACnC;AAAA,MACJ;AAEA,cAAQ,IAAI;AACZ,2BAAO,QAAQ,gBAAgB;AAC/B,2BAAO,IAAI,WAAW,OAAO,SAAS,MAAM,KAAK,OAAO,QAAQ,MAAM,KAAK,OAAO,QAAQ,MAAM,EAAE;AAClG,2BAAO,IAAI,UAAU,UAAU,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,EAAE;AAAA,IAC7G,SAAS,OAAO;AACZ,2BAAO,MAAM,cAAc;AAC3B,UAAI,iBAAiB,OAAO;AACxB,6BAAO,IAAI,MAAM,OAAO;AAAA,MAC5B;AACA,cAAQ,KAAK,CAAC;AAAA,IAClB;AAAA,EACJ,CAAC;AACT;",
6
- "names": ["chalk", "inquirer"]
7
- }
@@ -1,288 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var run_exports = {};
29
- __export(run_exports, {
30
- registerRunCommand: () => registerRunCommand
31
- });
32
- module.exports = __toCommonJS(run_exports);
33
- var import_logger = require("../utils/logger");
34
- var import_configService = require("../services/configService");
35
- var import_farseerService = require("../services/farseerService");
36
- var import_farseerFactory = require("../services/farseerFactory");
37
- var import_helpers = require("../utils/helpers");
38
- var fs = __toESM(require("fs"));
39
- var path = __toESM(require("path"));
40
- var import_child_process = require("child_process");
41
- function findScriptRecursively(baseDir, scriptName) {
42
- if (!fs.existsSync(baseDir)) {
43
- return null;
44
- }
45
- const search = (dir, relativePath = "") => {
46
- const items = fs.readdirSync(dir, { withFileTypes: true });
47
- for (const item of items) {
48
- const itemRelPath = relativePath ? `${relativePath}/${item.name}` : item.name;
49
- if (item.isFile() && item.name === scriptName) {
50
- return itemRelPath;
51
- }
52
- if (item.isDirectory()) {
53
- const found = search(path.join(dir, item.name), itemRelPath);
54
- if (found) return found;
55
- }
56
- }
57
- return null;
58
- };
59
- return search(baseDir);
60
- }
61
- async function getRunCredentials(tenant, tenantId) {
62
- const credential = (0, import_configService.getCredential)(tenant);
63
- if (credential) {
64
- return {
65
- tenantId: credential.tenantId,
66
- apiKey: credential.apiKey,
67
- basePath: credential.basePath
68
- };
69
- }
70
- const auth = (0, import_configService.getUserAuth)();
71
- if (!auth) {
72
- return null;
73
- }
74
- if (!(0, import_configService.isUserAuthValid)()) {
75
- import_logger.logger.dim("Token expired, refreshing...");
76
- const refreshed = await (0, import_farseerService.refreshAccessToken)(auth.refreshToken, auth.realm || "master");
77
- if (!refreshed) {
78
- import_logger.logger.warning("Could not refresh token. Please login again with: farseer login");
79
- return null;
80
- }
81
- (0, import_configService.setUserAuth)({
82
- accessToken: refreshed.accessToken,
83
- refreshToken: refreshed.refreshToken,
84
- expiresAt: new Date(Date.now() + refreshed.expiresIn * 1e3).toISOString(),
85
- realm: auth.realm
86
- });
87
- import_logger.logger.success("Token refreshed");
88
- }
89
- const updatedAuth = (0, import_configService.getUserAuth)();
90
- if (!updatedAuth) return null;
91
- return {
92
- tenantId: tenantId || tenant,
93
- accessToken: updatedAuth.accessToken,
94
- basePath: (0, import_configService.generateBasePath)(tenant)
95
- };
96
- }
97
- function collectArgs(value, previous) {
98
- return previous.concat([value]);
99
- }
100
- function registerRunCommand(program) {
101
- program.command("run <args...>").description("Run an app locally with injected credentials").option("--tenant-id <id>", "Tenant ID for env variables (defaults to tenant name)").option("--arg <value>", 'Pass argument in format "Name=Value" (can be used multiple times)', collectArgs, []).action(async (args, options) => {
102
- const { tenant, appName } = (0, import_helpers.parseAppArgs)(args);
103
- const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(tenant, options.tenantId);
104
- if (!clientResult) {
105
- (0, import_farseerFactory.showLoginPrompt)(tenant);
106
- process.exit(1);
107
- }
108
- const api = clientResult.client;
109
- import_logger.logger.info(`Loading app: ${appName}...`);
110
- const app = await api.getAppByName(appName);
111
- if (!app) {
112
- import_logger.logger.error(`App not found: ${appName}`);
113
- import_logger.logger.dim("List available apps with: farseer apps " + tenant);
114
- process.exit(1);
115
- }
116
- if (!app.mainScriptFileId || app.scriptFiles.length === 0) {
117
- import_logger.logger.error(`App "${appName}" has no scripts configured.`);
118
- import_logger.logger.dim('Configure the app with: farseer app configure "' + appName + '" --entrypoint <script>');
119
- process.exit(1);
120
- }
121
- const mainScript = app.scriptFiles.find((s) => s.id === app.mainScriptFileId);
122
- if (!mainScript) {
123
- import_logger.logger.error(`Entrypoint script not found for app "${appName}".`);
124
- process.exit(1);
125
- }
126
- let scriptName = mainScript.name;
127
- if (scriptName.toLowerCase().startsWith("scripts/")) {
128
- scriptName = scriptName.substring("scripts/".length);
129
- }
130
- const credentials = await getRunCredentials(tenant, options.tenantId);
131
- if (!credentials) {
132
- (0, import_farseerFactory.showLoginPrompt)(tenant);
133
- process.exit(1);
134
- }
135
- const tenantDir = (0, import_helpers.getTenantDir)(tenant);
136
- const srcDir = (0, import_helpers.getTenantSrcDir)(tenant);
137
- const filesDir = (0, import_helpers.getTenantFilesDir)(tenant);
138
- let scriptPath = path.resolve(srcDir, scriptName);
139
- let relativeScriptPath = `files/Scripts/${scriptName}`;
140
- if (!fs.existsSync(scriptPath)) {
141
- const foundPath = findScriptRecursively(filesDir, path.basename(scriptName));
142
- if (foundPath) {
143
- scriptPath = path.resolve(filesDir, foundPath);
144
- relativeScriptPath = `files/${foundPath}`;
145
- import_logger.logger.dim(`Found script at: ${foundPath}`);
146
- }
147
- }
148
- if (!fs.existsSync(scriptPath)) {
149
- import_logger.logger.error(`Script not found locally: ${scriptPath}`);
150
- import_logger.logger.dim('Run "farseer pull ' + tenant + '" to download scripts first.');
151
- process.exit(1);
152
- }
153
- const nodeModulesPath = path.join(tenantDir, "node_modules");
154
- if (!fs.existsSync(nodeModulesPath)) {
155
- import_logger.logger.error(`Dependencies not installed for ${tenant}`);
156
- import_logger.logger.dim(`Run: farseer install ${tenant}`);
157
- process.exit(1);
158
- }
159
- const appArgs = {};
160
- for (const arg of app.expectedArguments) {
161
- appArgs[arg.name] = arg.defaultValue;
162
- }
163
- for (const argStr of options.arg) {
164
- const eqIndex = argStr.indexOf("=");
165
- if (eqIndex === -1) {
166
- import_logger.logger.error(`Invalid argument format: ${argStr}`);
167
- import_logger.logger.dim('Use format: --arg "Name=Value"');
168
- process.exit(1);
169
- }
170
- const name = argStr.substring(0, eqIndex);
171
- const value = argStr.substring(eqIndex + 1);
172
- appArgs[name] = value;
173
- }
174
- const authType = credentials.apiKey ? "API key" : "access token";
175
- import_logger.logger.info(`Running app "${app.name}" (${scriptName}) for tenant ${tenant} (using ${authType})...`);
176
- if (Object.keys(appArgs).length > 0) {
177
- import_logger.logger.dim("Arguments:");
178
- for (const [key, value] of Object.entries(appArgs)) {
179
- import_logger.logger.dim(` ${key}: ${value}`);
180
- }
181
- }
182
- console.log();
183
- const envVars = {
184
- ...process.env,
185
- TENANT_ID: credentials.tenantId,
186
- FARSEER_URL: credentials.basePath
187
- };
188
- if (credentials.apiKey) {
189
- envVars.FARSEER_API_KEY = credentials.apiKey;
190
- }
191
- if (credentials.accessToken) {
192
- envVars.FARSEER_ACCESS_TOKEN = credentials.accessToken;
193
- }
194
- const cmdArgs = [];
195
- for (const arg of app.expectedArguments) {
196
- cmdArgs.push(appArgs[arg.name] ?? arg.defaultValue);
197
- }
198
- const quotedScriptPath = `"${relativeScriptPath}"`;
199
- const child = (0, import_child_process.spawn)("npx", ["tsx", quotedScriptPath, ...cmdArgs], {
200
- stdio: "inherit",
201
- cwd: tenantDir,
202
- shell: true,
203
- env: envVars
204
- });
205
- child.on("close", (code) => {
206
- if (code !== 0) {
207
- import_logger.logger.error(`Script exited with code ${code}`);
208
- process.exit(code || 1);
209
- }
210
- });
211
- child.on("error", (err) => {
212
- import_logger.logger.error(`Failed to run script: ${err.message}`);
213
- import_logger.logger.dim("Make sure tsx is installed: npm install -g tsx");
214
- process.exit(1);
215
- });
216
- });
217
- program.command("run-script <args...>").description("Run a script directly (without app wrapper)").option("--tenant-id <id>", "Tenant ID for env variables (defaults to tenant name)").action(async (args, options) => {
218
- let { tenant, appName: script } = (0, import_helpers.parseAppArgs)(args);
219
- const credentials = await getRunCredentials(tenant, options.tenantId);
220
- if (!credentials) {
221
- (0, import_farseerFactory.showLoginPrompt)(tenant);
222
- process.exit(1);
223
- }
224
- if (script.toLowerCase().startsWith("scripts/")) {
225
- script = script.substring("scripts/".length);
226
- }
227
- const tenantDir = (0, import_helpers.getTenantDir)(tenant);
228
- const srcDir = (0, import_helpers.getTenantSrcDir)(tenant);
229
- const filesDir = (0, import_helpers.getTenantFilesDir)(tenant);
230
- let scriptPath = path.resolve(srcDir, script);
231
- let relativeScriptPath = `files/Scripts/${script}`;
232
- if (!fs.existsSync(scriptPath)) {
233
- const foundPath = findScriptRecursively(filesDir, path.basename(script));
234
- if (foundPath) {
235
- scriptPath = path.resolve(filesDir, foundPath);
236
- relativeScriptPath = `files/${foundPath}`;
237
- import_logger.logger.dim(`Found script at: ${foundPath}`);
238
- }
239
- }
240
- if (!fs.existsSync(scriptPath)) {
241
- import_logger.logger.error(`Script not found: ${scriptPath}`);
242
- process.exit(1);
243
- }
244
- const nodeModulesPath = path.join(tenantDir, "node_modules");
245
- if (!fs.existsSync(nodeModulesPath)) {
246
- import_logger.logger.error(`Dependencies not installed for ${tenant}`);
247
- import_logger.logger.dim(`Run: farseer install ${tenant}`);
248
- process.exit(1);
249
- }
250
- const authType = credentials.apiKey ? "API key" : "access token";
251
- import_logger.logger.info(`Running ${script} for tenant ${tenant} (using ${authType})...`);
252
- console.log();
253
- const envVars = {
254
- ...process.env,
255
- TENANT_ID: credentials.tenantId,
256
- FARSEER_URL: credentials.basePath
257
- };
258
- if (credentials.apiKey) {
259
- envVars.FARSEER_API_KEY = credentials.apiKey;
260
- }
261
- if (credentials.accessToken) {
262
- envVars.FARSEER_ACCESS_TOKEN = credentials.accessToken;
263
- }
264
- const quotedScriptPath = `"${relativeScriptPath}"`;
265
- const child = (0, import_child_process.spawn)("npx", ["tsx", quotedScriptPath], {
266
- stdio: "inherit",
267
- cwd: tenantDir,
268
- shell: true,
269
- env: envVars
270
- });
271
- child.on("close", (code) => {
272
- if (code !== 0) {
273
- import_logger.logger.error(`Script exited with code ${code}`);
274
- process.exit(code || 1);
275
- }
276
- });
277
- child.on("error", (err) => {
278
- import_logger.logger.error(`Failed to run script: ${err.message}`);
279
- import_logger.logger.dim("Make sure tsx is installed: npm install -g tsx");
280
- process.exit(1);
281
- });
282
- });
283
- }
284
- // Annotate the CommonJS export names for ESM import in node:
285
- 0 && (module.exports = {
286
- registerRunCommand
287
- });
288
- //# sourceMappingURL=run.js.map