@trayai/tray-sync-cli 1.0.9 → 1.0.11

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.
@@ -0,0 +1,4 @@
1
+ export async function rollbackProject(client, projectId, versionNumber) {
2
+ await client.request("POST", `/v1/projects/${projectId}/rollbacks/versions/${versionNumber}`);
3
+ }
4
+ //# sourceMappingURL=project.js.map
@@ -1,3 +1,5 @@
1
1
  import { Command } from "commander";
2
+ import { projectCommand } from "./project.js";
2
3
  export const apiCommand = new Command("api").description("Direct, authenticated access to the Tray API");
4
+ apiCommand.addCommand(projectCommand);
3
5
  //# sourceMappingURL=api.js.map
@@ -0,0 +1,47 @@
1
+ import { Command, InvalidArgumentError } from "commander";
2
+ import { rollbackProject } from "../../api/resources/project.js";
3
+ import { isUuid } from "../../lib/uuid.js";
4
+ import { parseVersionNumber } from "../../lib/versionNumber.js";
5
+ import { OutputFormats } from "../../lib/outputFormat.js";
6
+ import { printProjectRollbackResult } from "../../views/api/project.v2.js";
7
+ import { printConfirmationJson } from "../../views/api/shared.js";
8
+ import { addCommonApiOptions, apiClientFor, realDeps, runApiAction, } from "./shared.js";
9
+ function parseProjectId(value) {
10
+ if (!isUuid(value)) {
11
+ throw new InvalidArgumentError("project id must be a UUID");
12
+ }
13
+ return value;
14
+ }
15
+ export async function runProjectRollback(deps, options) {
16
+ const client = apiClientFor(deps, options);
17
+ await rollbackProject(client, options.projectId, options.versionNumber);
18
+ if (options.format === OutputFormats.JSON) {
19
+ printConfirmationJson(deps.stdout, {
20
+ projectId: options.projectId,
21
+ versionNumber: options.versionNumber,
22
+ rolledBack: true,
23
+ });
24
+ }
25
+ else {
26
+ printProjectRollbackResult(deps.stdout, options.projectId, options.versionNumber);
27
+ }
28
+ return 0;
29
+ }
30
+ export const projectCommand = new Command("project").description("Manage projects");
31
+ const versionCommand = new Command("version").description("Manage project versions");
32
+ projectCommand.addCommand(versionCommand);
33
+ addCommonApiOptions(versionCommand
34
+ .command("rollback")
35
+ .description("Roll back a project to a specific version")
36
+ .argument("<project-id>", "Tray project UUID", parseProjectId)
37
+ .requiredOption("--version-number <major.minor>", "target version number", parseVersionNumber)).action(async (projectId, opts) => {
38
+ const deps = realDeps();
39
+ await runApiAction(deps, () => runProjectRollback(deps, {
40
+ projectId,
41
+ versionNumber: opts.versionNumber,
42
+ region: opts.region,
43
+ token: opts.token,
44
+ format: opts.format,
45
+ }));
46
+ });
47
+ //# sourceMappingURL=project.js.map
@@ -0,0 +1,35 @@
1
+ import { createTrayClientForRegion } from "../../api/trayClient.js";
2
+ import { resolveApiRegion, resolveApiToken } from "../../lib/apiAuth.js";
3
+ import { parseRegion } from "../../lib/regionParsing.js";
4
+ import { OutputFormats, parseFormat } from "../../lib/outputFormat.js";
5
+ import { FAILURE_ICON } from "../../views/icons.js";
6
+ export function realDeps() {
7
+ return {
8
+ env: process.env,
9
+ createClient: createTrayClientForRegion,
10
+ stdout: (line) => console.log(line),
11
+ stderr: (line) => console.error(line),
12
+ };
13
+ }
14
+ export function addCommonApiOptions(command) {
15
+ return command
16
+ .option("-r, --region <region>", "Tray region (falls back to TRAY_API_REGION)", parseRegion)
17
+ .option("-t, --token <token>", "Tray API token (falls back to TRAY_API_TOKEN)")
18
+ .option("--format <format>", "human or json", parseFormat, OutputFormats.HUMAN);
19
+ }
20
+ export async function runApiAction(deps, run) {
21
+ try {
22
+ process.exitCode = await run();
23
+ }
24
+ catch (err) {
25
+ const message = err instanceof Error ? err.message : String(err);
26
+ deps.stderr(`${FAILURE_ICON} ${message}`);
27
+ process.exitCode = 1;
28
+ }
29
+ }
30
+ export function apiClientFor(deps, options) {
31
+ const token = resolveApiToken({ tokenFlag: options.token, env: deps.env });
32
+ const region = resolveApiRegion({ regionFlag: options.region, env: deps.env });
33
+ return deps.createClient(region, token);
34
+ }
35
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1,6 @@
1
+ import ansis from "ansis";
2
+ import { SUCCESS_ICON } from "../icons.js";
3
+ export function printProjectRollbackResult(stdout, projectId, versionNumber) {
4
+ stdout(`${SUCCESS_ICON} Project ${ansis.bold(projectId)} rolled back to version ${ansis.bold(versionNumber)}.`);
5
+ }
6
+ //# sourceMappingURL=project.v2.js.map
@@ -0,0 +1,4 @@
1
+ export function printConfirmationJson(stdout, fields) {
2
+ stdout(JSON.stringify(fields, null, 2));
3
+ }
4
+ //# sourceMappingURL=shared.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayai/tray-sync-cli",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "CLI tool to clone Tray projects and related assets to a local directory, and promote them between Tray environments",
5
5
  "bin": {
6
6
  "tray": "dist/cli.js"