@xano/cli 0.0.8 → 0.0.10

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.
@@ -15,5 +15,7 @@ export default class EphemeralRunJob extends BaseCommand {
15
15
  run(): Promise<void>;
16
16
  private editFile;
17
17
  private readStdin;
18
+ private isUrl;
19
+ private fetchContent;
18
20
  private loadCredentials;
19
21
  }
@@ -16,7 +16,7 @@ export default class EphemeralRunJob extends BaseCommand {
16
16
  }),
17
17
  file: Flags.string({
18
18
  char: 'f',
19
- description: 'Path to file containing XanoScript code',
19
+ description: 'Path or URL to file containing XanoScript code',
20
20
  required: false,
21
21
  exclusive: ['stdin'],
22
22
  }),
@@ -43,7 +43,7 @@ export default class EphemeralRunJob extends BaseCommand {
43
43
  }),
44
44
  args: Flags.string({
45
45
  char: 'a',
46
- description: 'Path to JSON file containing input arguments',
46
+ description: 'Path or URL to JSON file containing input arguments',
47
47
  required: false,
48
48
  }),
49
49
  };
@@ -113,26 +113,20 @@ Job executed successfully!
113
113
  // Read XanoScript content
114
114
  let xanoscript;
115
115
  if (flags.file) {
116
- // Read from file
117
- let fileToRead = flags.file;
118
- // If edit flag is set, copy to temp file and open in editor
119
- if (flags.edit) {
120
- fileToRead = await this.editFile(flags.file);
121
- }
122
- try {
116
+ // If edit flag is set and source is not a URL, copy to temp file and open in editor
117
+ if (flags.edit && !this.isUrl(flags.file)) {
118
+ const fileToRead = await this.editFile(flags.file);
123
119
  xanoscript = fs.readFileSync(fileToRead, 'utf8');
124
- // Clean up temp file if it was created
125
- if (flags.edit && fileToRead !== flags.file) {
126
- try {
127
- fs.unlinkSync(fileToRead);
128
- }
129
- catch {
130
- // Ignore cleanup errors
131
- }
120
+ // Clean up temp file
121
+ try {
122
+ fs.unlinkSync(fileToRead);
123
+ }
124
+ catch {
125
+ // Ignore cleanup errors
132
126
  }
133
127
  }
134
- catch (error) {
135
- this.error(`Failed to read file '${fileToRead}': ${error}`);
128
+ else {
129
+ xanoscript = await this.fetchContent(flags.file);
136
130
  }
137
131
  }
138
132
  else if (flags.stdin) {
@@ -151,15 +145,15 @@ Job executed successfully!
151
145
  if (!xanoscript || xanoscript.trim().length === 0) {
152
146
  this.error('XanoScript content is empty');
153
147
  }
154
- // Load args from JSON file if provided
148
+ // Load args from JSON file or URL if provided
155
149
  let inputArgs;
156
150
  if (flags.args) {
157
151
  try {
158
- const argsContent = fs.readFileSync(flags.args, 'utf8');
152
+ const argsContent = await this.fetchContent(flags.args);
159
153
  inputArgs = JSON.parse(argsContent);
160
154
  }
161
155
  catch (error) {
162
- this.error(`Failed to read or parse args file '${flags.args}': ${error}`);
156
+ this.error(`Failed to read or parse args '${flags.args}': ${error}`);
163
157
  }
164
158
  }
165
159
  // Construct the API URL
@@ -294,6 +288,31 @@ Job executed successfully!
294
288
  process.stdin.resume();
295
289
  });
296
290
  }
291
+ isUrl(str) {
292
+ return str.startsWith('http://') || str.startsWith('https://');
293
+ }
294
+ async fetchContent(source) {
295
+ if (this.isUrl(source)) {
296
+ try {
297
+ const response = await fetch(source);
298
+ if (!response.ok) {
299
+ this.error(`Failed to fetch '${source}': ${response.status} ${response.statusText}`);
300
+ }
301
+ return await response.text();
302
+ }
303
+ catch (error) {
304
+ this.error(`Failed to fetch '${source}': ${error}`);
305
+ }
306
+ }
307
+ else {
308
+ try {
309
+ return fs.readFileSync(source, 'utf8');
310
+ }
311
+ catch (error) {
312
+ this.error(`Failed to read file '${source}': ${error}`);
313
+ }
314
+ }
315
+ }
297
316
  loadCredentials() {
298
317
  const configDir = path.join(os.homedir(), '.xano');
299
318
  const credentialsPath = path.join(configDir, 'credentials.yaml');
@@ -14,5 +14,7 @@ export default class EphemeralRunService extends BaseCommand {
14
14
  run(): Promise<void>;
15
15
  private editFile;
16
16
  private readStdin;
17
+ private isUrl;
18
+ private fetchContent;
17
19
  private loadCredentials;
18
20
  }
@@ -16,7 +16,7 @@ export default class EphemeralRunService extends BaseCommand {
16
16
  }),
17
17
  file: Flags.string({
18
18
  char: 'f',
19
- description: 'Path to file containing XanoScript code',
19
+ description: 'Path or URL to file containing XanoScript code',
20
20
  required: false,
21
21
  exclusive: ['stdin'],
22
22
  }),
@@ -103,26 +103,20 @@ Service created successfully!
103
103
  // Read XanoScript content
104
104
  let xanoscript;
105
105
  if (flags.file) {
106
- // Read from file
107
- let fileToRead = flags.file;
108
- // If edit flag is set, copy to temp file and open in editor
109
- if (flags.edit) {
110
- fileToRead = await this.editFile(flags.file);
111
- }
112
- try {
106
+ // If edit flag is set and source is not a URL, copy to temp file and open in editor
107
+ if (flags.edit && !this.isUrl(flags.file)) {
108
+ const fileToRead = await this.editFile(flags.file);
113
109
  xanoscript = fs.readFileSync(fileToRead, 'utf8');
114
- // Clean up temp file if it was created
115
- if (flags.edit && fileToRead !== flags.file) {
116
- try {
117
- fs.unlinkSync(fileToRead);
118
- }
119
- catch {
120
- // Ignore cleanup errors
121
- }
110
+ // Clean up temp file
111
+ try {
112
+ fs.unlinkSync(fileToRead);
113
+ }
114
+ catch {
115
+ // Ignore cleanup errors
122
116
  }
123
117
  }
124
- catch (error) {
125
- this.error(`Failed to read file '${fileToRead}': ${error}`);
118
+ else {
119
+ xanoscript = await this.fetchContent(flags.file);
126
120
  }
127
121
  }
128
122
  else if (flags.stdin) {
@@ -266,6 +260,31 @@ Service created successfully!
266
260
  process.stdin.resume();
267
261
  });
268
262
  }
263
+ isUrl(str) {
264
+ return str.startsWith('http://') || str.startsWith('https://');
265
+ }
266
+ async fetchContent(source) {
267
+ if (this.isUrl(source)) {
268
+ try {
269
+ const response = await fetch(source);
270
+ if (!response.ok) {
271
+ this.error(`Failed to fetch '${source}': ${response.status} ${response.statusText}`);
272
+ }
273
+ return await response.text();
274
+ }
275
+ catch (error) {
276
+ this.error(`Failed to fetch '${source}': ${error}`);
277
+ }
278
+ }
279
+ else {
280
+ try {
281
+ return fs.readFileSync(source, 'utf8');
282
+ }
283
+ catch (error) {
284
+ this.error(`Failed to read file '${source}': ${error}`);
285
+ }
286
+ }
287
+ }
269
288
  loadCredentials() {
270
289
  const configDir = path.join(os.homedir(), '.xano');
271
290
  const credentialsPath = path.join(configDir, 'credentials.yaml');