@automattic/vip 2.22.0 → 2.24.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 (110) hide show
  1. package/CHANGELOG.md +38 -13
  2. package/assets/dev-env.lando.template.yml.ejs +6 -1
  3. package/dist/bin/vip-app-list.js +0 -12
  4. package/dist/bin/vip-app.js +6 -13
  5. package/dist/bin/vip-cache-purge-url.js +4 -19
  6. package/dist/bin/vip-cache.js +0 -2
  7. package/dist/bin/vip-config-envvar-delete.js +4 -19
  8. package/dist/bin/vip-config-envvar-get-all.js +6 -19
  9. package/dist/bin/vip-config-envvar-get.js +4 -15
  10. package/dist/bin/vip-config-envvar-list.js +8 -20
  11. package/dist/bin/vip-config-envvar-set.js +4 -23
  12. package/dist/bin/vip-config-envvar.js +0 -2
  13. package/dist/bin/vip-config-software-get.js +0 -17
  14. package/dist/bin/vip-config-software-update.js +6 -22
  15. package/dist/bin/vip-config-software.js +0 -2
  16. package/dist/bin/vip-config.js +0 -2
  17. package/dist/bin/vip-dev-env-create.js +8 -21
  18. package/dist/bin/vip-dev-env-destroy.js +4 -11
  19. package/dist/bin/vip-dev-env-exec.js +4 -14
  20. package/dist/bin/vip-dev-env-import-media.js +3 -8
  21. package/dist/bin/vip-dev-env-import-sql.js +10 -23
  22. package/dist/bin/vip-dev-env-import.js +0 -3
  23. package/dist/bin/vip-dev-env-info.js +5 -13
  24. package/dist/bin/vip-dev-env-list.js +4 -9
  25. package/dist/bin/vip-dev-env-start.js +9 -17
  26. package/dist/bin/vip-dev-env-stop.js +4 -11
  27. package/dist/bin/vip-dev-env-update.js +4 -12
  28. package/dist/bin/vip-dev-env.js +0 -2
  29. package/dist/bin/vip-import-media-abort.js +0 -18
  30. package/dist/bin/vip-import-media-status.js +0 -12
  31. package/dist/bin/vip-import-media.js +6 -23
  32. package/dist/bin/vip-import-sql-status.js +0 -12
  33. package/dist/bin/vip-import-sql.js +33 -99
  34. package/dist/bin/vip-import-validate-files.js +21 -42
  35. package/dist/bin/vip-import-validate-sql.js +0 -8
  36. package/dist/bin/vip-import.js +0 -3
  37. package/dist/bin/vip-logs.js +20 -50
  38. package/dist/bin/vip-search-replace.js +8 -14
  39. package/dist/bin/vip-sync.js +2 -25
  40. package/dist/bin/vip-validate-preflight.js +467 -0
  41. package/dist/bin/vip-validate.js +19 -0
  42. package/dist/bin/vip-whoami.js +2 -14
  43. package/dist/bin/vip-wp.js +39 -89
  44. package/dist/bin/vip.js +14 -40
  45. package/dist/lib/analytics/clients/pendo.js +9 -18
  46. package/dist/lib/analytics/clients/stub.js +1 -3
  47. package/dist/lib/analytics/clients/tracks.js +11 -20
  48. package/dist/lib/analytics/index.js +4 -11
  49. package/dist/lib/api/app.js +1 -11
  50. package/dist/lib/api/cache-purge.js +4 -7
  51. package/dist/lib/api/feature-flags.js +1 -4
  52. package/dist/lib/api/http.js +9 -15
  53. package/dist/lib/api/user.js +1 -7
  54. package/dist/lib/api.js +7 -18
  55. package/dist/lib/app-logs/app-logs.js +2 -9
  56. package/dist/lib/app.js +2 -5
  57. package/dist/lib/cli/apiConfig.js +4 -19
  58. package/dist/lib/cli/command.js +43 -133
  59. package/dist/lib/cli/config.js +1 -5
  60. package/dist/lib/cli/envAlias.js +14 -15
  61. package/dist/lib/cli/exit.js +4 -6
  62. package/dist/lib/cli/format.js +8 -50
  63. package/dist/lib/cli/progress.js +13 -42
  64. package/dist/lib/cli/prompt.js +1 -5
  65. package/dist/lib/cli/repo.js +7 -20
  66. package/dist/lib/client-file-uploader.js +44 -97
  67. package/dist/lib/config/software.js +2 -52
  68. package/dist/lib/constants/dev-environment.js +1 -2
  69. package/dist/lib/constants/file-size.js +1 -1
  70. package/dist/lib/constants/vipgo.js +1 -1
  71. package/dist/lib/dev-environment/dev-environment-cli.js +140 -195
  72. package/dist/lib/dev-environment/dev-environment-core.js +91 -186
  73. package/dist/lib/dev-environment/dev-environment-lando.js +32 -96
  74. package/dist/lib/env.js +1 -4
  75. package/dist/lib/envvar/api-delete.js +1 -4
  76. package/dist/lib/envvar/api-get-all.js +1 -4
  77. package/dist/lib/envvar/api-get.js +1 -2
  78. package/dist/lib/envvar/api-list.js +3 -4
  79. package/dist/lib/envvar/api-set.js +1 -4
  80. package/dist/lib/envvar/api.js +5 -16
  81. package/dist/lib/envvar/input.js +1 -8
  82. package/dist/lib/envvar/logging.js +2 -6
  83. package/dist/lib/envvar/read-file.js +1 -3
  84. package/dist/lib/http/proxy-agent.js +17 -22
  85. package/dist/lib/keychain/browser.js +1 -4
  86. package/dist/lib/keychain/insecure.js +1 -10
  87. package/dist/lib/keychain/secure.js +1 -8
  88. package/dist/lib/keychain.js +4 -8
  89. package/dist/lib/logout.js +0 -6
  90. package/dist/lib/media-import/media-file-import.js +3 -7
  91. package/dist/lib/media-import/progress.js +6 -17
  92. package/dist/lib/media-import/status.js +14 -65
  93. package/dist/lib/read-file.js +1 -6
  94. package/dist/lib/rollbar.js +1 -7
  95. package/dist/lib/search-and-replace.js +9 -41
  96. package/dist/lib/site-import/db-file-import.js +3 -9
  97. package/dist/lib/site-import/status.js +17 -74
  98. package/dist/lib/token.js +1 -33
  99. package/dist/lib/tracker.js +4 -20
  100. package/dist/lib/user-error.js +0 -2
  101. package/dist/lib/validations/is-multi-site-sql-dump.js +4 -12
  102. package/dist/lib/validations/is-multi-site.js +5 -21
  103. package/dist/lib/validations/is-multisite-domain-mapped.js +5 -31
  104. package/dist/lib/validations/line-by-line.js +4 -16
  105. package/dist/lib/validations/site-type.js +10 -19
  106. package/dist/lib/validations/sql.js +11 -76
  107. package/dist/lib/validations/utils.js +1 -6
  108. package/dist/lib/vip-import-validate-files.js +82 -109
  109. package/npm-shrinkwrap.json +894 -357
  110. package/package.json +5 -2
@@ -4,16 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  /**
9
8
  * Internal dependencies
10
9
  */
10
+
11
11
  class AnalyticsClientStub {
12
12
  // eslint-disable-next-line no-unused-vars
13
13
  trackEvent(name, props) {
14
14
  return new Promise(resolve => resolve(true));
15
15
  }
16
-
17
16
  }
18
-
19
17
  exports.default = AnalyticsClientStub;
@@ -4,37 +4,35 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
9
-
10
8
  var _querystring = _interopRequireDefault(require("querystring"));
11
-
12
9
  var _apiConfig = require("../../cli/apiConfig");
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
11
 
16
12
  /**
17
13
  * External dependencies
18
14
  */
15
+
19
16
  const debug = require('debug')('@automattic/vip:analytics:clients:tracks');
17
+
20
18
  /**
21
19
  * Internal dependencies
22
20
  */
23
21
 
24
-
25
22
  const validEventOrPropNamePattern = /^[a-z_][a-z0-9_]*$/;
23
+
26
24
  /**
27
25
  * Simple class for tracking using Automattic Tracks.
28
26
  *
29
27
  * Implementation reference can be found in the Field Guide.
30
28
  */
29
+
31
30
  // TODO: add batch support (can include multiples in `events` array)
32
31
 
33
32
  class Tracks {
34
33
  static get ENDPOINT() {
35
34
  return 'https://public-api.wordpress.com/rest/v1.1/tracks/record';
36
35
  }
37
-
38
36
  constructor(userId, userType, eventPrefix, env) {
39
37
  this.eventPrefix = eventPrefix;
40
38
  this.userAgent = env.userAgent;
@@ -44,16 +42,13 @@ class Tracks {
44
42
  'commonProps[_via_ua]': this.userAgent
45
43
  };
46
44
  }
47
-
48
45
  async trackEvent(name, eventProps = {}) {
49
46
  if (!name.startsWith(this.eventPrefix)) {
50
47
  name = this.eventPrefix + name;
51
48
  }
52
-
53
49
  if (!validEventOrPropNamePattern.test(name)) {
54
50
  debug(`Error: Invalid event name detected: ${name} -- this event will be rejected during ETL`);
55
51
  }
56
-
57
52
  Object.keys(eventProps).forEach(propName => {
58
53
  if (!validEventOrPropNamePattern.test(propName)) {
59
54
  debug(`Error: Invalid prop name detected: ${propName} -- this event will be rejected during ETL`);
@@ -63,9 +58,11 @@ class Tracks {
63
58
 
64
59
  const event = Object.assign({
65
60
  _en: name
66
- }, eventProps); // For when we want to support batched events
61
+ }, eventProps);
67
62
 
63
+ // For when we want to support batched events
68
64
  const events = [event];
65
+
69
66
  /**
70
67
  * The API expects an indexed events array with event data.
71
68
  *
@@ -78,7 +75,6 @@ class Tracks {
78
75
  * - events[0][buttonName]=Deploy // event custom prop
79
76
  * - events[1][_en]=loadPage
80
77
  */
81
-
82
78
  const params = events.reduce((reduced, ev, index) => {
83
79
  Object.keys(ev).forEach(key => {
84
80
  const param = `events[${index}][${key}]`;
@@ -88,36 +84,31 @@ class Tracks {
88
84
  return reduced;
89
85
  }, {});
90
86
  debug('trackEvent()', params);
91
-
92
87
  try {
93
88
  return await this.send(params);
94
89
  } catch (error) {
95
90
  debug(error);
96
- } // Resolve to false instead of rejecting
97
-
91
+ }
98
92
 
93
+ // Resolve to false instead of rejecting
99
94
  return Promise.resolve(false);
100
95
  }
101
-
102
96
  send(extraParams) {
103
97
  const params = Object.assign({}, this.baseParams, extraParams);
104
98
  const method = 'POST';
105
-
106
99
  const body = _querystring.default.stringify(params);
107
-
108
100
  const headers = {
109
101
  'Content-Type': 'application/x-www-form-urlencoded',
110
102
  'User-Agent': this.userAgent
111
103
  };
112
- debug('send()', body); // eslint-disable-next-line no-undef
104
+ debug('send()', body);
113
105
 
106
+ // eslint-disable-next-line no-undef
114
107
  return (0, _nodeFetch.default)(Tracks.ENDPOINT, {
115
108
  method,
116
109
  body,
117
110
  headers
118
111
  });
119
112
  }
120
-
121
113
  }
122
-
123
114
  exports.default = Tracks;
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _debug = _interopRequireDefault(require("debug"));
9
-
10
8
  var _stub = _interopRequireDefault(require("./clients/stub"));
11
-
12
9
  var _env = _interopRequireDefault(require("../env"));
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  /**
17
12
  * External dependencies
18
13
  */
@@ -20,9 +15,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
20
15
  /**
21
16
  * Internal dependencies
22
17
  */
18
+
23
19
  const debug = (0, _debug.default)('@automattic/vip:analytics');
24
- /* eslint-disable camelcase */
25
20
 
21
+ /* eslint-disable camelcase */
26
22
  const client_info = {
27
23
  cli_version: _env.default.app.version,
28
24
  os_name: _env.default.os.name,
@@ -37,21 +33,18 @@ class Analytics {
37
33
  }) {
38
34
  this.clients = clients;
39
35
  }
40
-
41
36
  async trackEvent(name, props = {}) {
42
37
  if (process.env.DO_NOT_TRACK) {
43
38
  debug(`trackEvent() for ${name} => skipping per DO_NOT_TRACK variable`);
44
39
  return Promise.resolve(`Skipping trackEvent for ${name} (DO_NOT_TRACK)`);
45
40
  }
46
-
47
41
  return Promise.all(this.clients.map(client => {
48
- return client.trackEvent(name, { // eslint-disable-next-line camelcase
42
+ return client.trackEvent(name, {
43
+ // eslint-disable-next-line camelcase
49
44
  ...client_info,
50
45
  ...props
51
46
  });
52
47
  }));
53
48
  }
54
-
55
49
  }
56
-
57
50
  exports.default = Analytics;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = _default;
7
-
8
7
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
9
-
10
8
  var _api = _interopRequireDefault(require("../api"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
10
 
14
11
  /**
@@ -18,17 +15,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
18
15
  /**
19
16
  * Internal dependencies
20
17
  */
18
+
21
19
  async function _default(app, fields, fragments) {
22
20
  if (!fields) {
23
21
  fields = 'id,name';
24
22
  }
25
-
26
23
  if (!fragments) {
27
24
  fragments = '';
28
25
  }
29
-
30
26
  const api = await (0, _api.default)();
31
-
32
27
  if (isNaN(app)) {
33
28
  const res = await api.query({
34
29
  // $FlowFixMe: gql template is not supported by flow
@@ -46,14 +41,11 @@ async function _default(app, fields, fragments) {
46
41
  name: app
47
42
  }
48
43
  });
49
-
50
44
  if (!res || !res.data || !res.data.apps || !res.data.apps.edges || !res.data.apps.edges.length) {
51
45
  return {};
52
46
  }
53
-
54
47
  return res.data.apps.edges[0];
55
48
  }
56
-
57
49
  app = parseInt(app, 10);
58
50
  const res = await api.query({
59
51
  // $FlowFixMe: gql template is not supported by flow
@@ -67,10 +59,8 @@ async function _default(app, fields, fragments) {
67
59
  id: app
68
60
  }
69
61
  });
70
-
71
62
  if (!res || !res.data || !res.data.app) {
72
63
  return {};
73
64
  }
74
-
75
65
  return res.data.app;
76
66
  }
@@ -3,15 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.purgeCache = purgeCache;
7
6
  exports.appQuery = void 0;
8
-
7
+ exports.purgeCache = purgeCache;
9
8
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
10
-
11
9
  var _api = _interopRequireDefault(require("../api"));
12
-
13
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
11
  /**
16
12
  *
17
13
  * @format
@@ -24,6 +20,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
24
20
  /**
25
21
  * Internal dependencies
26
22
  */
23
+
27
24
  const mutation = (0, _graphqlTag.default)`
28
25
  mutation PurgePageCacheMutation(
29
26
  $appId: Int!
@@ -39,8 +36,9 @@ const mutation = (0, _graphqlTag.default)`
39
36
  urls
40
37
  }
41
38
  }
42
- `; // The subquery for environments lets users choose any environment, including production.
39
+ `;
43
40
 
41
+ // The subquery for environments lets users choose any environment, including production.
44
42
  const appQuery = `
45
43
  id
46
44
  name
@@ -55,7 +53,6 @@ const appQuery = `
55
53
  }
56
54
  `;
57
55
  exports.appQuery = appQuery;
58
-
59
56
  async function purgeCache(appId, envId, urls) {
60
57
  const api = await (0, _api.default)();
61
58
  const variables = {
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.get = get;
7
-
8
7
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
9
-
10
8
  var _api = _interopRequireDefault(require("../api"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
10
 
14
11
  /**
@@ -18,6 +15,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
18
15
  /**
19
16
  * Internal dependencies
20
17
  */
18
+
21
19
  let api;
22
20
  (0, _api.default)().then(client => {
23
21
  api = client;
@@ -29,7 +27,6 @@ const isVipQuery = (0, _graphqlTag.default)`
29
27
  }
30
28
  }
31
29
  `;
32
-
33
30
  async function get() {
34
31
  const res = await api.query({
35
32
  query: isVipQuery,
@@ -4,19 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
9
-
10
8
  var _token = _interopRequireDefault(require("../token"));
11
-
12
9
  var _env = _interopRequireDefault(require("../env"));
13
-
14
10
  var _proxyAgent = require("../http/proxy-agent");
15
-
16
11
  var _api = require("../api");
17
-
18
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
13
  /**
21
14
  * External dependencies
22
15
  */
@@ -24,7 +17,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
24
17
  /**
25
18
  * Internal dependencies
26
19
  */
20
+
27
21
  const debug = require('debug')('@automattic/vip:http');
22
+
28
23
  /**
29
24
  * Call the Public API with an arbitrary path (e.g. to connect to REST endpoints).
30
25
  * This will include the token in an Authorization header so requests are "logged-in."
@@ -35,16 +30,14 @@ const debug = require('debug')('@automattic/vip:http');
35
30
  * @param {object} options options to pass to `fetch`
36
31
  * @returns {Promise} Return value of the `fetch` call
37
32
  */
38
-
39
-
40
33
  var _default = async (path, options = {}) => {
41
- let url = path; // For convenience, we support just passing in the path to this function...
42
- // but some things (Apollo) always pass the full url
34
+ let url = path;
43
35
 
36
+ // For convenience, we support just passing in the path to this function...
37
+ // but some things (Apollo) always pass the full url
44
38
  if (!path.startsWith(_api.API_HOST)) {
45
39
  url = `${_api.API_HOST}${path}`;
46
40
  }
47
-
48
41
  const authToken = await _token.default.get();
49
42
  const headers = {
50
43
  'User-Agent': _env.default.userAgent,
@@ -52,10 +45,12 @@ var _default = async (path, options = {}) => {
52
45
  };
53
46
  const proxyAgent = (0, _proxyAgent.createProxyAgent)(url);
54
47
  debug('running fetch', url);
55
- return (0, _nodeFetch.default)(url, { ...options,
48
+ return (0, _nodeFetch.default)(url, {
49
+ ...options,
56
50
  ...{
57
51
  agent: proxyAgent,
58
- headers: { ...headers,
52
+ headers: {
53
+ ...headers,
59
54
  ...{
60
55
  'Content-Type': 'application/json'
61
56
  },
@@ -67,5 +62,4 @@ var _default = async (path, options = {}) => {
67
62
  }
68
63
  });
69
64
  };
70
-
71
65
  exports.default = _default;
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getCurrentUserInfo = getCurrentUserInfo;
7
-
8
7
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
9
-
10
8
  var _api = _interopRequireDefault(require("../api"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  /**
15
11
  *
16
12
  * @format
@@ -23,6 +19,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
23
19
  /**
24
20
  * Internal dependencies
25
21
  */
22
+
26
23
  const QUERY_CURRENT_USER = (0, _graphqlTag.default)`
27
24
  query Me {
28
25
  me {
@@ -38,7 +35,6 @@ const QUERY_CURRENT_USER = (0, _graphqlTag.default)`
38
35
  }
39
36
  }
40
37
  `;
41
-
42
38
  async function getCurrentUserInfo() {
43
39
  const api = await (0, _api.default)();
44
40
  const response = await api.query({
@@ -49,10 +45,8 @@ async function getCurrentUserInfo() {
49
45
  me
50
46
  }
51
47
  } = response;
52
-
53
48
  if (!me) {
54
49
  throw new Error('The API did not return any information about the user.');
55
50
  }
56
-
57
51
  return me;
58
52
  }
package/dist/lib/api.js CHANGED
@@ -3,28 +3,19 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.disableGlobalGraphQLErrorHandling = disableGlobalGraphQLErrorHandling;
6
+ exports.PRODUCTION_API_HOST = exports.API_URL = exports.API_HOST = void 0;
7
7
  exports.default = API;
8
- exports.API_URL = exports.API_HOST = exports.PRODUCTION_API_HOST = void 0;
9
-
8
+ exports.disableGlobalGraphQLErrorHandling = disableGlobalGraphQLErrorHandling;
9
+ exports.enableGlobalGraphQLErrorHandling = enableGlobalGraphQLErrorHandling;
10
10
  var _core = require("@apollo/client/core");
11
-
12
11
  var _core2 = require("@apollo/client/link/core");
13
-
14
12
  var _context = require("@apollo/client/link/context");
15
-
16
13
  var _error = require("@apollo/client/link/error");
17
-
18
14
  var _chalk = _interopRequireDefault(require("chalk"));
19
-
20
15
  var _token = _interopRequireDefault(require("./token"));
21
-
22
16
  var _env = _interopRequireDefault(require("./env"));
23
-
24
17
  var _proxyAgent = require("./http/proxy-agent");
25
-
26
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
-
28
19
  /**
29
20
  *
30
21
  * @format
@@ -37,6 +28,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
37
28
  /**
38
29
  * Internal dependencies
39
30
  */
31
+
40
32
  // Config
41
33
  const PRODUCTION_API_HOST = 'https://api.wpvip.com';
42
34
  exports.PRODUCTION_API_HOST = PRODUCTION_API_HOST;
@@ -45,11 +37,12 @@ exports.API_HOST = API_HOST;
45
37
  const API_URL = `${API_HOST}/graphql`;
46
38
  exports.API_URL = API_URL;
47
39
  let globalGraphQLErrorHandlingEnabled = true;
48
-
49
40
  function disableGlobalGraphQLErrorHandling() {
50
41
  globalGraphQLErrorHandlingEnabled = false;
51
42
  }
52
-
43
+ function enableGlobalGraphQLErrorHandling() {
44
+ globalGraphQLErrorHandlingEnabled = true;
45
+ }
53
46
  async function API({
54
47
  exitOnError = true
55
48
  } = {}) {
@@ -66,12 +59,10 @@ async function API({
66
59
  console.error(_chalk.default.red('Unauthorized:'), 'You are unauthorized to perform this request, please logout with `vip logout` then try again.');
67
60
  process.exit();
68
61
  }
69
-
70
62
  if (graphQLErrors && graphQLErrors.length && globalGraphQLErrorHandlingEnabled) {
71
63
  graphQLErrors.forEach(error => {
72
64
  console.error(_chalk.default.red('Error:'), error.message);
73
65
  });
74
-
75
66
  if (exitOnError) {
76
67
  process.exit();
77
68
  }
@@ -95,9 +86,7 @@ async function API({
95
86
  return forward(operation);
96
87
  });
97
88
  const proxyAgent = (0, _proxyAgent.createProxyAgent)(API_URL);
98
-
99
89
  const http = require("./api/http").default;
100
-
101
90
  const httpLink = new _core.HttpLink({
102
91
  uri: API_URL,
103
92
  headers,
@@ -3,15 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getRecentLogs = getRecentLogs;
7
6
  exports.LIMIT_MAX = void 0;
8
-
7
+ exports.getRecentLogs = getRecentLogs;
9
8
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
10
-
11
9
  var _api = _interopRequireDefault(require("../api"));
12
-
13
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
11
  /**
16
12
  *
17
13
  * @format
@@ -24,6 +20,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
24
20
  /**
25
21
  * Internal dependencies
26
22
  */
23
+
27
24
  const LIMIT_MAX = 5000;
28
25
  exports.LIMIT_MAX = LIMIT_MAX;
29
26
  const QUERY_ENVIRONMENT_LOGS = (0, _graphqlTag.default)`
@@ -43,10 +40,8 @@ const QUERY_ENVIRONMENT_LOGS = (0, _graphqlTag.default)`
43
40
  }
44
41
  }
45
42
  `;
46
-
47
43
  async function getRecentLogs(appId, envId, type, limit, after) {
48
44
  var _response$data, _response$data$app, _response$data$app$en;
49
-
50
45
  const api = await (0, _api.default)({
51
46
  exitOnError: false
52
47
  });
@@ -61,10 +56,8 @@ async function getRecentLogs(appId, envId, type, limit, after) {
61
56
  }
62
57
  });
63
58
  const logs = response === null || response === void 0 ? void 0 : (_response$data = response.data) === null || _response$data === void 0 ? void 0 : (_response$data$app = _response$data.app) === null || _response$data$app === void 0 ? void 0 : (_response$data$app$en = _response$data$app.environments[0]) === null || _response$data$app$en === void 0 ? void 0 : _response$data$app$en.logs;
64
-
65
59
  if (!(logs !== null && logs !== void 0 && logs.nodes)) {
66
60
  throw new Error('Unable to query logs');
67
61
  }
68
-
69
62
  return logs;
70
63
  }
package/dist/lib/app.js CHANGED
@@ -3,11 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isAppWordPress = isAppWordPress;
7
6
  exports.isAppNodejs = isAppNodejs;
8
-
7
+ exports.isAppWordPress = isAppWordPress;
9
8
  var _vipgo = require("./constants/vipgo");
10
-
11
9
  /**
12
10
  * External dependencies
13
11
  */
@@ -24,13 +22,12 @@ var _vipgo = require("./constants/vipgo");
24
22
  function isAppWordPress(appTypeId) {
25
23
  return _vipgo.WORDPRESS_SITE_TYPE_IDS.includes(appTypeId);
26
24
  }
25
+
27
26
  /**
28
27
  * Is this a Nodejs application?
29
28
  * @param {int} appTypeId application type ID
30
29
  * @constructor
31
30
  */
32
-
33
-
34
31
  function isAppNodejs(appTypeId) {
35
32
  return _vipgo.NODEJS_SITE_TYPE_IDS.includes(appTypeId);
36
33
  }
@@ -6,21 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.checkFeatureEnabled = checkFeatureEnabled;
7
7
  exports.checkIfUserIsVip = checkIfUserIsVip;
8
8
  exports.exitWhenFeatureDisabled = exitWhenFeatureDisabled;
9
-
10
9
  var _tracker = require("../tracker");
11
-
12
10
  var exit = _interopRequireWildcard(require("./exit"));
13
-
14
11
  var featureFlags = _interopRequireWildcard(require("../api/feature-flags"));
15
-
16
12
  var _token = _interopRequireDefault(require("../token"));
17
-
18
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
-
22
15
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
-
24
16
  /**
25
17
  *
26
18
  * @format
@@ -33,6 +25,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
33
25
  /**
34
26
  * Internal dependencies
35
27
  */
28
+
36
29
  async function checkFeatureEnabled(featureName, exitOnFalse = false) {
37
30
  // TODO: eventually let's look at more feature flags coming from the public api,
38
31
  // for now, let's see if the user of the CLI is VIP
@@ -43,9 +36,7 @@ async function checkFeatureEnabled(featureName, exitOnFalse = false) {
43
36
  const isVIP = await new Promise(async resolve => {
44
37
  try {
45
38
  var _res$data, _res$data$me;
46
-
47
39
  const res = await featureFlags.get();
48
-
49
40
  if ((res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : (_res$data$me = _res$data.me) === null || _res$data$me === void 0 ? void 0 : _res$data$me.isVIP) !== undefined) {
50
41
  resolve(res.data.me.isVIP);
51
42
  } else {
@@ -61,30 +52,24 @@ async function checkFeatureEnabled(featureName, exitOnFalse = false) {
61
52
  exit.withError('Failed to determine if feature is enabled' + message);
62
53
  }
63
54
  });
64
-
65
55
  if (exitOnFalse === true && isVIP === false) {
66
56
  exit.withError('The feature you are attempting to use is not currently enabled.');
67
57
  }
68
-
69
58
  return isVIP === true;
70
- } // Because this function is called by trackEvent:
59
+ }
60
+
61
+ // Because this function is called by trackEvent:
71
62
  // - It cannot directly or indirectly call trackEvent, or it will cause a loop.
72
63
  // - It is mocked globally in jest.setupMocks.js.
73
-
74
-
75
64
  async function checkIfUserIsVip() {
76
65
  const token = await _token.default.get();
77
-
78
66
  if (token && token.valid()) {
79
67
  var _res$data2, _res$data2$me;
80
-
81
68
  const res = await featureFlags.get();
82
69
  return !!(res !== null && res !== void 0 && (_res$data2 = res.data) !== null && _res$data2 !== void 0 && (_res$data2$me = _res$data2.me) !== null && _res$data2$me !== void 0 && _res$data2$me.isVIP);
83
70
  }
84
-
85
71
  return false;
86
72
  }
87
-
88
73
  async function exitWhenFeatureDisabled(featureName) {
89
74
  return checkFeatureEnabled(featureName, true);
90
75
  }