avo 3.0.0-beta.1 → 3.1.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.
Files changed (3) hide show
  1. package/Avo.js +784 -1045
  2. package/cli.js +99 -18
  3. package/package.json +1 -1
package/cli.js CHANGED
@@ -25,7 +25,7 @@ import walk from 'ignore-walk';
25
25
  import writeFile from 'write';
26
26
  import { writeJsonFile } from 'write-json-file';
27
27
  import Configstore from 'configstore';
28
- import Inspector from 'node-avo-inspector';
28
+ import { AvoInspector, AvoInspectorEnv } from 'node-avo-inspector';
29
29
  import yargs from 'yargs';
30
30
  import { hideBin } from 'yargs/helpers';
31
31
  import httpShutdown from 'http-shutdown';
@@ -293,7 +293,7 @@ const customAnalyticsDestination = {
293
293
  make: function make(production) {
294
294
  this.production = production;
295
295
  },
296
- logEvent: function logEvent(userId, eventName, eventProperties) {
296
+ logEvent: (userId, eventName, eventProperties) => {
297
297
  api
298
298
  .request('POST', '/c/v1/track', {
299
299
  origin: api.apiOrigin,
@@ -306,17 +306,18 @@ const customAnalyticsDestination = {
306
306
  .catch(() => {
307
307
  // don't crash on tracking errors
308
308
  });
309
+ return undefined;
309
310
  },
310
- setUserProperties: () => { }, // noop
311
+ setUserProperties: () => undefined, // noop
311
312
  };
312
- const inspector = new Inspector.AvoInspector({
313
+ const inspector = new AvoInspector({
313
314
  apiKey: '3UWtteG9HenZ825cYoYr',
314
- env: Inspector.AvoInspectorEnv.Prod,
315
- version: '1.0.0',
315
+ env: AvoInspectorEnv.Prod,
316
+ version: pkg.version,
316
317
  appName: 'Avo CLI',
317
318
  });
318
319
  // setup Avo analytics
319
- Avo.initAvo({ env: 'prod', inspector }, { client: Avo.Client.CLI, version: pkg.version }, {}, customAnalyticsDestination);
320
+ Avo.initAvo({ env: Avo.AvoEnv.Prod, inspector }, { client: Avo.Client.CLI, version: pkg.version }, {}, customAnalyticsDestination);
320
321
  function isLegacyAvoJson(json) {
321
322
  // check if legacy avo.json or un-initialized project
322
323
  return json.types ?? !json.schema;
@@ -739,7 +740,11 @@ function loadAvoJsonOrInit({ argv, skipPullMaster, skipInit }) {
739
740
  }
740
741
  return Promise.resolve(JSON.parse(avoFile));
741
742
  })
742
- .then((json) => Promise.resolve({ ...json, force: argv.f === true }))
743
+ .then((json) => Promise.resolve({
744
+ ...json,
745
+ force: argv.f === true,
746
+ forceFeatures: argv.forceFeatures,
747
+ }))
743
748
  .then(validateAvoJson)
744
749
  .catch((error) => {
745
750
  if (error.code === 'ENOENT' && skipInit) {
@@ -757,7 +762,7 @@ function writeAvoJson(json) {
757
762
  indent: 2,
758
763
  }).then(() => json);
759
764
  }
760
- function codegen(json, { schema, sources: targets, warnings, errors }) {
765
+ function codegen(json, { schema, sources: targets, warnings, success, errors }) {
761
766
  const newJson = { ...JSON.parse(JSON.stringify(json)), schema };
762
767
  newJson.sources = newJson.sources.map((source) => {
763
768
  const target = targets.find(({ id }) => id === source.id);
@@ -787,6 +792,11 @@ function codegen(json, { schema, sources: targets, warnings, errors }) {
787
792
  report.warn(warning);
788
793
  });
789
794
  }
795
+ if (success !== undefined && success !== null && Array.isArray(success)) {
796
+ success.forEach((success) => {
797
+ report.success(success);
798
+ });
799
+ }
790
800
  report.success(`Analytics ${targets.length > 1 ? 'wrappers' : 'wrapper'} successfully updated`);
791
801
  targets.forEach((target) => {
792
802
  const source = newJson.sources.find(({ id }) => id === target.id);
@@ -923,6 +933,7 @@ function pull(sourceFilter, json) {
923
933
  path: source.path,
924
934
  })),
925
935
  force: json.force ?? false,
936
+ forceFeatures: json.forceFeatures,
926
937
  },
927
938
  }))
928
939
  .then((result) => {
@@ -1253,6 +1264,9 @@ function logout(refreshToken) {
1253
1264
  conf.delete('tokens');
1254
1265
  }
1255
1266
  }
1267
+ function parseForceFeaturesParam(forceFeatures) {
1268
+ return forceFeatures?.split(',').map((it) => it.trim());
1269
+ }
1256
1270
  yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1257
1271
  .usage('$0 command')
1258
1272
  .scriptName('avo')
@@ -1262,12 +1276,6 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1262
1276
  default: false,
1263
1277
  describe: 'make output more verbose',
1264
1278
  type: 'boolean',
1265
- })
1266
- .option('f', {
1267
- alias: 'force',
1268
- describe: 'Proceed with merge when incoming branch is open',
1269
- default: false,
1270
- type: 'boolean',
1271
1279
  })
1272
1280
  .command({
1273
1281
  command: 'track-install',
@@ -1294,6 +1302,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1294
1302
  userId_: installIdOrUserId(),
1295
1303
  cliAction: Avo.CliAction.INIT,
1296
1304
  cliInvokedByCi: invokedByCi(),
1305
+ force: undefined,
1306
+ forceFeatures: undefined,
1297
1307
  });
1298
1308
  report.info(`Avo is already initialized for workspace ${cyan(json.schema.name)} (${file('avo.json')} exists)`);
1299
1309
  return Promise.resolve();
@@ -1306,6 +1316,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1306
1316
  userId_: installIdOrUserId(),
1307
1317
  cliAction: Avo.CliAction.INIT,
1308
1318
  cliInvokedByCi: invokedByCi(),
1319
+ force: undefined,
1320
+ forceFeatures: undefined,
1309
1321
  });
1310
1322
  return requireAuth(argv, () => init()
1311
1323
  .then(writeAvoJson)
@@ -1322,6 +1334,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1322
1334
  userId_: installIdOrUserId(),
1323
1335
  cliAction: Avo.CliAction.INIT,
1324
1336
  cliInvokedByCi: invokedByCi(),
1337
+ force: undefined,
1338
+ forceFeatures: undefined,
1325
1339
  });
1326
1340
  });
1327
1341
  },
@@ -1329,8 +1343,21 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1329
1343
  .command({
1330
1344
  command: 'pull [source]',
1331
1345
  desc: 'Pull analytics wrappers from Avo workspace',
1332
- builder: (yargs) => yargs.option('branch', {
1346
+ builder: (yargs) => yargs
1347
+ .option('branch', {
1333
1348
  describe: 'Name of Avo branch to pull from',
1349
+ default: 'main',
1350
+ type: 'string',
1351
+ })
1352
+ .option('f', {
1353
+ alias: 'force',
1354
+ describe: 'Proceed ignoring the unsupported features for given source',
1355
+ default: false,
1356
+ type: 'boolean',
1357
+ })
1358
+ .option('forceFeatures', {
1359
+ describe: 'Optional comma separated list of features to force enable',
1360
+ default: undefined,
1334
1361
  type: 'string',
1335
1362
  }),
1336
1363
  handler: (argv) => {
@@ -1344,6 +1371,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1344
1371
  userId_: installIdOrUserId(),
1345
1372
  cliAction: Avo.CliAction.PULL,
1346
1373
  cliInvokedByCi: invokedByCi(),
1374
+ force: argv.f === true,
1375
+ forceFeatures: parseForceFeaturesParam(argv.forceFeatures),
1347
1376
  });
1348
1377
  requireAuth(argv, () => {
1349
1378
  if (argv.branch && json.branch.name !== argv.branch) {
@@ -1364,6 +1393,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1364
1393
  userId_: installIdOrUserId(),
1365
1394
  cliAction: Avo.CliAction.PULL,
1366
1395
  cliInvokedByCi: invokedByCi(),
1396
+ force: undefined,
1397
+ forceFeatures: undefined,
1367
1398
  });
1368
1399
  throw error;
1369
1400
  });
@@ -1383,6 +1414,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1383
1414
  userId_: installIdOrUserId(),
1384
1415
  cliAction: Avo.CliAction.CHECKOUT,
1385
1416
  cliInvokedByCi: invokedByCi(),
1417
+ force: undefined,
1418
+ forceFeatures: undefined,
1386
1419
  });
1387
1420
  report.info(`Currently on branch '${json.branch.name}'`);
1388
1421
  requireAuth(argv, () => checkout(argv.branch, json).then(writeAvoJson));
@@ -1396,6 +1429,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1396
1429
  userId_: installIdOrUserId(),
1397
1430
  cliAction: Avo.CliAction.CHECKOUT,
1398
1431
  cliInvokedByCi: invokedByCi(),
1432
+ force: undefined,
1433
+ forceFeatures: undefined,
1399
1434
  });
1400
1435
  throw error;
1401
1436
  }),
@@ -1419,6 +1454,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1419
1454
  userId_: installIdOrUserId(),
1420
1455
  cliAction: Avo.CliAction.SOURCE,
1421
1456
  cliInvokedByCi: invokedByCi(),
1457
+ force: undefined,
1458
+ forceFeatures: undefined,
1422
1459
  });
1423
1460
  if (!json.sources || !json.sources.length) {
1424
1461
  report.info(`No sources defined in ${file('avo.json')}. Run ${cmd('avo source add')} to add sources`);
@@ -1439,6 +1476,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1439
1476
  userId_: installIdOrUserId(),
1440
1477
  cliAction: Avo.CliAction.SOURCE,
1441
1478
  cliInvokedByCi: invokedByCi(),
1479
+ force: undefined,
1480
+ forceFeatures: undefined,
1442
1481
  });
1443
1482
  throw error;
1444
1483
  });
@@ -1458,6 +1497,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1458
1497
  userId_: installIdOrUserId(),
1459
1498
  cliAction: Avo.CliAction.SOURCE_ADD,
1460
1499
  cliInvokedByCi: invokedByCi(),
1500
+ force: undefined,
1501
+ forceFeatures: undefined,
1461
1502
  });
1462
1503
  requireAuth(argv, () => {
1463
1504
  selectSource(argv.source, json).then(writeAvoJson);
@@ -1472,6 +1513,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1472
1513
  userId_: installIdOrUserId(),
1473
1514
  cliAction: Avo.CliAction.SOURCE_ADD,
1474
1515
  cliInvokedByCi: invokedByCi(),
1516
+ force: undefined,
1517
+ forceFeatures: undefined,
1475
1518
  });
1476
1519
  throw error;
1477
1520
  });
@@ -1492,6 +1535,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1492
1535
  userId_: installIdOrUserId(),
1493
1536
  cliAction: Avo.CliAction.SOURCE_REMOVE,
1494
1537
  cliInvokedByCi: invokedByCi(),
1538
+ force: undefined,
1539
+ forceFeatures: undefined,
1495
1540
  });
1496
1541
  if (!json.sources || !json.sources.length) {
1497
1542
  report.warn(`No sources defined in ${file('avo.json')}. Run ${cmd('avo source add')} to add sources`);
@@ -1552,6 +1597,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1552
1597
  userId_: installIdOrUserId(),
1553
1598
  cliAction: Avo.CliAction.SOURCE_REMOVE,
1554
1599
  cliInvokedByCi: invokedByCi(),
1600
+ force: undefined,
1601
+ forceFeatures: undefined,
1555
1602
  });
1556
1603
  throw error;
1557
1604
  });
@@ -1573,6 +1620,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1573
1620
  userId_: installIdOrUserId(),
1574
1621
  cliAction: Avo.CliAction.STATUS,
1575
1622
  cliInvokedByCi: invokedByCi(),
1623
+ force: undefined,
1624
+ forceFeatures: undefined,
1576
1625
  });
1577
1626
  report.info(`Currently on branch '${json.branch.name}'`);
1578
1627
  return getSource(argv, json);
@@ -1587,6 +1636,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1587
1636
  userId_: installIdOrUserId(),
1588
1637
  cliAction: Avo.CliAction.STATUS,
1589
1638
  cliInvokedByCi: invokedByCi(),
1639
+ force: undefined,
1640
+ forceFeatures: undefined,
1590
1641
  });
1591
1642
  throw error;
1592
1643
  });
@@ -1596,6 +1647,12 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1596
1647
  command: 'merge main',
1597
1648
  aliases: ['merge master'],
1598
1649
  desc: 'Pull the Avo main branch into your current branch',
1650
+ builder: (yargs) => yargs.option('f', {
1651
+ alias: 'force',
1652
+ describe: 'Proceed with merge when incoming branch is open',
1653
+ default: false,
1654
+ type: 'boolean',
1655
+ }),
1599
1656
  handler: (argv) => {
1600
1657
  loadAvoJsonOrInit({ argv, skipPullMaster: true, skipInit: false })
1601
1658
  .then((json) => {
@@ -1608,6 +1665,7 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1608
1665
  cliAction: Avo.CliAction.MERGE,
1609
1666
  cliInvokedByCi: invokedByCi(),
1610
1667
  force: json.force,
1668
+ forceFeatures: undefined,
1611
1669
  });
1612
1670
  return requireAuth(argv, () => pullMaster(json).then(writeAvoJson));
1613
1671
  })
@@ -1620,6 +1678,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1620
1678
  userId_: installIdOrUserId(),
1621
1679
  cliAction: Avo.CliAction.MERGE,
1622
1680
  cliInvokedByCi: invokedByCi(),
1681
+ force: undefined,
1682
+ forceFeatures: undefined,
1623
1683
  });
1624
1684
  throw error;
1625
1685
  });
@@ -1644,6 +1704,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1644
1704
  userId_: installIdOrUserId(),
1645
1705
  cliAction: Avo.CliAction.CONFLICT,
1646
1706
  cliInvokedByCi: invokedByCi(),
1707
+ force: undefined,
1708
+ forceFeatures: undefined,
1647
1709
  });
1648
1710
  pull(null, json);
1649
1711
  }));
@@ -1658,6 +1720,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1658
1720
  userId_: installIdOrUserId(),
1659
1721
  cliAction: Avo.CliAction.CONFLICT,
1660
1722
  cliInvokedByCi: invokedByCi(),
1723
+ force: undefined,
1724
+ forceFeatures: undefined,
1661
1725
  });
1662
1726
  return Promise.resolve(json);
1663
1727
  })
@@ -1670,6 +1734,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1670
1734
  userId_: installIdOrUserId(),
1671
1735
  cliAction: Avo.CliAction.CONFLICT,
1672
1736
  cliInvokedByCi: invokedByCi(),
1737
+ force: undefined,
1738
+ forceFeatures: undefined,
1673
1739
  });
1674
1740
  throw error;
1675
1741
  }),
@@ -1688,6 +1754,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1688
1754
  userId_: installIdOrUserId(),
1689
1755
  cliAction: Avo.CliAction.EDIT,
1690
1756
  cliInvokedByCi: invokedByCi(),
1757
+ force: undefined,
1758
+ forceFeatures: undefined,
1691
1759
  });
1692
1760
  const { schema } = json;
1693
1761
  const schemaUrl = `https://www.avo.app/schemas/${schema.id}`;
@@ -1703,6 +1771,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1703
1771
  userId_: installIdOrUserId(),
1704
1772
  cliAction: Avo.CliAction.EDIT,
1705
1773
  cliInvokedByCi: invokedByCi(),
1774
+ force: undefined,
1775
+ forceFeatures: undefined,
1706
1776
  });
1707
1777
  throw error;
1708
1778
  });
@@ -1725,7 +1795,7 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1725
1795
  Avo.signedIn({
1726
1796
  userId_: result.user.user_id,
1727
1797
  email: result.user.email,
1728
- cliInvokedByCi: invokedByCi(),
1798
+ authenticationMethod: Avo.AuthenticationMethod.CLI,
1729
1799
  });
1730
1800
  report.success(`Logged in as ${email(result.user.email)}`);
1731
1801
  })
@@ -1734,7 +1804,6 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1734
1804
  userId_: conf.get('avo_install_id'),
1735
1805
  emailInput: '',
1736
1806
  signInError: Avo.SignInError.UNKNOWN,
1737
- cliInvokedByCi: invokedByCi(),
1738
1807
  });
1739
1808
  });
1740
1809
  };
@@ -1748,6 +1817,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1748
1817
  userId_: installIdOrUserId(),
1749
1818
  cliAction: Avo.CliAction.LOGIN,
1750
1819
  cliInvokedByCi: invokedByCi(),
1820
+ force: undefined,
1821
+ forceFeatures: undefined,
1751
1822
  });
1752
1823
  command();
1753
1824
  })
@@ -1760,6 +1831,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1760
1831
  userId_: installIdOrUserId(),
1761
1832
  cliAction: Avo.CliAction.LOGIN,
1762
1833
  cliInvokedByCi: invokedByCi(),
1834
+ force: undefined,
1835
+ forceFeatures: undefined,
1763
1836
  });
1764
1837
  command();
1765
1838
  });
@@ -1804,6 +1877,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1804
1877
  userId_: installIdOrUserId(),
1805
1878
  cliAction: Avo.CliAction.LOGOUT,
1806
1879
  cliInvokedByCi: invokedByCi(),
1880
+ force: undefined,
1881
+ forceFeatures: undefined,
1807
1882
  });
1808
1883
  command();
1809
1884
  })
@@ -1816,6 +1891,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1816
1891
  userId_: installIdOrUserId(),
1817
1892
  cliAction: Avo.CliAction.LOGOUT,
1818
1893
  cliInvokedByCi: invokedByCi(),
1894
+ force: undefined,
1895
+ forceFeatures: undefined,
1819
1896
  });
1820
1897
  command();
1821
1898
  });
@@ -1846,6 +1923,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1846
1923
  userId_: installIdOrUserId(),
1847
1924
  cliAction: Avo.CliAction.WHOAMI,
1848
1925
  cliInvokedByCi: invokedByCi(),
1926
+ force: undefined,
1927
+ forceFeatures: undefined,
1849
1928
  });
1850
1929
  command();
1851
1930
  })
@@ -1858,6 +1937,8 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1858
1937
  userId_: installIdOrUserId(),
1859
1938
  cliAction: Avo.CliAction.WHOAMI,
1860
1939
  cliInvokedByCi: invokedByCi(),
1940
+ force: undefined,
1941
+ forceFeatures: undefined,
1861
1942
  });
1862
1943
  command();
1863
1944
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "avo",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.1.0",
4
4
  "type": "module",
5
5
  "description": "The command-line interface for Avo",
6
6
  "author": "Avo (https://www.avo.app)",