@mochabug/adaptkit 0.8.7 → 0.8.9
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 +69 -65
- package/bin/publish.d.ts.map +1 -1
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import figlet from 'figlet';
|
|
|
5
5
|
import isValidHostname from 'is-valid-hostname';
|
|
6
6
|
import fs from 'fs';
|
|
7
7
|
import inquirer from 'inquirer';
|
|
8
|
-
import { ServiceType, stackIntercept } from '@protobuf-ts/runtime-rpc';
|
|
8
|
+
import { ServiceType, stackIntercept, RpcError } from '@protobuf-ts/runtime-rpc';
|
|
9
9
|
import { MessageType, reflectionMergePartial, UnknownFieldHandler, WireType } from '@protobuf-ts/runtime';
|
|
10
10
|
import { mkdirp } from 'mkdirp';
|
|
11
11
|
import path from 'path';
|
|
@@ -1475,17 +1475,6 @@ class PluginServiceClient {
|
|
|
1475
1475
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1476
1476
|
// See the License for the specific language governing permissions and
|
|
1477
1477
|
// limitations under the License.
|
|
1478
|
-
function printStatus(status) {
|
|
1479
|
-
if (status.code !== 'OK') {
|
|
1480
|
-
console.error('Error: The server returned a non-successful status code.');
|
|
1481
|
-
console.error(`Status Code: ${status.code}`);
|
|
1482
|
-
console.error(`Details: ${status.detail}`);
|
|
1483
|
-
console.log(chalk.bgRed('FAILURE'));
|
|
1484
|
-
}
|
|
1485
|
-
else {
|
|
1486
|
-
console.log(chalk.green('Stream message was sent successfully'));
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
1478
|
async function resize(filepath, height, width) {
|
|
1490
1479
|
const extname = path.extname(filepath);
|
|
1491
1480
|
switch (extname) {
|
|
@@ -1508,14 +1497,21 @@ async function resize(filepath, height, width) {
|
|
|
1508
1497
|
}
|
|
1509
1498
|
throw new Error('Invalid logotype');
|
|
1510
1499
|
}
|
|
1500
|
+
function isPathSafe(filePath) {
|
|
1501
|
+
const currentWorkingDir = path.resolve('.');
|
|
1502
|
+
const absoluteFilePath = path.resolve(filePath);
|
|
1503
|
+
return absoluteFilePath.startsWith(currentWorkingDir);
|
|
1504
|
+
}
|
|
1511
1505
|
async function sendPlugin(manifest, client, metadata) {
|
|
1512
1506
|
console.log('Sending the plugin to the server');
|
|
1513
1507
|
const stream = client.uploadPlugin({ meta: metadata });
|
|
1514
1508
|
const lookup = {};
|
|
1515
|
-
// Returns success / false
|
|
1516
1509
|
async function send(filePath, imgOpts) {
|
|
1517
1510
|
if (!filePath || lookup[filePath]) {
|
|
1518
|
-
return
|
|
1511
|
+
return;
|
|
1512
|
+
}
|
|
1513
|
+
if (!isPathSafe(filePath)) {
|
|
1514
|
+
throw new Error(`The file path is not safe: ${filePath}. It must be contained inside the manifest folder. Invalid manifest`);
|
|
1519
1515
|
}
|
|
1520
1516
|
if (!fs.existsSync(filePath)) {
|
|
1521
1517
|
throw new Error(`The file does not exists: ${filePath}. Invalid manifest`);
|
|
@@ -1539,11 +1535,9 @@ async function sendPlugin(manifest, client, metadata) {
|
|
|
1539
1535
|
}
|
|
1540
1536
|
}
|
|
1541
1537
|
};
|
|
1542
|
-
|
|
1538
|
+
// The idea here is that we will have an RPC error if the server has returned an error
|
|
1539
|
+
await Promise.race([stream.requests.send(message), stream.status]);
|
|
1543
1540
|
lookup[filePath] = true;
|
|
1544
|
-
const status = await stream.status;
|
|
1545
|
-
printStatus(status);
|
|
1546
|
-
return status.code === 'OK';
|
|
1547
1541
|
}
|
|
1548
1542
|
// The first message must be the manifest
|
|
1549
1543
|
// All the other messages must be files and must be described in the manifest
|
|
@@ -1554,68 +1548,39 @@ async function sendPlugin(manifest, client, metadata) {
|
|
|
1554
1548
|
}
|
|
1555
1549
|
};
|
|
1556
1550
|
await stream.requests.send(request);
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
success = await send('LICENSE.md');
|
|
1563
|
-
if (!success) {
|
|
1564
|
-
return;
|
|
1565
|
-
}
|
|
1566
|
-
success = await send(manifest.executorEsm);
|
|
1567
|
-
if (!success) {
|
|
1568
|
-
return;
|
|
1569
|
-
}
|
|
1570
|
-
success = await send(manifest.configuratorEsm);
|
|
1571
|
-
if (!success) {
|
|
1572
|
-
return;
|
|
1573
|
-
}
|
|
1574
|
-
success = await send(manifest.logo, [80, 80]);
|
|
1575
|
-
if (!success) {
|
|
1576
|
-
return;
|
|
1577
|
-
}
|
|
1551
|
+
await send('README.md');
|
|
1552
|
+
await send('LICENSE.md');
|
|
1553
|
+
await send(manifest.executorEsm);
|
|
1554
|
+
await send(manifest.configuratorEsm);
|
|
1555
|
+
await send(manifest.logo, [80, 80]);
|
|
1578
1556
|
// Send everything inside the asset directory as assets
|
|
1579
1557
|
if (manifest.assetsDir && fs.existsSync(manifest.assetsDir)) {
|
|
1580
1558
|
const paths = await fg(path.join(manifest.assetsDir, '**', '*'));
|
|
1581
1559
|
for (let filepath of paths) {
|
|
1582
1560
|
if (fs.statSync(filepath).isFile()) {
|
|
1583
|
-
|
|
1584
|
-
if (!success) {
|
|
1585
|
-
return;
|
|
1586
|
-
}
|
|
1561
|
+
await send(filepath);
|
|
1587
1562
|
}
|
|
1588
1563
|
}
|
|
1589
1564
|
}
|
|
1590
1565
|
// Send everything related to the vertices. Logos, schemas and configs
|
|
1591
1566
|
for (let vertex of manifest.vertices) {
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
return;
|
|
1595
|
-
}
|
|
1596
|
-
success = await send(vertex.defaultConfig);
|
|
1597
|
-
if (!success) {
|
|
1598
|
-
return;
|
|
1599
|
-
}
|
|
1567
|
+
await send(vertex.logo, [40, 40]);
|
|
1568
|
+
await send(vertex.defaultConfig);
|
|
1600
1569
|
for (let mtls of vertex.mtls) {
|
|
1601
|
-
|
|
1602
|
-
if (!success) {
|
|
1603
|
-
return;
|
|
1604
|
-
}
|
|
1570
|
+
await send(mtls.trustedCa);
|
|
1605
1571
|
}
|
|
1606
1572
|
}
|
|
1607
1573
|
// Send the ca bundles
|
|
1608
1574
|
for (let mtls of manifest.mtls) {
|
|
1609
|
-
|
|
1610
|
-
if (!success) {
|
|
1611
|
-
return;
|
|
1612
|
-
}
|
|
1575
|
+
await send(mtls.trustedCa);
|
|
1613
1576
|
}
|
|
1614
1577
|
await stream.requests.complete();
|
|
1578
|
+
const status = await stream.status;
|
|
1579
|
+
console.error(chalk.green(`Status Code: ${status.code}`));
|
|
1580
|
+
console.error(chalk.green(`Details: ${status.detail}`));
|
|
1615
1581
|
const result = await stream.response;
|
|
1616
|
-
console.log(chalk.bgGreen('SUCCESS'));
|
|
1617
|
-
console.log(chalk.green('Publishing done'));
|
|
1618
1582
|
console.log(result);
|
|
1583
|
+
console.log(chalk.bgGreen('SUCCESS'));
|
|
1619
1584
|
}
|
|
1620
1585
|
async function emulate(manifest, host) {
|
|
1621
1586
|
const transport = new GrpcTransport({
|
|
@@ -1627,8 +1592,13 @@ async function emulate(manifest, host) {
|
|
|
1627
1592
|
await sendPlugin(manifest, client);
|
|
1628
1593
|
}
|
|
1629
1594
|
catch (e) {
|
|
1630
|
-
|
|
1631
|
-
|
|
1595
|
+
if (e instanceof RpcError) {
|
|
1596
|
+
printRpcError(e);
|
|
1597
|
+
}
|
|
1598
|
+
else {
|
|
1599
|
+
console.error(e);
|
|
1600
|
+
}
|
|
1601
|
+
console.log(`For more information, use: ${chalk.blue('adaptkit help publish')}`);
|
|
1632
1602
|
}
|
|
1633
1603
|
}
|
|
1634
1604
|
async function publish(manifest, host, accessToken, insecure) {
|
|
@@ -1646,13 +1616,47 @@ async function publish(manifest, host, accessToken, insecure) {
|
|
|
1646
1616
|
await sendPlugin(manifest, client, metadata);
|
|
1647
1617
|
}
|
|
1648
1618
|
catch (e) {
|
|
1649
|
-
|
|
1619
|
+
if (e instanceof RpcError) {
|
|
1620
|
+
printRpcError(e);
|
|
1621
|
+
}
|
|
1622
|
+
else {
|
|
1623
|
+
console.error(e);
|
|
1624
|
+
}
|
|
1650
1625
|
console.log(`For more information, use: ${chalk.blue('adaptkit help publish')}`);
|
|
1651
1626
|
}
|
|
1652
1627
|
}
|
|
1628
|
+
function printRpcError(error) {
|
|
1629
|
+
const line = chalk.red('--------------------------------------------------');
|
|
1630
|
+
const title = chalk.bold.red('RPC Error Details');
|
|
1631
|
+
const name = chalk.bold.white('Name: ') + chalk.redBright(error.name);
|
|
1632
|
+
const message = chalk.bold.white('Message: ') + chalk.redBright(error.message);
|
|
1633
|
+
const code = chalk.bold.white('Code: ') + chalk.redBright(error.code);
|
|
1634
|
+
const methodName = error.methodName
|
|
1635
|
+
? chalk.bold.white('Method Name: ') + chalk.yellowBright(error.methodName)
|
|
1636
|
+
: '';
|
|
1637
|
+
const serviceName = error.serviceName
|
|
1638
|
+
? chalk.bold.white('Service Name: ') + chalk.yellowBright(error.serviceName)
|
|
1639
|
+
: '';
|
|
1640
|
+
const meta = chalk.bold.white('Metadata: ') +
|
|
1641
|
+
(error.meta
|
|
1642
|
+
? chalk.blue(JSON.stringify(error.meta, null, 2))
|
|
1643
|
+
: chalk.gray('No Metadata'));
|
|
1644
|
+
console.error(line);
|
|
1645
|
+
console.error(title);
|
|
1646
|
+
console.error(line);
|
|
1647
|
+
console.error(name);
|
|
1648
|
+
console.error(message);
|
|
1649
|
+
console.error(code);
|
|
1650
|
+
if (methodName)
|
|
1651
|
+
console.error(methodName);
|
|
1652
|
+
if (serviceName)
|
|
1653
|
+
console.error(serviceName);
|
|
1654
|
+
console.error(meta);
|
|
1655
|
+
console.error(line);
|
|
1656
|
+
}
|
|
1653
1657
|
|
|
1654
1658
|
var name = "@mochabug/adaptkit";
|
|
1655
|
-
var version = "0.8.
|
|
1659
|
+
var version = "0.8.9";
|
|
1656
1660
|
var description = "A cmd to create, emulate and publish Mochabug Adapt plugins";
|
|
1657
1661
|
var main$1 = "bin/index.js";
|
|
1658
1662
|
var type = "module";
|
package/bin/publish.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,QAAQ,EAET,MAAM,kDAAkD,CAAC;
|
|
1
|
+
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,QAAQ,EAET,MAAM,kDAAkD,CAAC;AAwI1D,wBAAsB,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,iBAkB7D;AAED,wBAAsB,OAAO,CAC3B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,OAAO,iBAwBlB"}
|