@uniformdev/cli 17.7.1-alpha.34 → 18.0.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/dist/index.mjs CHANGED
@@ -1,3 +1,175 @@
1
1
  #!/usr/bin/env node
2
- import{a as l,b,c as v}from"./chunk-LPA4W6MO.mjs";import R from"yargs";import I from"yargs";import h from"yargs";var r=b(v());import{writeFile as C}from"fs";import _ from"isomorphic-unfetch";import{exit as a}from"process";var u="https://uniform.app";var A={command:"download [output]",describe:"Download intent manifest",builder:e=>{var o;return e.option("apiKey",{alias:"k",demandOption:!0,string:!0,default:process.env.UNIFORM_API_KEY,describe:"Uniform API key to use. Defaults to UNIFORM_API_KEY env if set."}).option("project",{describe:"Uniform project ID. Defaults to UOPT_CLI_PROJECT_ID or UNIFORM_PROJECT_ID env. Supports dotenv.",default:(o=process.env.UOPT_CLI_PROJECT_ID)!=null?o:process.env.UNIFORM_PROJECT_ID,type:"string",alias:["p"]}).option("preview",{describe:"If set, fetches the unpublished preview manifest (assuming your API key has permission)",default:!1,type:"boolean",alias:["d"]}).option("output",{string:!0,alias:"o",default:process.env.UNIFORM_MANIFEST_PATH,describe:"Path to write manifest to. Defaults to UNIFORM_MANIFEST_PATH env if set."})},handler:async({apiKey:e,output:o,project:s,preview:m})=>{/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i.test(e)?console.error(r.default.yellow("WARNING: you appear to be using a deprecated type of API key. Keys like this will stop working soon; please create new keys on uniform.app.")):s||(console.error(r.default.red("You must specify the project ID")),a(1));let U=M(),d=new URLSearchParams;s&&d.set("projectId",s),m&&d.set("preview","true");let i=`${U}api/v1/manifest?${d.toString()}`,t;try{if(t=await _(i,{headers:{"x-api-key":e}}),!t.ok)throw t.status===403?`The API key ${e} had no published data. This means it is either incorrectly entered, or intents have not been published since creating the API key.`:`${t.status} ${t.statusText}, content ${await t.text()}`}catch(n){console.error(r.default.red(`\u26A0 Error fetching intent manifest ${i}`)),console.error(r.default.gray(` \u2757 ${n}`)),a(1)}let p;try{p=await t.json()}catch(n){console.error(r.default.red(r.default.red(`\u26A0 Error parsing intent manifest ${i}`))),console.error(r.default.gray(` \u2757 ${n}`)),console.error(`Response: ${await t.text()}`),a(1)}let f=JSON.stringify(p,null,2);o?C(o,f,n=>{n&&(console.error(`Error writing file to ${o}
3
- `,n),a(1)),console.log(r.default.green(`\u2705 ${o} has been updated from ${i}`))}):console.log(f)}},M=()=>{let e=process.env.UNIFORM_CLI_BASE_URL||u;return e.endsWith("/")||(e+="/"),e},y=A;var O={command:"manifest <command>",describe:"Intent manifest commands",builder:()=>h.command(y),handler:()=>h.showHelp()},g=O;var P={command:"optimize <command>",aliases:["opt"],describe:"Uniform Optimize commands",builder:()=>I.command(g),handler:()=>I.showHelp()},w=P;l("dotenv").config();var T=["@uniformdev/canvas/cli","@uniformdev/context/cli","@uniformdev/project-map/cli"],c=R.scriptName("uniform");T.flatMap(e=>{try{let o=l(e).uniformCLI.commands;(Array.isArray(o)?o:[]).forEach(m=>{c=c.command(m)})}catch{}});c.command(w).demandCommand(1,"").strict().help().argv;
2
+ import {
3
+ __require,
4
+ __toESM,
5
+ require_source
6
+ } from "./chunk-IRPO3X2Q.mjs";
7
+
8
+ // src/index.ts
9
+ import yargs3 from "yargs";
10
+
11
+ // src/commands/optimize.ts
12
+ import yargs2 from "yargs";
13
+
14
+ // src/commands/optimize/manifest.ts
15
+ import yargs from "yargs";
16
+
17
+ // src/commands/optimize/manifest/download.ts
18
+ var import_chalk = __toESM(require_source());
19
+ import { writeFile } from "fs";
20
+ import fetch from "isomorphic-unfetch";
21
+ import { exit } from "process";
22
+
23
+ // src/constants.ts
24
+ var UniformBaseUrl = "https://uniform.app";
25
+
26
+ // src/commands/optimize/manifest/download.ts
27
+ var module = {
28
+ command: "download [output]",
29
+ describe: "Download intent manifest",
30
+ builder: (yargs4) => {
31
+ var _a;
32
+ return yargs4.option("apiKey", {
33
+ alias: "k",
34
+ demandOption: true,
35
+ string: true,
36
+ default: process.env.UNIFORM_API_KEY,
37
+ describe: "Uniform API key to use. Defaults to UNIFORM_API_KEY env if set."
38
+ }).option("project", {
39
+ describe: "Uniform project ID. Defaults to UOPT_CLI_PROJECT_ID or UNIFORM_PROJECT_ID env. Supports dotenv.",
40
+ default: (_a = process.env.UOPT_CLI_PROJECT_ID) != null ? _a : process.env.UNIFORM_PROJECT_ID,
41
+ type: "string",
42
+ alias: ["p"]
43
+ }).option("preview", {
44
+ describe: "If set, fetches the unpublished preview manifest (assuming your API key has permission)",
45
+ default: false,
46
+ type: "boolean",
47
+ alias: ["d"]
48
+ }).option("output", {
49
+ string: true,
50
+ alias: "o",
51
+ default: process.env.UNIFORM_MANIFEST_PATH,
52
+ describe: "Path to write manifest to. Defaults to UNIFORM_MANIFEST_PATH env if set."
53
+ });
54
+ },
55
+ handler: async ({ apiKey, output, project, preview }) => {
56
+ const isLegacyApiKey = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i.test(
57
+ apiKey
58
+ );
59
+ if (isLegacyApiKey) {
60
+ console.error(
61
+ import_chalk.default.yellow(
62
+ "WARNING: you appear to be using a deprecated type of API key. Keys like this will stop working soon; please create new keys on uniform.app."
63
+ )
64
+ );
65
+ } else if (!project) {
66
+ console.error(import_chalk.default.red("You must specify the project ID"));
67
+ exit(1);
68
+ }
69
+ const baseUrl = resolveBaseUrl();
70
+ const qs = new URLSearchParams();
71
+ if (project) {
72
+ qs.set("projectId", project);
73
+ }
74
+ if (preview) {
75
+ qs.set("preview", "true");
76
+ }
77
+ const manifestUrl = `${baseUrl}api/v1/manifest?${qs.toString()}`;
78
+ let fetchResponse = void 0;
79
+ try {
80
+ fetchResponse = await fetch(manifestUrl, {
81
+ headers: {
82
+ "x-api-key": apiKey
83
+ }
84
+ });
85
+ if (!fetchResponse.ok) {
86
+ if (fetchResponse.status === 403) {
87
+ throw `The API key ${apiKey} had no published data. This means it is either incorrectly entered, or intents have not been published since creating the API key.`;
88
+ }
89
+ throw `${fetchResponse.status} ${fetchResponse.statusText}, content ${await fetchResponse.text()}`;
90
+ }
91
+ } catch (e) {
92
+ console.error(import_chalk.default.red(`\u26A0 Error fetching intent manifest ${manifestUrl}`));
93
+ console.error(import_chalk.default.gray(` \u2757 ${e}`));
94
+ exit(1);
95
+ }
96
+ let json;
97
+ try {
98
+ json = await fetchResponse.json();
99
+ } catch (e) {
100
+ console.error(import_chalk.default.red(import_chalk.default.red(`\u26A0 Error parsing intent manifest ${manifestUrl}`)));
101
+ console.error(import_chalk.default.gray(` \u2757 ${e}`));
102
+ console.error(`Response: ${await fetchResponse.text()}`);
103
+ exit(1);
104
+ }
105
+ const text = JSON.stringify(json, null, 2);
106
+ if (output) {
107
+ writeFile(output, text, (error) => {
108
+ if (error) {
109
+ console.error(`Error writing file to ${output}
110
+ `, error);
111
+ exit(1);
112
+ }
113
+ console.log(import_chalk.default.green(`\u2705 ${output} has been updated from ${manifestUrl}`));
114
+ });
115
+ } else {
116
+ console.log(text);
117
+ }
118
+ }
119
+ };
120
+ var resolveBaseUrl = () => {
121
+ let baseUrl = process.env.UNIFORM_CLI_BASE_URL || UniformBaseUrl;
122
+ if (!baseUrl.endsWith("/")) {
123
+ baseUrl += "/";
124
+ }
125
+ return baseUrl;
126
+ };
127
+ var download_default = module;
128
+
129
+ // src/commands/optimize/manifest.ts
130
+ var module2 = {
131
+ command: "manifest <command>",
132
+ describe: "Intent manifest commands",
133
+ builder: () => {
134
+ return yargs.command(download_default);
135
+ },
136
+ handler: () => {
137
+ return yargs.showHelp();
138
+ }
139
+ };
140
+ var manifest_default = module2;
141
+
142
+ // src/commands/optimize.ts
143
+ var command = {
144
+ command: "optimize <command>",
145
+ aliases: ["opt"],
146
+ describe: "Uniform Optimize commands",
147
+ builder: () => {
148
+ return yargs2.command(manifest_default);
149
+ },
150
+ handler: () => {
151
+ return yargs2.showHelp();
152
+ }
153
+ };
154
+ var optimize_default = command;
155
+
156
+ // src/index.ts
157
+ __require("dotenv").config();
158
+ var plugins = [
159
+ "@uniformdev/canvas/cli",
160
+ "@uniformdev/context/cli",
161
+ "@uniformdev/project-map/cli",
162
+ "@uniformdev/uniform-new"
163
+ ];
164
+ var yarggery = yargs3.scriptName("uniform");
165
+ plugins.flatMap((plugin) => {
166
+ try {
167
+ const commands = __require(plugin).uniformCLI.commands;
168
+ const commandsToAdd = Array.isArray(commands) ? commands : [];
169
+ commandsToAdd.forEach((command2) => {
170
+ yarggery = yarggery.command(command2);
171
+ });
172
+ } catch (e) {
173
+ }
174
+ });
175
+ yarggery.command(optimize_default).demandCommand(1, "").strict().help().argv;
@@ -1,7 +1,7 @@
1
1
  import { Change } from 'diff';
2
2
  import { Argv } from 'yargs';
3
3
 
4
- declare type SyncEngineLogOptions = {
4
+ type SyncEngineLogOptions = {
5
5
  id: string;
6
6
  providerId: string;
7
7
  displayName: string;
@@ -9,7 +9,7 @@ declare type SyncEngineLogOptions = {
9
9
  whatIf: boolean;
10
10
  diff: Change[];
11
11
  };
12
- declare type SyncEngineObject<TObject> = {
12
+ type SyncEngineObject<TObject> = {
13
13
  /** Unique ID that is identical across all providers */
14
14
  id: string;
15
15
  /** Provider specific ID. Value is provided to deleteObject() function (always the provider ID from the same provider that issued it). */
@@ -19,7 +19,7 @@ declare type SyncEngineObject<TObject> = {
19
19
  /** The object being synced. */
20
20
  object: TObject;
21
21
  };
22
- declare type SyncEngineDataSource<TObject> = {
22
+ type SyncEngineDataSource<TObject> = {
23
23
  /** The objects to sync. */
24
24
  objects: AsyncIterable<SyncEngineObject<TObject>>;
25
25
  /**
@@ -39,7 +39,7 @@ declare type SyncEngineDataSource<TObject> = {
39
39
  */
40
40
  onSyncComplete?: (isTarget: boolean) => Promise<void>;
41
41
  };
42
- declare type SyncEngineOptions<TObject> = {
42
+ type SyncEngineOptions<TObject> = {
43
43
  source: SyncEngineDataSource<TObject>;
44
44
  target: SyncEngineDataSource<TObject>;
45
45
  compareContents?: (source: SyncEngineObject<TObject>, target: SyncEngineObject<TObject>) => boolean;
@@ -55,7 +55,7 @@ declare class SyncEngineError<TObject> extends Error {
55
55
  constructor(innerError: unknown, sourceObject: SyncEngineObject<TObject>);
56
56
  }
57
57
 
58
- declare type CreateArraySyncEngineDataSourceOptions<TObject> = {
58
+ type CreateArraySyncEngineDataSourceOptions<TObject> = {
59
59
  objects: Array<TObject>;
60
60
  selectIdentifier: (object: TObject) => string;
61
61
  selectDisplayName?: (object: TObject) => string;
@@ -65,7 +65,7 @@ declare function createArraySyncEngineDataSource<TObject>({ objects, selectIdent
65
65
  extractCurrent: () => Array<TObject>;
66
66
  }>;
67
67
 
68
- declare type CreateFileSyncEngineDataSourceOptions<TObject> = {
68
+ type CreateFileSyncEngineDataSourceOptions<TObject> = {
69
69
  directory: string;
70
70
  selectIdentifier: (object: TObject) => string;
71
71
  selectDisplayName?: (object: TObject) => string;
@@ -74,36 +74,36 @@ declare type CreateFileSyncEngineDataSourceOptions<TObject> = {
74
74
  };
75
75
  declare function createFileSyncEngineDataSource<TObject>({ directory, format, selectIdentifier, selectDisplayName, selectFilename, }: CreateFileSyncEngineDataSourceOptions<TObject>): Promise<SyncEngineDataSource<TObject>>;
76
76
 
77
- declare type UniformPackage = {
77
+ type UniformPackage = {
78
78
  [key: string]: unknown;
79
79
  };
80
80
  declare function readUniformPackage(filename: string, assertExists: boolean): UniformPackage;
81
81
  declare function writeUniformPackage(filename: string, packageContents: UniformPackage): void;
82
82
 
83
- declare type DiffMode = 'off' | 'on' | 'update';
83
+ type DiffMode = 'off' | 'on' | 'update';
84
84
  declare function createSyncEngineConsoleLogger(options?: {
85
85
  diffMode?: DiffMode;
86
86
  indent?: string;
87
87
  prefix?: string;
88
88
  }): ({ action, displayName, whatIf, diff }: SyncEngineLogOptions) => void;
89
89
 
90
- declare type ApiArgs = {
90
+ type ApiArgs = {
91
91
  apiKey: string;
92
92
  apiHost: string;
93
93
  proxy?: string;
94
94
  };
95
95
  declare function withApiOptions<T>(yargs: Argv<T>): Argv<T>;
96
96
  declare function nodeFetchProxy(proxy: string | undefined): typeof fetch;
97
- declare type ProjectArgs = {
97
+ type ProjectArgs = {
98
98
  project: string;
99
99
  };
100
100
  declare function withProjectOptions<T>(yargs: Argv<T>): Argv<T>;
101
- declare type FormatArgs = {
101
+ type FormatArgs = {
102
102
  format: 'json' | 'yaml';
103
103
  filename?: string;
104
104
  };
105
105
  declare function withFormatOptions<T>(yargs: Argv<T>): Argv<T>;
106
- declare type DiffArgs = {
106
+ type DiffArgs = {
107
107
  diff: DiffMode;
108
108
  };
109
109
  declare function withDiffOptions<T>(yargs: Argv<T>): Argv<T>;