@mochabug/adaptkit 0.5.0-alpha.1 → 0.5.0-alpha.2

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/bin/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import chalk from 'chalk';
3
3
  import { program } from 'commander';
4
4
  import figlet from 'figlet';
5
+ import isValidHostname from 'is-valid-hostname';
5
6
  import fs from 'fs';
6
7
  import inquirer from 'inquirer';
7
8
  import { ServiceType, stackIntercept } from '@protobuf-ts/runtime-rpc';
@@ -1222,7 +1223,7 @@ var successPage = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=
1222
1223
  const OAUTH_CALLBACK_PORT = 51421;
1223
1224
  const PORT_RANGE = 5;
1224
1225
  const OAUTH_SCOPE = 'https://www.mochabugapis.com/auth/adapt.plugins';
1225
- const AUDIENCE = 'https://adapt.mochabugapis.com';
1226
+ const AUDIENCE = 'https://test.adapt.mochabugapis.com';
1226
1227
  function createCodeUrl({ clientId, redirectUri, scope, state, authUrl, codeChallenge, audience }) {
1227
1228
  const res = new URL(authUrl);
1228
1229
  res.searchParams.set('response_type', 'code');
@@ -1551,9 +1552,9 @@ async function sendPlugin(manifest, client, metadata) {
1551
1552
  console.log(chalk.bgRed('FAILURE'));
1552
1553
  }
1553
1554
  }
1554
- async function emulate(manifest, address) {
1555
+ async function emulate(manifest, host) {
1555
1556
  const transport = new GrpcTransport({
1556
- host: address,
1557
+ host,
1557
1558
  channelCredentials: ChannelCredentials.createInsecure()
1558
1559
  });
1559
1560
  const client = new PluginServiceClient(transport);
@@ -1593,6 +1594,23 @@ async function isValidUrl(urlString) {
1593
1594
  return false;
1594
1595
  }
1595
1596
  }
1597
+ function isValidPort(port) {
1598
+ const portNumber = parseInt(port, 10);
1599
+ return portNumber > 0 && portNumber <= 65535;
1600
+ }
1601
+ function isValidHostWithPort(hostWithPort) {
1602
+ const [hostname, port] = hostWithPort.split(':');
1603
+ if (!isValidHostname(hostname)) {
1604
+ return { isValid: false, hostname };
1605
+ }
1606
+ if (port !== undefined) {
1607
+ if (!isValidPort(port)) {
1608
+ return { isValid: false, hostname, port: parseInt(port, 10) };
1609
+ }
1610
+ return { isValid: true, hostname, port: parseInt(port, 10) };
1611
+ }
1612
+ return { isValid: true, hostname };
1613
+ }
1596
1614
  function banner() {
1597
1615
  return chalk.yellowBright(figlet.textSync('Adaptkit'));
1598
1616
  }
@@ -1620,11 +1638,17 @@ async function handleAdd(cmd) {
1620
1638
  await add(manifest);
1621
1639
  }
1622
1640
  async function handlePublish(host, authority, client, insecure, errorUrl, cmd) {
1623
- if (!(await isValidUrl(authority)) || !host) {
1624
- console.error(chalk.red(`Error: The provided address or host is not a valid URL.`));
1641
+ if (!(await isValidUrl(authority))) {
1642
+ console.error(chalk.red(`Error: The provided authority is not a valid URL: ${authority}`));
1625
1643
  console.log(`For more information, use: ${chalk.blue('adaptkit help publish')}`);
1626
1644
  process.exit(1);
1627
1645
  }
1646
+ const { isValid, hostname, port } = isValidHostWithPort(host);
1647
+ if (!isValid) {
1648
+ console.error(chalk.red(`Error: The provided host or port is not valid: ${hostname}${port ? ':' + port : ''}`));
1649
+ console.log(`For more information, use: ${chalk.blue('adaptkit help emulate')}`);
1650
+ process.exit(1);
1651
+ }
1628
1652
  if (cmd.args.length >= 1) {
1629
1653
  console.error(chalk.red(`Error: Invalid sub-command or arguments provided.`));
1630
1654
  console.log(`For more information, use: ${chalk.blue('adaptkit help publish')}`);
@@ -1642,9 +1666,10 @@ async function handlePublish(host, authority, client, insecure, errorUrl, cmd) {
1642
1666
  }
1643
1667
  await publish(manifest, host, accessToken, insecure);
1644
1668
  }
1645
- async function handleEmulate(address, cmd) {
1646
- if (!(await isValidUrl(address))) {
1647
- console.error(chalk.red(`Error: The provided address is not a valid URL.`));
1669
+ async function handleEmulate(host, cmd) {
1670
+ const { isValid, hostname, port } = isValidHostWithPort(host);
1671
+ if (!isValid) {
1672
+ console.error(chalk.red(`Error: The provided host or port is not valid: ${hostname}${port ? ':' + port : ''}`));
1648
1673
  console.log(`For more information, use: ${chalk.blue('adaptkit help emulate')}`);
1649
1674
  process.exit(1);
1650
1675
  }
@@ -1658,7 +1683,7 @@ async function handleEmulate(address, cmd) {
1658
1683
  console.log(`For more information, use: ${chalk.blue('adaptkit help emulate')}`);
1659
1684
  process.exit(1);
1660
1685
  }
1661
- await emulate(manifest, address);
1686
+ await emulate(manifest, host);
1662
1687
  }
1663
1688
  async function main() {
1664
1689
  program
@@ -1684,10 +1709,10 @@ async function main() {
1684
1709
  .action((cmd) => handleAdd(cmd));
1685
1710
  program
1686
1711
  .command('publish')
1687
- .option('-h, --host <host>', chalk.yellow('Warning: Primarily for development purposes'), 'adapt.mochabugapis.com')
1688
- .option('-a, --authority <authority>', chalk.yellow('Warning: Primarily for development purposes'), 'https://auth.mochabug.com')
1689
- .option('-c, --client <client>', chalk.yellow('Warning: Primarily for development purposes'), '7e0fd8a6-ffa2-46bb-8bdc-1d17266fd559')
1690
- .option('-e, --error-url <errorUrl>', chalk.yellow('Warning: Primarily for development purposes'), 'https://accounts.mochabug.com/services/error')
1712
+ .option('-h, --host <host>', chalk.yellow('Warning: Primarily for development purposes'), 'test.adapt.mochabugapis.com')
1713
+ .option('-a, --authority <authority>', chalk.yellow('Warning: Primarily for development purposes'), 'https://test.auth.mochabug.com')
1714
+ .option('-c, --client <client>', chalk.yellow('Warning: Primarily for development purposes'), 'da745cc5-a453-4400-aed2-c49af411bd3f')
1715
+ .option('-e, --error-url <errorUrl>', chalk.yellow('Warning: Primarily for development purposes'), 'https://test.accounts.mochabug.com/services/error')
1691
1716
  .option('--insecure', chalk.red('Ignore SSL certificate errors (insecure)'))
1692
1717
  .description('Ready for liftoff? Publish your plugin to your organization with this command.')
1693
1718
  .action(({ host, authority, client, insecure, errorUrl }, cmd) => handlePublish(host, authority, client, insecure, errorUrl, cmd));
@@ -1695,7 +1720,7 @@ async function main() {
1695
1720
  .command('emulate')
1696
1721
  .option('-h, --host <host>', 'Specify the URL to test your plugin in the emulator. Ideal for custom port configurations.', 'localhost:51002')
1697
1722
  .description('Take your plugin for a test drive. Best used in conjunction with your build pipeline.')
1698
- .action(({ url }, cmd) => handleEmulate(url, cmd));
1723
+ .action(({ host }, cmd) => handleEmulate(host, cmd));
1699
1724
  // Set a custom help action
1700
1725
  program.addHelpText('beforeAll', banner() + '\n');
1701
1726
  program.showHelpAfterError();
package/bin/publish.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { Manifest } from './genproto/mochabugapis/adapt/plugins/v1/plugins';
2
- export declare function emulate(manifest: Manifest, address: string): Promise<void>;
2
+ export declare function emulate(manifest: Manifest, host: string): Promise<void>;
3
3
  export declare function publish(manifest: Manifest, host: string, accessToken: string, insecure: boolean): Promise<void>;
4
4
  //# sourceMappingURL=publish.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,QAAQ,EAET,MAAM,kDAAkD,CAAC;AAgI1D,wBAAsB,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAOhE;AAED,wBAAsB,OAAO,CAC3B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,OAAO,iBAWlB"}
1
+ {"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,QAAQ,EAET,MAAM,kDAAkD,CAAC;AAgI1D,wBAAsB,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,iBAO7D;AAED,wBAAsB,OAAO,CAC3B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,OAAO,iBAWlB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mochabug/adaptkit",
3
- "version": "0.5.0-alpha.1",
3
+ "version": "0.5.0-alpha.2",
4
4
  "description": "A cmd to create, emulate and publish Mochabug Adapt plugins",
5
5
  "main": "bin/index.js",
6
6
  "type": "module",
@@ -41,13 +41,13 @@
41
41
  "@rollup/plugin-commonjs": "^25.0.7",
42
42
  "@rollup/plugin-node-resolve": "^15.2.3",
43
43
  "@rollup/plugin-typescript": "^11.1.5",
44
- "@types/express": "^4.17.20",
45
- "@types/figlet": "^1.5.7",
46
- "@types/inquirer": "^9.0.6",
47
- "@types/jest": "^29.5.7",
44
+ "@types/express": "^4.17.21",
45
+ "@types/figlet": "^1.5.8",
46
+ "@types/inquirer": "^9.0.7",
47
+ "@types/jest": "^29.5.8",
48
48
  "@types/mkdirp": "^1.0.2",
49
- "@types/mustache": "^4.2.4",
50
- "@types/node": "^20.8.10",
49
+ "@types/mustache": "^4.2.5",
50
+ "@types/node": "^20.9.0",
51
51
  "@types/sharp": "^0.31.1",
52
52
  "jest": "^29.7.0",
53
53
  "rollup": "^4.3.0",
@@ -64,9 +64,10 @@
64
64
  "chalk": "^5.3.0",
65
65
  "commander": "^11.1.0",
66
66
  "express": "^4.18.2",
67
- "fast-glob": "^3.3.1",
67
+ "fast-glob": "^3.3.2",
68
68
  "figlet": "^1.7.0",
69
- "inquirer": "^9.2.11",
69
+ "inquirer": "^9.2.12",
70
+ "is-valid-hostname": "^1.0.2",
70
71
  "mkdirp": "^3.0.1",
71
72
  "mustache": "^4.2.0",
72
73
  "node-fetch": "^3.3.2",