farseer-cli 1.3.0 → 1.5.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.
- package/README.md +102 -30
- package/dist/commands/checkout.js +3 -8
- package/dist/commands/checkout.js.map +2 -2
- package/dist/commands/dimensions.js +8 -8
- package/dist/commands/dimensions.js.map +2 -2
- package/dist/commands/model.js +29 -13
- package/dist/commands/model.js.map +2 -2
- package/dist/commands/pull.js +159 -46
- package/dist/commands/pull.js.map +2 -2
- package/dist/commands/push.js +185 -75
- package/dist/commands/push.js.map +2 -2
- package/dist/commands/run.js +31 -30
- package/dist/commands/run.js.map +2 -2
- package/dist/commands/status.js +26 -33
- package/dist/commands/status.js.map +2 -2
- package/dist/commands/variables.js +2 -2
- package/dist/commands/variables.js.map +2 -2
- package/dist/index.js +5 -3
- package/dist/index.js.map +2 -2
- package/dist/mcp/tools/appTools.js +6 -20
- package/dist/mcp/tools/appTools.js.map +2 -2
- package/dist/mcp/tools/authTools.js +2 -1
- package/dist/mcp/tools/authTools.js.map +2 -2
- package/dist/mcp/tools/cellTools.js +2 -10
- package/dist/mcp/tools/cellTools.js.map +2 -2
- package/dist/mcp/tools/dashboardTools.js +12 -23
- package/dist/mcp/tools/dashboardTools.js.map +2 -2
- package/dist/mcp/tools/dataTools.js +5 -16
- package/dist/mcp/tools/dataTools.js.map +2 -2
- package/dist/mcp/tools/folderTools.js +3 -11
- package/dist/mcp/tools/folderTools.js.map +2 -2
- package/dist/mcp/tools/modelTools.js +61 -69
- package/dist/mcp/tools/modelTools.js.map +2 -2
- package/dist/mcp/tools/runTools.js +3 -8
- package/dist/mcp/tools/runTools.js.map +2 -2
- package/dist/mcp/tools/sheetTools.js +11 -22
- package/dist/mcp/tools/sheetTools.js.map +2 -2
- package/dist/mcp/tools/syncTools.js +132 -47
- package/dist/mcp/tools/syncTools.js.map +2 -2
- package/dist/mcp/utils/helpers.js +2 -2
- package/dist/mcp/utils/helpers.js.map +2 -2
- package/dist/services/appSyncService.js +3 -2
- package/dist/services/appSyncService.js.map +2 -2
- package/dist/services/farseerApi.js +120 -72
- package/dist/services/farseerApi.js.map +2 -2
- package/dist/services/farseerFactory.js +1 -1
- package/dist/services/farseerFactory.js.map +2 -2
- package/dist/services/farseerService.js +87 -47
- package/dist/services/farseerService.js.map +2 -2
- package/dist/services/syncService.js +322 -182
- package/dist/services/syncService.js.map +3 -3
- package/dist/utils/cliOptions.js +36 -0
- package/dist/utils/cliOptions.js.map +7 -0
- package/dist/utils/errorFormatter.js +152 -0
- package/dist/utils/errorFormatter.js.map +7 -0
- package/dist/utils/fileLogger.js +13 -0
- package/dist/utils/fileLogger.js.map +2 -2
- package/dist/utils/fileValidation.js +180 -0
- package/dist/utils/fileValidation.js.map +7 -0
- package/dist/utils/helpers.js +85 -14
- package/dist/utils/helpers.js.map +2 -2
- package/docs/cli-guide.md +49 -4
- package/package.json +1 -1
package/dist/commands/push.js
CHANGED
|
@@ -28,6 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var push_exports = {};
|
|
30
30
|
__export(push_exports, {
|
|
31
|
+
buildPushPlan: () => buildPushPlan,
|
|
31
32
|
registerPushCommand: () => registerPushCommand
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(push_exports);
|
|
@@ -39,11 +40,17 @@ var import_farseerFactory = require("../services/farseerFactory");
|
|
|
39
40
|
var import_syncService = require("../services/syncService");
|
|
40
41
|
var import_appSyncService = require("../services/appSyncService");
|
|
41
42
|
var import_helpers = require("../utils/helpers");
|
|
43
|
+
var import_errorFormatter = require("../utils/errorFormatter");
|
|
44
|
+
var import_fileValidation = require("../utils/fileValidation");
|
|
45
|
+
var import_cliOptions = require("../utils/cliOptions");
|
|
42
46
|
var fs = __toESM(require("fs"));
|
|
43
47
|
function registerPushCommand(program) {
|
|
44
48
|
program.command("push [org] [tenant]").description(
|
|
45
49
|
"Push local files to Farseer instance\n\nUsage: push <org> <tenant> OR push <tenant> (if org is known)"
|
|
46
|
-
).option(
|
|
50
|
+
).option(
|
|
51
|
+
"--force",
|
|
52
|
+
"Force-mirror remote to local: overwrite remote drift AND delete remote files with no local counterpart (always asks for confirmation)"
|
|
53
|
+
).option("-y, --yes", "Skip confirmation prompt for non-destructive pushes (ignored under --force)").option("--include-ext <ext>", "Include extra file extension (repeatable)", import_cliOptions.collectValues, []).option("--include-folder <folder>", "Include all files in folder (repeatable)", import_cliOptions.collectValues, []).action(async (arg1, arg2, options) => {
|
|
47
54
|
const { organisation, tenant } = (0, import_helpers.resolveTenantWithOrgMapping)(arg1, arg2);
|
|
48
55
|
const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
|
|
49
56
|
if (!clientResult) {
|
|
@@ -57,7 +64,7 @@ function registerPushCommand(program) {
|
|
|
57
64
|
process.exit(1);
|
|
58
65
|
}
|
|
59
66
|
const syncService = new import_syncService.SyncService(tenant, clientResult.client);
|
|
60
|
-
const includeExtensions = normalizeExtensions(options.includeExt);
|
|
67
|
+
const includeExtensions = (0, import_cliOptions.normalizeExtensions)(options.includeExt);
|
|
61
68
|
const includeFolders = options.includeFolder;
|
|
62
69
|
const syncFilterOptions = {
|
|
63
70
|
includeExtensions: includeExtensions.length > 0 ? includeExtensions : void 0,
|
|
@@ -65,70 +72,106 @@ function registerPushCommand(program) {
|
|
|
65
72
|
};
|
|
66
73
|
if (!options.force) {
|
|
67
74
|
import_logger.logger.info("Checking for remote changes...");
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
70
|
-
import_logger.logger.error(
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
const driftResult = await syncService.checkRemoteChanges(syncFilterOptions);
|
|
76
|
+
if (driftResult.drift) {
|
|
77
|
+
import_logger.logger.error(
|
|
78
|
+
`Remote has ${driftResult.addedRemotely.length + driftResult.deletedRemotely.length} change(s) within your sync scope that aren't recorded locally.`
|
|
79
|
+
);
|
|
80
|
+
if (driftResult.addedRemotely.length > 0) {
|
|
81
|
+
console.log(import_chalk.default.cyan(" New on remote (need to pull):"));
|
|
82
|
+
for (const f of driftResult.addedRemotely) console.log(import_chalk.default.cyan(` + ${f}`));
|
|
83
|
+
}
|
|
84
|
+
if (driftResult.deletedRemotely.length > 0) {
|
|
85
|
+
console.log(import_chalk.default.red(" Removed on remote (need to pull to clean local):"));
|
|
86
|
+
for (const f of driftResult.deletedRemotely) console.log(import_chalk.default.red(` - ${f}`));
|
|
87
|
+
}
|
|
88
|
+
const scopeFlags = [];
|
|
89
|
+
for (const ext of options.includeExt) scopeFlags.push(`--include-ext ${ext}`);
|
|
90
|
+
for (const folder of options.includeFolder)
|
|
91
|
+
scopeFlags.push(`--include-folder "${folder}"`);
|
|
92
|
+
const pullCmd = ["farseer pull", tenant, ...scopeFlags].filter(Boolean).join(" ");
|
|
93
|
+
import_logger.logger.dim(`Run \`${pullCmd}\` first, then try pushing again.`);
|
|
94
|
+
import_logger.logger.dim("Or use --force to overwrite remote (this will also mirror deletions).");
|
|
73
95
|
process.exit(1);
|
|
74
96
|
}
|
|
75
|
-
import_logger.logger.dim("Remote is in sync.");
|
|
76
|
-
}
|
|
77
|
-
const status = await syncService.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
newRemote: [],
|
|
84
|
-
synced: []
|
|
85
|
-
};
|
|
97
|
+
import_logger.logger.dim("Remote is in sync with local baseline.");
|
|
98
|
+
}
|
|
99
|
+
const status = await syncService.getStatus({
|
|
100
|
+
...syncFilterOptions,
|
|
101
|
+
deep: !!options.force
|
|
102
|
+
});
|
|
103
|
+
const plan = buildPushPlan(status, { force: !!options.force });
|
|
104
|
+
const { filesToUpload, filesToDelete, remoteOnlyFiles, filesToRecreate, filesToOverwrite } = plan;
|
|
86
105
|
const appSyncService = new import_appSyncService.AppSyncService(tenant, clientResult.client);
|
|
87
|
-
appStatus = await appSyncService.getStatus();
|
|
88
|
-
const
|
|
106
|
+
const appStatus = await appSyncService.getStatus();
|
|
107
|
+
const hasConflicts = status.conflicts.length > 0;
|
|
108
|
+
const hasFileChanges = filesToUpload.length > 0 || filesToDelete.length > 0 || remoteOnlyFiles.length > 0 || hasConflicts;
|
|
89
109
|
const hasAppChanges = appStatus.newLocal.length > 0 || appStatus.modified.length > 0;
|
|
90
110
|
if (!hasFileChanges && !hasAppChanges) {
|
|
91
111
|
import_logger.logger.success("Nothing to push. Everything is in sync.");
|
|
92
112
|
return;
|
|
93
113
|
}
|
|
94
114
|
console.log();
|
|
95
|
-
import_logger.logger.header("Changes to push:");
|
|
96
|
-
if (
|
|
97
|
-
for (const file of
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
} else {
|
|
102
|
-
console.log(import_chalk.default.yellow(` M ${file}`));
|
|
103
|
-
}
|
|
104
|
-
}
|
|
115
|
+
import_logger.logger.header(options.force ? "Mirror plan (--force):" : "Changes to push:");
|
|
116
|
+
if (status.addedLocally.length > 0) {
|
|
117
|
+
for (const file of status.addedLocally) console.log(import_chalk.default.green(` + ${file}`));
|
|
118
|
+
}
|
|
119
|
+
if (status.modifiedLocally.length > 0) {
|
|
120
|
+
for (const file of status.modifiedLocally) console.log(import_chalk.default.yellow(` M ${file}`));
|
|
105
121
|
}
|
|
106
122
|
if (filesToDelete.length > 0) {
|
|
107
|
-
for (const file of filesToDelete) {
|
|
108
|
-
|
|
123
|
+
for (const file of filesToDelete) console.log(import_chalk.default.red(` - ${file}`));
|
|
124
|
+
}
|
|
125
|
+
if (remoteOnlyFiles.length > 0) {
|
|
126
|
+
console.log(import_chalk.default.red.bold("Remote-only files that will be DELETED on remote:"));
|
|
127
|
+
for (const file of remoteOnlyFiles) console.log(import_chalk.default.red(` - ${file} (remote only)`));
|
|
128
|
+
}
|
|
129
|
+
if (filesToRecreate.length > 0) {
|
|
130
|
+
console.log(import_chalk.default.green.bold("Files deleted on remote that will be RECREATED:"));
|
|
131
|
+
for (const file of filesToRecreate) console.log(import_chalk.default.green(` + ${file} (re-uploading local copy)`));
|
|
132
|
+
}
|
|
133
|
+
if (filesToOverwrite.length > 0) {
|
|
134
|
+
console.log(import_chalk.default.yellow.bold("Files where remote drifted \u2014 local will OVERWRITE:"));
|
|
135
|
+
for (const file of filesToOverwrite)
|
|
136
|
+
console.log(import_chalk.default.yellow(` M ${file} (remote content drift; local wins)`));
|
|
137
|
+
}
|
|
138
|
+
if (hasConflicts) {
|
|
139
|
+
const headerText = options.force ? "Conflicts (will be force-overwritten on remote):" : "Conflicts (will be SKIPPED \u2014 pull first to resolve):";
|
|
140
|
+
console.log(import_chalk.default.red.bold(headerText));
|
|
141
|
+
for (const conflict of status.conflicts) {
|
|
142
|
+
console.log(import_chalk.default.red(` ! ${conflict.filePath}`));
|
|
143
|
+
console.log(import_chalk.default.dim(` ${conflict.description}`));
|
|
109
144
|
}
|
|
110
145
|
}
|
|
111
146
|
if (appStatus.newLocal.length > 0) {
|
|
112
147
|
console.log(import_chalk.default.green("New apps:"));
|
|
113
|
-
for (const app of appStatus.newLocal) {
|
|
114
|
-
console.log(import_chalk.default.green(` + ${app}`));
|
|
115
|
-
}
|
|
148
|
+
for (const app of appStatus.newLocal) console.log(import_chalk.default.green(` + ${app}`));
|
|
116
149
|
}
|
|
117
150
|
if (appStatus.modified.length > 0) {
|
|
118
151
|
console.log(import_chalk.default.yellow("Modified apps:"));
|
|
119
|
-
for (const app of appStatus.modified) {
|
|
120
|
-
|
|
152
|
+
for (const app of appStatus.modified) console.log(import_chalk.default.yellow(` ~ ${app}`));
|
|
153
|
+
}
|
|
154
|
+
const previewCandidates = [...filesToUpload, ...filesToRecreate, ...filesToOverwrite];
|
|
155
|
+
const previewRejections = previewPushPlan(filesDir, previewCandidates);
|
|
156
|
+
if (previewRejections.length > 0) {
|
|
157
|
+
console.log();
|
|
158
|
+
console.log(import_chalk.default.red.bold("Files that pre-flight will reject (skipped from upload):"));
|
|
159
|
+
for (const r of previewRejections) {
|
|
160
|
+
console.log(import_chalk.default.red(` \u2717 ${r.filePath}`));
|
|
161
|
+
console.log(import_chalk.default.dim(` ${r.detail}`));
|
|
162
|
+
if (r.hint) console.log(import_chalk.default.dim(` ${r.hint}`));
|
|
121
163
|
}
|
|
122
164
|
}
|
|
123
165
|
console.log();
|
|
124
|
-
const totalChanges =
|
|
125
|
-
|
|
166
|
+
const totalChanges = filesToUpload.length + filesToDelete.length + remoteOnlyFiles.length + appStatus.newLocal.length + appStatus.modified.length;
|
|
167
|
+
const confirmMessage = options.force ? `Mirror to ${tenant}: ${remoteOnlyFiles.length} remote deletion(s), ${filesToOverwrite.length} drift overwrite(s), ${filesToRecreate.length} recreation(s), ${status.addedLocally.length} new upload(s), ${status.modifiedLocally.length} local edit(s), ${filesToDelete.length} local-rm deletion(s). This is destructive.` : `Push ${totalChanges} change(s) to ${tenant}?`;
|
|
168
|
+
if (options.force || !options.yes) {
|
|
126
169
|
const confirm = await import_inquirer.default.prompt([
|
|
127
170
|
{
|
|
128
171
|
type: "confirm",
|
|
129
172
|
name: "proceed",
|
|
130
|
-
message:
|
|
131
|
-
default:
|
|
173
|
+
message: confirmMessage,
|
|
174
|
+
default: !options.force
|
|
132
175
|
}
|
|
133
176
|
]);
|
|
134
177
|
if (!confirm.proceed) {
|
|
@@ -138,41 +181,59 @@ function registerPushCommand(program) {
|
|
|
138
181
|
}
|
|
139
182
|
await (0, import_farseerFactory.ensureFreshToken)(clientResult.client);
|
|
140
183
|
try {
|
|
141
|
-
let result = {
|
|
184
|
+
let result = {
|
|
185
|
+
uploaded: [],
|
|
186
|
+
updated: [],
|
|
187
|
+
deleted: [],
|
|
188
|
+
unchanged: [],
|
|
189
|
+
conflicts: [],
|
|
190
|
+
rejected: [],
|
|
191
|
+
failed: []
|
|
192
|
+
};
|
|
142
193
|
if (hasFileChanges) {
|
|
143
194
|
import_logger.logger.info(`Pushing files to ${tenant}...`);
|
|
144
|
-
result = await syncService.push({
|
|
195
|
+
result = await syncService.push({
|
|
196
|
+
force: options.force,
|
|
197
|
+
mirror: options.force,
|
|
198
|
+
...syncFilterOptions,
|
|
199
|
+
precomputedRemoteHashes: status.remoteHashes
|
|
200
|
+
});
|
|
145
201
|
console.log();
|
|
146
|
-
if (result.
|
|
202
|
+
if (result.rejected.length > 0) {
|
|
203
|
+
console.log(import_chalk.default.red.bold("Files skipped (backend would reject):"));
|
|
204
|
+
renderRejections(result.rejected);
|
|
205
|
+
}
|
|
206
|
+
if (result.conflicts.length > 0) {
|
|
147
207
|
console.log(import_chalk.default.red.bold(`${result.conflicts.length} conflict(s) detected:`));
|
|
148
|
-
console.log();
|
|
149
208
|
for (const conflict of result.conflicts) {
|
|
150
209
|
console.log(import_chalk.default.red(` ! ${conflict.filePath}`));
|
|
151
210
|
console.log(import_chalk.default.dim(` ${conflict.description}`));
|
|
152
211
|
}
|
|
153
212
|
console.log();
|
|
154
213
|
import_logger.logger.dim(`Resolve conflicts by pulling first: farseer pull ${tenant}`);
|
|
155
|
-
import_logger.logger.dim("Or use --force to push anyway (
|
|
214
|
+
import_logger.logger.dim("Or use --force to push anyway (overwrites remote and mirrors deletions).");
|
|
156
215
|
console.log();
|
|
157
216
|
}
|
|
158
217
|
if (result.uploaded.length > 0) {
|
|
159
218
|
console.log(import_chalk.default.green("Uploaded files (new):"));
|
|
160
|
-
for (const file of result.uploaded) {
|
|
161
|
-
console.log(import_chalk.default.green(` + ${file}`));
|
|
162
|
-
}
|
|
219
|
+
for (const file of result.uploaded) console.log(import_chalk.default.green(` + ${file}`));
|
|
163
220
|
console.log();
|
|
164
221
|
}
|
|
165
222
|
if (result.updated.length > 0) {
|
|
166
223
|
console.log(import_chalk.default.yellow("Updated files:"));
|
|
167
|
-
for (const file of result.updated) {
|
|
168
|
-
console.log(import_chalk.default.yellow(` M ${file}`));
|
|
169
|
-
}
|
|
224
|
+
for (const file of result.updated) console.log(import_chalk.default.yellow(` M ${file}`));
|
|
170
225
|
console.log();
|
|
171
226
|
}
|
|
172
227
|
if (result.deleted.length > 0) {
|
|
173
228
|
console.log(import_chalk.default.red("Deleted files:"));
|
|
174
|
-
for (const file of result.deleted) {
|
|
175
|
-
|
|
229
|
+
for (const file of result.deleted) console.log(import_chalk.default.red(` - ${file}`));
|
|
230
|
+
console.log();
|
|
231
|
+
}
|
|
232
|
+
if (result.failed.length > 0) {
|
|
233
|
+
console.log(import_chalk.default.red.bold(`${result.failed.length} file(s) failed during push:`));
|
|
234
|
+
for (const failure of result.failed) {
|
|
235
|
+
console.log(import_chalk.default.red(` ! ${failure.filePath} (${failure.operation})`));
|
|
236
|
+
console.log(import_chalk.default.dim(` ${failure.reason}`));
|
|
176
237
|
}
|
|
177
238
|
console.log();
|
|
178
239
|
}
|
|
@@ -188,43 +249,61 @@ function registerPushCommand(program) {
|
|
|
188
249
|
appResult = await appSyncService.push();
|
|
189
250
|
if (appResult.created.length > 0) {
|
|
190
251
|
console.log(import_chalk.default.green("Created apps:"));
|
|
191
|
-
for (const app of appResult.created) {
|
|
192
|
-
console.log(import_chalk.default.green(` + ${app}`));
|
|
193
|
-
}
|
|
252
|
+
for (const app of appResult.created) console.log(import_chalk.default.green(` + ${app}`));
|
|
194
253
|
console.log();
|
|
195
254
|
}
|
|
196
255
|
if (appResult.updated.length > 0) {
|
|
197
256
|
console.log(import_chalk.default.yellow("Updated apps:"));
|
|
198
|
-
for (const app of appResult.updated) {
|
|
199
|
-
console.log(import_chalk.default.yellow(` ~ ${app}`));
|
|
200
|
-
}
|
|
257
|
+
for (const app of appResult.updated) console.log(import_chalk.default.yellow(` ~ ${app}`));
|
|
201
258
|
console.log();
|
|
202
259
|
}
|
|
203
260
|
if (appResult.deleted.length > 0) {
|
|
204
261
|
console.log(import_chalk.default.red("Deleted apps:"));
|
|
205
|
-
for (const app of appResult.deleted) {
|
|
206
|
-
console.log(import_chalk.default.red(` - ${app}`));
|
|
207
|
-
}
|
|
262
|
+
for (const app of appResult.deleted) console.log(import_chalk.default.red(` - ${app}`));
|
|
208
263
|
console.log();
|
|
209
264
|
}
|
|
210
265
|
}
|
|
211
266
|
console.log();
|
|
267
|
+
const fileSideEffects = result.uploaded.length + result.updated.length + result.deleted.length;
|
|
268
|
+
const appSideEffects = appResult.created.length + appResult.updated.length + appResult.deleted.length;
|
|
269
|
+
const conflictCount = result.conflicts.length;
|
|
270
|
+
const rejectedCount = result.rejected.length;
|
|
271
|
+
const failedCount = result.failed.length;
|
|
272
|
+
if (fileSideEffects + appSideEffects === 0 && (conflictCount > 0 || rejectedCount > 0)) {
|
|
273
|
+
if (rejectedCount > 0 && conflictCount === 0) {
|
|
274
|
+
import_logger.logger.warning(`Push did nothing \u2014 ${rejectedCount} file(s) rejected by pre-flight.`);
|
|
275
|
+
import_logger.logger.dim("Fix the issues listed above and re-run `farseer push`.");
|
|
276
|
+
} else if (conflictCount > 0 && rejectedCount === 0) {
|
|
277
|
+
import_logger.logger.warning(`Push did nothing \u2014 ${conflictCount} conflict(s) blocked the upload.`);
|
|
278
|
+
import_logger.logger.dim(`Resolve via 'farseer pull ${tenant}' or rerun with --force.`);
|
|
279
|
+
} else {
|
|
280
|
+
import_logger.logger.warning(
|
|
281
|
+
`Push did nothing \u2014 ${rejectedCount} file(s) rejected and ${conflictCount} conflict(s) blocked the upload.`
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
process.exit(1);
|
|
285
|
+
}
|
|
212
286
|
import_logger.logger.success("Push complete!");
|
|
213
287
|
import_logger.logger.dim(`Files: +${result.uploaded.length} ~${result.updated.length} -${result.deleted.length}`);
|
|
214
288
|
import_logger.logger.dim(
|
|
215
289
|
`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length}`
|
|
216
290
|
);
|
|
291
|
+
if (rejectedCount > 0 || failedCount > 0) {
|
|
292
|
+
if (rejectedCount > 0 && failedCount > 0) {
|
|
293
|
+
import_logger.logger.warning(
|
|
294
|
+
`${rejectedCount} file(s) skipped pre-flight, ${failedCount} failed mid-push \u2014 see above and rerun.`
|
|
295
|
+
);
|
|
296
|
+
} else if (rejectedCount > 0) {
|
|
297
|
+
import_logger.logger.warning(`${rejectedCount} file(s) skipped (see above) \u2014 fix and rerun.`);
|
|
298
|
+
} else {
|
|
299
|
+
import_logger.logger.warning(`${failedCount} file(s) failed during push (see above) \u2014 rerun to retry.`);
|
|
300
|
+
}
|
|
301
|
+
process.exit(1);
|
|
302
|
+
}
|
|
217
303
|
} catch (error) {
|
|
218
304
|
import_fileLogger.fileLogger.error("push", error, { tenant, organisation });
|
|
219
305
|
import_logger.logger.error("Push failed.");
|
|
220
|
-
|
|
221
|
-
import_logger.logger.error(error.message);
|
|
222
|
-
if (error.cause) {
|
|
223
|
-
import_logger.logger.dim(String(error.cause));
|
|
224
|
-
}
|
|
225
|
-
} else {
|
|
226
|
-
import_logger.logger.dim(String(error));
|
|
227
|
-
}
|
|
306
|
+
import_logger.logger.error(await (0, import_errorFormatter.formatClientError)(error));
|
|
228
307
|
const logPath = import_fileLogger.fileLogger.getLogPath();
|
|
229
308
|
if (logPath) {
|
|
230
309
|
import_logger.logger.dim(`Debug log: ${logPath}`);
|
|
@@ -233,14 +312,45 @@ function registerPushCommand(program) {
|
|
|
233
312
|
}
|
|
234
313
|
});
|
|
235
314
|
}
|
|
236
|
-
function
|
|
237
|
-
return
|
|
315
|
+
function buildPushPlan(status, options) {
|
|
316
|
+
return {
|
|
317
|
+
filesToUpload: [
|
|
318
|
+
...status.addedLocally,
|
|
319
|
+
...status.modifiedLocally,
|
|
320
|
+
...options.force ? status.deletedRemotely : [],
|
|
321
|
+
...options.force ? status.modifiedRemotely : []
|
|
322
|
+
],
|
|
323
|
+
filesToDelete: [...status.deletedLocally],
|
|
324
|
+
remoteOnlyFiles: options.force ? [...status.addedRemotely] : [],
|
|
325
|
+
filesToRecreate: options.force ? [...status.deletedRemotely] : [],
|
|
326
|
+
filesToOverwrite: options.force ? [...status.modifiedRemotely] : []
|
|
327
|
+
};
|
|
238
328
|
}
|
|
239
|
-
function
|
|
240
|
-
|
|
329
|
+
function renderRejections(rejections) {
|
|
330
|
+
for (const r of rejections) {
|
|
331
|
+
console.log(import_chalk.default.red(` x ${r.filePath}`));
|
|
332
|
+
console.log(import_chalk.default.dim(` ${r.detail}`));
|
|
333
|
+
if (r.hint) console.log(import_chalk.default.dim(` ${r.hint}`));
|
|
334
|
+
}
|
|
335
|
+
console.log();
|
|
336
|
+
}
|
|
337
|
+
function previewPushPlan(filesDir, candidates) {
|
|
338
|
+
const validationInputs = [];
|
|
339
|
+
for (const filePath of candidates) {
|
|
340
|
+
try {
|
|
341
|
+
const fullPath = (0, import_helpers.safeResolveWithinBase)(filesDir, filePath);
|
|
342
|
+
const content = fs.readFileSync(fullPath);
|
|
343
|
+
validationInputs.push({ filePath, size: content.length, content });
|
|
344
|
+
} catch {
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const { rejected } = (0, import_fileValidation.partitionForUpload)(validationInputs);
|
|
349
|
+
return rejected;
|
|
241
350
|
}
|
|
242
351
|
// Annotate the CommonJS export names for ESM import in node:
|
|
243
352
|
0 && (module.exports = {
|
|
353
|
+
buildPushPlan,
|
|
244
354
|
registerPushCommand
|
|
245
355
|
});
|
|
246
356
|
//# sourceMappingURL=push.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 { fileLogger } from '../utils/fileLogger';\nimport { getFarseerClientWithFallback, showLoginPrompt, ensureFreshToken } from '../services/farseerFactory';\nimport { SyncService } from '../services/syncService';\nimport { AppSyncService } from '../services/appSyncService';\nimport { getTenantFilesDir, resolveTenantWithOrgMapping } from '../utils/helpers';\nimport * as fs from 'fs';\n\nexport function registerPushCommand(program: Command): void {\n program\n .command('push [org] [tenant]')\n .description(\n 'Push local files to Farseer instance\\n\\nUsage: push <org> <tenant> OR push <tenant> (if org is known)',\n )\n .option('--force', 'Force push even if remote has changes')\n .option('-y, --yes', 'Skip confirmation prompt (auto-confirm)')\n .option('--include-ext <ext>', 'Include extra file extension (repeatable)', collectValues, [])\n .option('--include-folder <folder>', 'Include all files in folder (repeatable)', collectValues, [])\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: farseer-apps/${tenant}/files/`);\n logger.dim('Run \"farseer pull <tenant>\" first to initialize the folder.');\n process.exit(1);\n }\n\n const syncService = new SyncService(tenant, clientResult.client);\n const includeExtensions = normalizeExtensions(options.includeExt);\n const includeFolders = options.includeFolder as string[];\n const syncFilterOptions = {\n includeExtensions: includeExtensions.length > 0 ? includeExtensions : undefined,\n includeFolders: includeFolders.length > 0 ? includeFolders : undefined,\n };\n\n // Step 1: Check if remote has unpulled changes\n if (!options.force) {\n logger.info('Checking for remote changes...');\n\n const hasRemoteChanges = await syncService.checkRemoteChanges(syncFilterOptions);\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 2: Show what will be pushed (using fast status check that doesn't download remote content)\n const status = await syncService.getStatusFast(syncFilterOptions);\n\n const filesToPush = [...status.modifiedLocally, ...status.onlyLocal];\n\n const filesToDelete = status.modifiedRemotely.filter((f) => !fs.existsSync(`${filesDir}/${f}`));\n\n // Check app changes too\n let appStatus = {\n newLocal: [] as string[],\n modified: [] as string[],\n newRemote: [] as string[],\n synced: [] as string[],\n };\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 =\n filesToPush.length + filesToDelete.length + appStatus.newLocal.length + appStatus.modified.length;\n\n // Step 3: Confirm push (skip if --yes flag is set)\n if (!options.yes) {\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\n // Ensure token is fresh before push operations (may have expired during user input)\n await ensureFreshToken(clientResult.client);\n\n try {\n // Step 4: Push files only if there are file changes\n let result: {\n uploaded: string[];\n updated: string[];\n deleted: string[];\n unchanged: string[];\n conflicts?: import('../services/syncService').SyncConflict[];\n } = { uploaded: [], updated: [], deleted: [], unchanged: [] };\n\n if (hasFileChanges) {\n logger.info(`Pushing files to ${tenant}...`);\n result = await syncService.push({ force: options.force });\n\n console.log();\n\n if (result.conflicts && result.conflicts.length > 0) {\n console.log(chalk.red.bold(`${result.conflicts.length} conflict(s) detected:`));\n console.log();\n for (const conflict of result.conflicts) {\n console.log(chalk.red(` ! ${conflict.filePath}`));\n console.log(chalk.dim(` ${conflict.description}`));\n }\n console.log();\n logger.dim(`Resolve conflicts by pulling first: farseer pull ${tenant}`);\n logger.dim('Or use --force to push anyway (may overwrite remote changes).');\n console.log();\n }\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 5: Push apps only if there are app changes\n let appResult = {\n created: [] as string[],\n updated: [] as string[],\n deleted: [] as string[],\n unchanged: [] as string[],\n };\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 console.log();\n logger.success('Push complete!');\n logger.dim(`Files: +${result.uploaded.length} ~${result.updated.length} -${result.deleted.length}`);\n logger.dim(\n `Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length}`,\n );\n } catch (error) {\n fileLogger.error('push', error, { tenant, organisation });\n logger.error('Push failed.');\n if (error instanceof Error) {\n logger.error(error.message);\n if (error.cause) {\n logger.dim(String(error.cause));\n }\n } else {\n logger.dim(String(error));\n }\n const logPath = fileLogger.getLogPath();\n if (logPath) {\n logger.dim(`Debug log: ${logPath}`);\n }\n process.exit(1);\n }\n });\n}\n\nfunction collectValues(value: string, previous: string[]): string[] {\n return previous.concat([value]);\n}\n\nfunction normalizeExtensions(exts: string[]): string[] {\n return exts.map((ext) => (ext.startsWith('.') ? ext.toLowerCase() : `.${ext.toLowerCase()}`));\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,sBAAqB;AACrB,oBAAuB;AACvB,wBAA2B;AAC3B,4BAAgF;AAChF,yBAA4B;AAC5B,4BAA+B;AAC/B,
|
|
4
|
+
"sourcesContent": ["import { Command } from 'commander';\nimport chalk from 'chalk';\nimport inquirer from 'inquirer';\nimport { logger } from '../utils/logger';\nimport { fileLogger } from '../utils/fileLogger';\nimport { getFarseerClientWithFallback, showLoginPrompt, ensureFreshToken } from '../services/farseerFactory';\nimport { SyncService } from '../services/syncService';\nimport { AppSyncService } from '../services/appSyncService';\nimport { getTenantFilesDir, resolveTenantWithOrgMapping, safeResolveWithinBase } from '../utils/helpers';\nimport { formatClientError } from '../utils/errorFormatter';\nimport { ValidationFailure, partitionForUpload } from '../utils/fileValidation';\nimport { collectValues, normalizeExtensions } from '../utils/cliOptions';\nimport type { SyncStatus } from '../services/syncService';\nimport * as fs from 'fs';\n\n/**\n * Push semantics (in plain English, since this is the easiest part of the\n * CLI to misunderstand):\n *\n * farseer push\n * 1. Pre-flight: refuse local files that the backend will reject\n * (extension whitelist, name length, empty body). Print them and\n * exit non-zero so the user fixes them before we touch the network.\n * 2. Compare local vs remote (no remote download \u2014 we trust the\n * recorded sync baseline). If remote diverged from baseline,\n * refuse and ask the user to pull first.\n * 3. Show a diff (added / modified / deleted).\n * 4. Confirm.\n * 5. Upload modified files. Re-check each one against current remote\n * right before overwrite to avoid clobbering a concurrent edit.\n *\n * farseer push --force\n * Same as above, but:\n * \u2022 Skip step 2 (allow pushing over remote drift).\n * \u2022 Make remote mirror local: also delete any remote files that\n * have no local counterpart (not just ones you previously pulled).\n * Because --force is destructive, we always show the full plan\n * (including deletions of remote-only files) and require an explicit\n * \"yes\". `-y` won't bypass --force confirmation; you must answer the\n * prompt.\n */\nexport function registerPushCommand(program: Command): void {\n program\n .command('push [org] [tenant]')\n .description(\n 'Push local files to Farseer instance\\n\\nUsage: push <org> <tenant> OR push <tenant> (if org is known)',\n )\n .option(\n '--force',\n 'Force-mirror remote to local: overwrite remote drift AND delete remote files with no local counterpart (always asks for confirmation)',\n )\n .option('-y, --yes', 'Skip confirmation prompt for non-destructive pushes (ignored under --force)')\n .option('--include-ext <ext>', 'Include extra file extension (repeatable)', collectValues, [])\n .option('--include-folder <folder>', 'Include all files in folder (repeatable)', collectValues, [])\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: farseer-apps/${tenant}/files/`);\n logger.dim('Run \"farseer pull <tenant>\" first to initialize the folder.');\n process.exit(1);\n }\n\n const syncService = new SyncService(tenant, clientResult.client);\n const includeExtensions = normalizeExtensions(options.includeExt);\n const includeFolders = options.includeFolder as string[];\n const syncFilterOptions = {\n includeExtensions: includeExtensions.length > 0 ? includeExtensions : undefined,\n includeFolders: includeFolders.length > 0 ? includeFolders : undefined,\n };\n\n // Step 1: Drift check. Skipped under --force; the user has\n // explicitly opted into overwriting whatever's on remote.\n if (!options.force) {\n logger.info('Checking for remote changes...');\n const driftResult = await syncService.checkRemoteChanges(syncFilterOptions);\n if (driftResult.drift) {\n logger.error(\n `Remote has ${driftResult.addedRemotely.length + driftResult.deletedRemotely.length} change(s) within your sync scope that aren't recorded locally.`,\n );\n if (driftResult.addedRemotely.length > 0) {\n console.log(chalk.cyan(' New on remote (need to pull):'));\n for (const f of driftResult.addedRemotely) console.log(chalk.cyan(` + ${f}`));\n }\n if (driftResult.deletedRemotely.length > 0) {\n console.log(chalk.red(' Removed on remote (need to pull to clean local):'));\n for (const f of driftResult.deletedRemotely) console.log(chalk.red(` - ${f}`));\n }\n // Echo back the same scope flags the user passed so the\n // suggested pull command actually fetches the files\n // causing the drift. Without this, `farseer pull` runs\n // in default scope and says \"Already up to date\",\n // leaving the user stuck in a loop.\n const scopeFlags: string[] = [];\n for (const ext of options.includeExt as string[]) scopeFlags.push(`--include-ext ${ext}`);\n for (const folder of options.includeFolder as string[])\n scopeFlags.push(`--include-folder \"${folder}\"`);\n const pullCmd = ['farseer pull', tenant, ...scopeFlags].filter(Boolean).join(' ');\n logger.dim(`Run \\`${pullCmd}\\` first, then try pushing again.`);\n logger.dim('Or use --force to overwrite remote (this will also mirror deletions).');\n process.exit(1);\n }\n logger.dim('Remote is in sync with local baseline.');\n }\n\n // Step 2: Build a single status snapshot \u2014 same buckets the\n // `farseer status` command uses, so the user sees the same\n // categorisation in both places.\n //\n // Under --force, run a DEEP status. Reason: fast status can't\n // see remote-side content drift (it trusts our recorded\n // baseline), so a mirror push where someone else has edited\n // a file we still match locally would short-circuit at the\n // hasFileChanges check and never invoke service.push() \u2014\n // even though service.push({ mirror: true }) was specifically\n // built to overwrite that drift. Deep is slow on big tenants\n // but the user has already opted into a destructive, slow\n // operation by passing --force.\n const status = await syncService.getStatus({\n ...syncFilterOptions,\n deep: !!options.force,\n });\n\n const plan = buildPushPlan(status, { force: !!options.force });\n const { filesToUpload, filesToDelete, remoteOnlyFiles, filesToRecreate, filesToOverwrite } = plan;\n\n // Apps are independent of the file pre-flight gate.\n const appSyncService = new AppSyncService(tenant, clientResult.client);\n const appStatus = await appSyncService.getStatus();\n\n const hasConflicts = status.conflicts.length > 0;\n const hasFileChanges =\n filesToUpload.length > 0 || filesToDelete.length > 0 || remoteOnlyFiles.length > 0 || hasConflicts;\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(options.force ? 'Mirror plan (--force):' : 'Changes to push:');\n\n if (status.addedLocally.length > 0) {\n for (const file of status.addedLocally) console.log(chalk.green(` + ${file}`));\n }\n if (status.modifiedLocally.length > 0) {\n for (const file of status.modifiedLocally) console.log(chalk.yellow(` M ${file}`));\n }\n if (filesToDelete.length > 0) {\n for (const file of filesToDelete) console.log(chalk.red(` - ${file}`));\n }\n if (remoteOnlyFiles.length > 0) {\n console.log(chalk.red.bold('Remote-only files that will be DELETED on remote:'));\n for (const file of remoteOnlyFiles) console.log(chalk.red(` - ${file} (remote only)`));\n }\n if (filesToRecreate.length > 0) {\n console.log(chalk.green.bold('Files deleted on remote that will be RECREATED:'));\n for (const file of filesToRecreate) console.log(chalk.green(` + ${file} (re-uploading local copy)`));\n }\n if (filesToOverwrite.length > 0) {\n console.log(chalk.yellow.bold('Files where remote drifted \u2014 local will OVERWRITE:'));\n for (const file of filesToOverwrite)\n console.log(chalk.yellow(` M ${file} (remote content drift; local wins)`));\n }\n\n // Conflicts surface BEFORE the confirmation prompt so the user\n // never confirms a plan that secretly contains skipped files.\n // Without --force these will be skipped (and the user can re-run\n // with `farseer pull` to resolve); under --force the upload step\n // will overwrite local\u2192remote anyway, but the user still deserves\n // to see what's affected.\n if (hasConflicts) {\n const headerText = options.force\n ? 'Conflicts (will be force-overwritten on remote):'\n : 'Conflicts (will be SKIPPED \u2014 pull first to resolve):';\n console.log(chalk.red.bold(headerText));\n for (const conflict of status.conflicts) {\n console.log(chalk.red(` ! ${conflict.filePath}`));\n console.log(chalk.dim(` ${conflict.description}`));\n }\n }\n\n if (appStatus.newLocal.length > 0) {\n console.log(chalk.green('New apps:'));\n for (const app of appStatus.newLocal) console.log(chalk.green(` + ${app}`));\n }\n if (appStatus.modified.length > 0) {\n console.log(chalk.yellow('Modified apps:'));\n for (const app of appStatus.modified) console.log(chalk.yellow(` ~ ${app}`));\n }\n\n // Pre-flight in the preview, BEFORE the confirm prompt. README\n // promises rejections show up in the plan; running pre-flight\n // only inside syncService.push() pushed them to AFTER the user\n // had already said \"yes\". Cost: every upload candidate is read\n // twice (preview + push). For big tenants this is measurable\n // but predictability is the user-visible contract \u2014 they'd\n // rather know about a 256-char-name reject before pressing\n // ENTER on a 200-file mirror push.\n const previewCandidates = [...filesToUpload, ...filesToRecreate, ...filesToOverwrite];\n const previewRejections = previewPushPlan(filesDir, previewCandidates);\n if (previewRejections.length > 0) {\n console.log();\n console.log(chalk.red.bold('Files that pre-flight will reject (skipped from upload):'));\n for (const r of previewRejections) {\n console.log(chalk.red(` \u2717 ${r.filePath}`));\n console.log(chalk.dim(` ${r.detail}`));\n if (r.hint) console.log(chalk.dim(` ${r.hint}`));\n }\n }\n\n console.log();\n\n // filesToUpload already includes filesToRecreate under --force,\n // so don't double-count.\n const totalChanges =\n filesToUpload.length +\n filesToDelete.length +\n remoteOnlyFiles.length +\n appStatus.newLocal.length +\n appStatus.modified.length;\n\n // Step 3: Confirm. --force always confirms (cannot be skipped\n // with -y) because mirror mode includes destructive deletes.\n //\n // Spell out every bucket in the prompt itself, not just the\n // total. A 200-overwrite + 2-delete mirror with the old\n // \"Mirror N change(s) (including K remote deletion(s))\"\n // headline read like \"small change\" \u2014 the eye-catching K\n // hid the bigger blast radius. The plan above the prompt is\n // already explicit; the prompt-line should match it.\n const confirmMessage = options.force\n ? `Mirror to ${tenant}: ${remoteOnlyFiles.length} remote deletion(s), ` +\n `${filesToOverwrite.length} drift overwrite(s), ${filesToRecreate.length} recreation(s), ` +\n `${status.addedLocally.length} new upload(s), ${status.modifiedLocally.length} local edit(s), ` +\n `${filesToDelete.length} local-rm deletion(s). This is destructive.`\n : `Push ${totalChanges} change(s) to ${tenant}?`;\n\n if (options.force || !options.yes) {\n const confirm = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'proceed',\n message: confirmMessage,\n default: !options.force,\n },\n ]);\n\n if (!confirm.proceed) {\n logger.info('Push cancelled.');\n return;\n }\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 // Mirror the service's actual return type so every field is\n // present and non-optional. The earlier hand-rolled inline\n // type marked conflicts/rejected/failed as optional, which\n // forced `?.length ?? 0` defensiveness at every read site\n // even though the service always returns those arrays.\n let result: Awaited<ReturnType<SyncService['push']>> = {\n uploaded: [],\n updated: [],\n deleted: [],\n unchanged: [],\n conflicts: [],\n rejected: [],\n failed: [],\n };\n\n if (hasFileChanges) {\n logger.info(`Pushing files to ${tenant}...`);\n // Pass syncFilterOptions so mirror-mode deletes honour\n // --include-folder / --include-ext scope. Without this\n // the preview's \"remote-only DELETE\" line and the actual\n // mirror step diverged for non-default extensions.\n //\n // Hand `status.remoteHashes` (populated when deep status\n // ran above, i.e. under --force) into service.push so\n // the candidate-content fetch skips files we already\n // have hashes for. Without it, --force re-downloaded\n // every remote file a second time inside push().\n result = await syncService.push({\n force: options.force,\n mirror: options.force,\n ...syncFilterOptions,\n precomputedRemoteHashes: status.remoteHashes,\n });\n\n console.log();\n\n if (result.rejected.length > 0) {\n console.log(chalk.red.bold('Files skipped (backend would reject):'));\n renderRejections(result.rejected);\n }\n\n if (result.conflicts.length > 0) {\n console.log(chalk.red.bold(`${result.conflicts.length} conflict(s) detected:`));\n for (const conflict of result.conflicts) {\n console.log(chalk.red(` ! ${conflict.filePath}`));\n console.log(chalk.dim(` ${conflict.description}`));\n }\n console.log();\n logger.dim(`Resolve conflicts by pulling first: farseer pull ${tenant}`);\n logger.dim('Or use --force to push anyway (overwrites remote and mirrors deletions).');\n console.log();\n }\n\n if (result.uploaded.length > 0) {\n console.log(chalk.green('Uploaded files (new):'));\n for (const file of result.uploaded) console.log(chalk.green(` + ${file}`));\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) console.log(chalk.yellow(` M ${file}`));\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) console.log(chalk.red(` - ${file}`));\n console.log();\n }\n\n if (result.failed.length > 0) {\n // Per-file errors that the backend rejected mid-flight\n // (5xx, validation we couldn't pre-flight, etc.).\n // Distinct from `rejected` (pre-flight) \u2014 these\n // already attempted the call. State for files that\n // succeeded before the failure has been saved.\n console.log(chalk.red.bold(`${result.failed.length} file(s) failed during push:`));\n for (const failure of result.failed) {\n console.log(chalk.red(` ! ${failure.filePath} (${failure.operation})`));\n console.log(chalk.dim(` ${failure.reason}`));\n }\n console.log();\n }\n }\n\n let appResult = {\n created: [] as string[],\n updated: [] as string[],\n deleted: [] as string[],\n unchanged: [] as string[],\n };\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) console.log(chalk.green(` + ${app}`));\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) console.log(chalk.yellow(` ~ ${app}`));\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) console.log(chalk.red(` - ${app}`));\n console.log();\n }\n }\n\n console.log();\n const fileSideEffects = result.uploaded.length + result.updated.length + result.deleted.length;\n const appSideEffects = appResult.created.length + appResult.updated.length + appResult.deleted.length;\n const conflictCount = result.conflicts.length;\n const rejectedCount = result.rejected.length;\n const failedCount = result.failed.length;\n if (fileSideEffects + appSideEffects === 0 && (conflictCount > 0 || rejectedCount > 0)) {\n // Nothing was actually pushed (every candidate hit a\n // conflict or pre-flight rejection). Surface as a\n // warning + EXIT 1 so CI and shell scripts can branch\n // \u2014 the bare \"Push complete!\" line was misleading.\n if (rejectedCount > 0 && conflictCount === 0) {\n logger.warning(`Push did nothing \u2014 ${rejectedCount} file(s) rejected by pre-flight.`);\n logger.dim('Fix the issues listed above and re-run `farseer push`.');\n } else if (conflictCount > 0 && rejectedCount === 0) {\n logger.warning(`Push did nothing \u2014 ${conflictCount} conflict(s) blocked the upload.`);\n logger.dim(`Resolve via 'farseer pull ${tenant}' or rerun with --force.`);\n } else {\n logger.warning(\n `Push did nothing \u2014 ${rejectedCount} file(s) rejected and ${conflictCount} conflict(s) blocked the upload.`,\n );\n }\n process.exit(1);\n }\n logger.success('Push complete!');\n logger.dim(`Files: +${result.uploaded.length} ~${result.updated.length} -${result.deleted.length}`);\n logger.dim(\n `Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length}`,\n );\n if (rejectedCount > 0 || failedCount > 0) {\n // Partial success: at least some side effects landed\n // but some candidates were skipped (rejected pre-flight)\n // or failed mid-push (network/backend error). EXIT 1\n // (not 2 \u2014 the previous split was undocumented and most\n // CI scripts treat any non-zero as failure anyway).\n if (rejectedCount > 0 && failedCount > 0) {\n logger.warning(\n `${rejectedCount} file(s) skipped pre-flight, ${failedCount} failed mid-push \u2014 see above and rerun.`,\n );\n } else if (rejectedCount > 0) {\n logger.warning(`${rejectedCount} file(s) skipped (see above) \u2014 fix and rerun.`);\n } else {\n logger.warning(`${failedCount} file(s) failed during push (see above) \u2014 rerun to retry.`);\n }\n process.exit(1);\n }\n } catch (error) {\n fileLogger.error('push', error, { tenant, organisation });\n logger.error('Push failed.');\n logger.error(await formatClientError(error));\n const logPath = fileLogger.getLogPath();\n if (logPath) {\n logger.dim(`Debug log: ${logPath}`);\n }\n process.exit(1);\n }\n });\n}\n\n/**\n * Translate a SyncStatus + force flag into the buckets the push command\n * actually acts on. Pure: takes a status, returns lists. Lives at the\n * top level (not inside the action closure) so it can be exported and\n * unit-tested directly \u2014 the status engine has its own coverage, and\n * before this extraction the bucket logic was inline in the action and\n * only reachable via mocking commander + inquirer + fs.\n *\n * Default push: upload the added/modified locally, delete the locally-\n * removed. Remote-side activity is not in scope (drift check refuses\n * before we reach this).\n *\n * Force push (mirror): also re-upload files the remote has lost\n * (deletedRemotely \u2192 recreate) and files the remote has drifted away\n * from (modifiedRemotely \u2192 local wins, overwrite). Plus mirror-deletes\n * remote files that have no local counterpart (addedRemotely).\n */\nexport function buildPushPlan(\n status: SyncStatus,\n options: { force: boolean },\n): {\n filesToUpload: string[];\n filesToDelete: string[];\n remoteOnlyFiles: string[];\n filesToRecreate: string[];\n filesToOverwrite: string[];\n} {\n return {\n filesToUpload: [\n ...status.addedLocally,\n ...status.modifiedLocally,\n ...(options.force ? status.deletedRemotely : []),\n ...(options.force ? status.modifiedRemotely : []),\n ],\n filesToDelete: [...status.deletedLocally],\n remoteOnlyFiles: options.force ? [...status.addedRemotely] : [],\n filesToRecreate: options.force ? [...status.deletedRemotely] : [],\n filesToOverwrite: options.force ? [...status.modifiedRemotely] : [],\n };\n}\n\nfunction renderRejections(rejections: ValidationFailure[]): void {\n for (const r of rejections) {\n console.log(chalk.red(` x ${r.filePath}`));\n console.log(chalk.dim(` ${r.detail}`));\n if (r.hint) console.log(chalk.dim(` ${r.hint}`));\n }\n console.log();\n}\n\n/**\n * Run pre-flight against a list of upload candidates and return only the\n * rejections so the preview can show them BEFORE the confirm prompt. We\n * read each file once here; syncService.push() reads them again at upload\n * time. The duplicate read is the price of putting rejections into the\n * confirmation plan \u2014 without this, the user only learned about rejected\n * files after pressing ENTER, which contradicted the README.\n *\n * Files that fail to read (permission errors, race with deletion) get\n * skipped \u2014 push() will surface that as a real failure if the file\n * actually still mattered.\n */\nfunction previewPushPlan(filesDir: string, candidates: string[]): ValidationFailure[] {\n const validationInputs: { filePath: string; size: number; content: Buffer }[] = [];\n for (const filePath of candidates) {\n try {\n const fullPath = safeResolveWithinBase(filesDir, filePath);\n const content = fs.readFileSync(fullPath);\n validationInputs.push({ filePath, size: content.length, content });\n } catch {\n // Race: file disappeared between getStatus and the preview\n // read, or unreadable. Push() will see the same condition\n // and surface a real error. Don't pretend to know more here.\n continue;\n }\n }\n const { rejected } = partitionForUpload(validationInputs);\n return rejected;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,sBAAqB;AACrB,oBAAuB;AACvB,wBAA2B;AAC3B,4BAAgF;AAChF,yBAA4B;AAC5B,4BAA+B;AAC/B,qBAAsF;AACtF,4BAAkC;AAClC,4BAAsD;AACtD,wBAAmD;AAEnD,SAAoB;AA4Bb,SAAS,oBAAoB,SAAwB;AACxD,UACK,QAAQ,qBAAqB,EAC7B;AAAA,IACG;AAAA,EACJ,EACC;AAAA,IACG;AAAA,IACA;AAAA,EACJ,EACC,OAAO,aAAa,6EAA6E,EACjG,OAAO,uBAAuB,6CAA6C,iCAAe,CAAC,CAAC,EAC5F,OAAO,6BAA6B,4CAA4C,iCAAe,CAAC,CAAC,EACjG,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,eAAW,kCAAkB,MAAM;AAEzC,QAAI,CAAC,GAAG,WAAW,QAAQ,GAAG;AAC1B,2BAAO,MAAM,wCAAwC,MAAM,SAAS;AACpE,2BAAO,IAAI,6DAA6D;AACxE,cAAQ,KAAK,CAAC;AAAA,IAClB;AAEA,UAAM,cAAc,IAAI,+BAAY,QAAQ,aAAa,MAAM;AAC/D,UAAM,wBAAoB,uCAAoB,QAAQ,UAAU;AAChE,UAAM,iBAAiB,QAAQ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tD;AACA,UAAQ,IAAI;AAChB;AAcA,SAAS,gBAAgB,UAAkB,YAA2C;AAClF,QAAM,mBAA0E,CAAC;AACjF,aAAW,YAAY,YAAY;AAC/B,QAAI;AACA,YAAM,eAAW,sCAAsB,UAAU,QAAQ;AACzD,YAAM,UAAU,GAAG,aAAa,QAAQ;AACxC,uBAAiB,KAAK,EAAE,UAAU,MAAM,QAAQ,QAAQ,QAAQ,CAAC;AAAA,IACrE,QAAQ;AAIJ;AAAA,IACJ;AAAA,EACJ;AACA,QAAM,EAAE,SAAS,QAAI,0CAAmB,gBAAgB;AACxD,SAAO;AACX;",
|
|
6
6
|
"names": ["chalk", "inquirer"]
|
|
7
7
|
}
|
package/dist/commands/run.js
CHANGED
|
@@ -59,49 +59,50 @@ function findScriptRecursively(baseDir, scriptName) {
|
|
|
59
59
|
};
|
|
60
60
|
return search(baseDir);
|
|
61
61
|
}
|
|
62
|
-
async function getRunCredentials(tenant,
|
|
62
|
+
async function getRunCredentials(organisation, tenant, tenantIdOverride) {
|
|
63
63
|
const credential = (0, import_configService.getCredential)(tenant);
|
|
64
64
|
if (credential) {
|
|
65
65
|
return {
|
|
66
|
-
tenantId: credential.tenantId,
|
|
66
|
+
tenantId: tenantIdOverride || credential.tenantId,
|
|
67
67
|
apiKey: credential.apiKey,
|
|
68
68
|
basePath: credential.basePath
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
const auth = (0, import_configService.getUserAuth)();
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
if (auth) {
|
|
73
|
+
if (!(0, import_configService.isUserAuthValid)()) {
|
|
74
|
+
import_logger.logger.dim("Token expired, refreshing...");
|
|
75
|
+
const refreshed = await (0, import_farseerService.refreshAccessToken)(auth.refreshToken, auth.realm || "master");
|
|
76
|
+
if (refreshed) {
|
|
77
|
+
(0, import_configService.setUserAuth)({
|
|
78
|
+
accessToken: refreshed.accessToken,
|
|
79
|
+
refreshToken: refreshed.refreshToken,
|
|
80
|
+
expiresAt: new Date(Date.now() + refreshed.expiresIn * 1e3).toISOString(),
|
|
81
|
+
realm: auth.realm
|
|
82
|
+
});
|
|
83
|
+
import_logger.logger.success("Token refreshed");
|
|
84
|
+
} else {
|
|
85
|
+
import_logger.logger.warning("Could not refresh token. Please login again with: farseer login");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const updatedAuth = (0, import_configService.getUserAuth)();
|
|
89
|
+
if (updatedAuth && (0, import_configService.isUserAuthValid)()) {
|
|
90
|
+
return {
|
|
91
|
+
tenantId: tenantIdOverride || tenant,
|
|
92
|
+
accessToken: updatedAuth.accessToken,
|
|
93
|
+
basePath: (0, import_configService.generateBasePath)(organisation)
|
|
94
|
+
};
|
|
81
95
|
}
|
|
82
|
-
(0, import_configService.setUserAuth)({
|
|
83
|
-
accessToken: refreshed.accessToken,
|
|
84
|
-
refreshToken: refreshed.refreshToken,
|
|
85
|
-
expiresAt: new Date(Date.now() + refreshed.expiresIn * 1e3).toISOString(),
|
|
86
|
-
realm: auth.realm
|
|
87
|
-
});
|
|
88
|
-
import_logger.logger.success("Token refreshed");
|
|
89
96
|
}
|
|
90
|
-
|
|
91
|
-
if (!updatedAuth) return null;
|
|
92
|
-
return {
|
|
93
|
-
tenantId: tenantId || tenant,
|
|
94
|
-
accessToken: updatedAuth.accessToken,
|
|
95
|
-
basePath: (0, import_configService.generateBasePath)(tenant)
|
|
96
|
-
};
|
|
97
|
+
return null;
|
|
97
98
|
}
|
|
98
99
|
function collectArgs(value, previous) {
|
|
99
100
|
return previous.concat([value]);
|
|
100
101
|
}
|
|
101
102
|
function registerRunCommand(program) {
|
|
102
103
|
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) => {
|
|
103
|
-
const { tenant, appName } = (0, import_helpers.parseAppArgs)(args);
|
|
104
|
-
const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(
|
|
104
|
+
const { organisation, tenant, appName } = (0, import_helpers.parseAppArgs)(args);
|
|
105
|
+
const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
|
|
105
106
|
if (!clientResult) {
|
|
106
107
|
(0, import_farseerFactory.showLoginPrompt)(tenant);
|
|
107
108
|
process.exit(1);
|
|
@@ -129,7 +130,7 @@ function registerRunCommand(program) {
|
|
|
129
130
|
if (scriptName.toLowerCase().startsWith("scripts/")) {
|
|
130
131
|
scriptName = scriptName.substring("scripts/".length);
|
|
131
132
|
}
|
|
132
|
-
const credentials = await getRunCredentials(tenant, options.tenantId);
|
|
133
|
+
const credentials = await getRunCredentials(organisation, tenant, options.tenantId);
|
|
133
134
|
if (!credentials) {
|
|
134
135
|
(0, import_farseerFactory.showLoginPrompt)(tenant);
|
|
135
136
|
process.exit(1);
|
|
@@ -265,9 +266,9 @@ function registerRunCommand(program) {
|
|
|
265
266
|
});
|
|
266
267
|
});
|
|
267
268
|
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) => {
|
|
268
|
-
const { tenant, appName } = (0, import_helpers.parseAppArgs)(args);
|
|
269
|
+
const { organisation, tenant, appName } = (0, import_helpers.parseAppArgs)(args);
|
|
269
270
|
let script = appName;
|
|
270
|
-
const credentials = await getRunCredentials(tenant, options.tenantId);
|
|
271
|
+
const credentials = await getRunCredentials(organisation, tenant, options.tenantId);
|
|
271
272
|
if (!credentials) {
|
|
272
273
|
(0, import_farseerFactory.showLoginPrompt)(tenant);
|
|
273
274
|
process.exit(1);
|