@asyncapi/cli 1.12.2 → 1.13.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/lib/base.d.ts CHANGED
@@ -14,6 +14,7 @@ export default abstract class extends Command {
14
14
  recordActionFinished(action: string, metadata?: MetricMetadata, rawDocument?: string): Promise<void>;
15
15
  recordActionInvoked(action: string, metadata?: MetricMetadata): Promise<void>;
16
16
  recordActionMetric(recordFunc: (recorder: Recorder) => Promise<void>): Promise<void>;
17
+ setSource(): Promise<void>;
17
18
  finally(error: Error | undefined): Promise<any>;
18
19
  recorderFromEnv(prefix: string): Promise<Recorder>;
19
20
  }
package/lib/base.js CHANGED
@@ -9,7 +9,7 @@ const fs_extra_1 = require("fs-extra");
9
9
  const fs_1 = require("fs");
10
10
  const uuid_1 = require("uuid");
11
11
  const os_1 = require("os");
12
- const { readFile, writeFile } = fs_1.promises;
12
+ const { readFile, writeFile, stat } = fs_1.promises;
13
13
  class DiscardSink {
14
14
  send() {
15
15
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
@@ -86,6 +86,7 @@ class default_1 extends core_1.Command {
86
86
  recordActionMetric(recordFunc) {
87
87
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
88
88
  try {
89
+ yield this.setSource();
89
90
  yield recordFunc(yield this.recorder);
90
91
  yield (yield this.recorder).flush();
91
92
  }
@@ -96,6 +97,22 @@ class default_1 extends core_1.Command {
96
97
  }
97
98
  });
98
99
  }
100
+ setSource() {
101
+ var _a;
102
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
103
+ const specFilePath = (_a = this.specFile) === null || _a === void 0 ? void 0 : _a.getFilePath();
104
+ if (!specFilePath) {
105
+ return;
106
+ }
107
+ try {
108
+ const stats = yield stat(specFilePath);
109
+ this.metricsMetadata['file_creation_timestamp'] = stats.birthtimeMs;
110
+ }
111
+ catch (e) {
112
+ // If there's an error with the file, we don't handle it here because it's expected to be handled and reported in the 'finally' method of the command.
113
+ }
114
+ });
115
+ }
99
116
  finally(error) {
100
117
  const _super = Object.create(null, {
101
118
  finally: { get: () => super.finally }
@@ -16,6 +16,9 @@ export default class Template extends Command {
16
16
  watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
17
17
  param: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined>;
18
18
  'map-base-url': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
19
+ 'registry-url': import("@oclif/core/lib/interfaces").OptionFlag<string>;
20
+ 'registry-auth': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
21
+ 'registry-token': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
19
22
  };
20
23
  static args: {
21
24
  name: string;
@@ -25,6 +28,8 @@ export default class Template extends Command {
25
28
  run(): Promise<void>;
26
29
  private parseArgs;
27
30
  private parseFlags;
31
+ private registryURLParser;
32
+ private registryValidation;
28
33
  private paramParser;
29
34
  private disableHooksParser;
30
35
  private mapBaseURLParser;
@@ -17,6 +17,7 @@ const generator_error_1 = require("../../errors/generator-error");
17
17
  const parser_1 = require("@asyncapi/parser");
18
18
  const prompts_1 = require("@clack/prompts");
19
19
  const picocolors_1 = require("picocolors");
20
+ const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
20
21
  const templatesNotSupportingV3 = {
21
22
  '@asyncapi/minimaltemplate': 'some link',
22
23
  '@asyncapi/dotnet-nats-template': 'https://github.com/asyncapi/dotnet-nats-template/issues/384',
@@ -84,7 +85,7 @@ class Template extends base_1.default {
84
85
  template = parsedArgs.template;
85
86
  output = parsedArgs.output;
86
87
  }
87
- const parsedFlags = this.parseFlags(flags['disable-hook'], flags['param'], flags['map-base-url']);
88
+ const parsedFlags = this.parseFlags(flags['disable-hook'], flags['param'], flags['map-base-url'], flags['registry.url'], flags['registry.auth'], flags['registry.token']);
88
89
  const options = {
89
90
  forceWrite: flags['force-write'],
90
91
  install: flags.install,
@@ -93,6 +94,11 @@ class Template extends base_1.default {
93
94
  noOverwriteGlobs: flags['no-overwrite'],
94
95
  mapBaseUrlToFolder: parsedFlags.mapBaseUrlToFolder,
95
96
  disabledHooks: parsedFlags.disableHooks,
97
+ registry: {
98
+ url: flags['registry-url'],
99
+ auth: flags['registry-auth'],
100
+ token: flags['registry-token']
101
+ }
96
102
  };
97
103
  const asyncapiInput = (yield (0, SpecificationFile_1.load)(asyncapi)) || (yield (0, SpecificationFile_1.load)());
98
104
  this.specFile = asyncapiInput;
@@ -165,13 +171,32 @@ class Template extends base_1.default {
165
171
  return { asyncapi, template, output };
166
172
  });
167
173
  }
168
- parseFlags(disableHooks, params, mapBaseUrl) {
174
+ parseFlags(disableHooks, params, mapBaseUrl, registryUrl, registryAuth, registryToken) {
169
175
  return {
170
176
  params: this.paramParser(params),
171
177
  disableHooks: this.disableHooksParser(disableHooks),
172
178
  mapBaseUrlToFolder: this.mapBaseURLParser(mapBaseUrl),
179
+ registryURLValidation: this.registryURLParser(registryUrl),
180
+ registryAuthentication: this.registryValidation(registryUrl, registryAuth, registryToken)
173
181
  };
174
182
  }
183
+ registryURLParser(input) {
184
+ if (!input) {
185
+ return;
186
+ }
187
+ const isURL = /^https?:/;
188
+ if (!isURL.test(input.toLowerCase())) {
189
+ throw new Error('Invalid --registry-url flag. The param requires a valid http/https url.');
190
+ }
191
+ }
192
+ registryValidation(registryUrl, registryAuth, registryToken) {
193
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
194
+ const response = yield (0, node_fetch_1.default)(registryUrl);
195
+ if (response.status === 401 && !registryAuth && !registryToken) {
196
+ throw new Error('Need to pass either registryAuth in username:password encoded in Base64 or need to pass registryToken');
197
+ }
198
+ });
199
+ }
175
200
  paramParser(inputs) {
176
201
  if (!inputs) {
177
202
  return {};
@@ -363,6 +388,16 @@ Template.flags = {
363
388
  'map-base-url': core_1.Flags.string({
364
389
  description: 'Maps all schema references from base url to local folder'
365
390
  }),
391
+ 'registry-url': core_1.Flags.string({
392
+ default: 'https://registry.npmjs.org',
393
+ description: 'Specifies the URL of the private registry for fetching templates and dependencies'
394
+ }),
395
+ 'registry-auth': core_1.Flags.string({
396
+ description: 'The registry username and password encoded with base64, formatted as username:password'
397
+ }),
398
+ 'registry-token': core_1.Flags.string({
399
+ description: 'The npm registry authentication token, that can be passed instead of base64 encoded username and password'
400
+ })
366
401
  };
367
402
  Template.args = [
368
403
  { name: 'asyncapi', description: '- Local path, url or context-name pointing to AsyncAPI file' },
@@ -605,6 +605,28 @@
605
605
  "hasDynamicHelp": false,
606
606
  "multiple": false,
607
607
  "type": "option"
608
+ },
609
+ "registry-url": {
610
+ "description": "Specifies the URL of the private registry for fetching templates and dependencies",
611
+ "name": "registry-url",
612
+ "default": "https://registry.npmjs.org",
613
+ "hasDynamicHelp": false,
614
+ "multiple": false,
615
+ "type": "option"
616
+ },
617
+ "registry-auth": {
618
+ "description": "The registry username and password encoded with base64, formatted as username:password",
619
+ "name": "registry-auth",
620
+ "hasDynamicHelp": false,
621
+ "multiple": false,
622
+ "type": "option"
623
+ },
624
+ "registry-token": {
625
+ "description": "The npm registry authentication token, that can be passed instead of base64 encoded username and password",
626
+ "name": "registry-token",
627
+ "hasDynamicHelp": false,
628
+ "multiple": false,
629
+ "type": "option"
608
630
  }
609
631
  },
610
632
  "hasDynamicHelp": false,
@@ -1448,5 +1470,5 @@
1448
1470
  ]
1449
1471
  }
1450
1472
  },
1451
- "version": "1.12.2"
1473
+ "version": "1.13.0"
1452
1474
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@asyncapi/cli",
3
3
  "description": "All in one CLI for all AsyncAPI tools",
4
- "version": "1.12.2",
4
+ "version": "1.13.0",
5
5
  "author": "@asyncapi",
6
6
  "bin": {
7
7
  "asyncapi": "./bin/run_bin"
@@ -13,7 +13,7 @@
13
13
  "@asyncapi/converter": "^1.4.19",
14
14
  "@asyncapi/diff": "^0.4.1",
15
15
  "@asyncapi/generator": "^1.17.25",
16
- "@asyncapi/modelina": "^3.4.9",
16
+ "@asyncapi/modelina": "^3.5.0",
17
17
  "@asyncapi/openapi-schema-parser": "^3.0.22",
18
18
  "@asyncapi/optimizer": "^1.0.2",
19
19
  "@asyncapi/parser": "^3.0.14",