@commercetools-frontend/mc-scripts 21.18.0 → 21.19.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 (43) hide show
  1. package/bin/cli.js +6 -1
  2. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +318 -295
  3. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +318 -295
  4. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +317 -294
  5. package/dist/{build-70142b7e.esm.js → build-20d77feb.esm.js} +3 -3
  6. package/dist/{build-5fb0fc10.cjs.prod.js → build-b1030e29.cjs.prod.js} +3 -3
  7. package/dist/{build-6f94dc3b.cjs.dev.js → build-c1a3c8cd.cjs.dev.js} +3 -3
  8. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +1 -1
  9. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +1 -1
  10. package/dist/commercetools-frontend-mc-scripts.esm.js +1 -1
  11. package/dist/{config-sync-5987fd39.cjs.dev.js → config-sync-2263c2ec.cjs.dev.js} +259 -137
  12. package/dist/{config-sync-0844f13b.esm.js → config-sync-6a39d2e3.esm.js} +255 -134
  13. package/dist/{config-sync-27736a53.cjs.prod.js → config-sync-edec607e.cjs.prod.js} +259 -137
  14. package/dist/{create-postcss-config-9b9a988c.cjs.dev.js → create-postcss-config-3a117693.cjs.dev.js} +1 -1
  15. package/dist/{create-postcss-config-0c7dbb5c.esm.js → create-postcss-config-6dcc86ab.esm.js} +1 -1
  16. package/dist/{create-postcss-config-b8604cd6.cjs.prod.js → create-postcss-config-ef589644.cjs.prod.js} +1 -1
  17. package/dist/{create-webpack-config-for-development-5b4f9f05.cjs.dev.js → create-webpack-config-for-development-28510e96.cjs.dev.js} +1 -1
  18. package/dist/{create-webpack-config-for-development-10c389cd.esm.js → create-webpack-config-for-development-a29fdeee.esm.js} +1 -1
  19. package/dist/{create-webpack-config-for-development-bd88930a.cjs.prod.js → create-webpack-config-for-development-fa017d55.cjs.prod.js} +1 -1
  20. package/dist/{create-webpack-config-for-production-e80b6fc7.cjs.prod.js → create-webpack-config-for-production-15e6365d.cjs.prod.js} +1 -1
  21. package/dist/{create-webpack-config-for-production-2c77e9fe.esm.js → create-webpack-config-for-production-39453789.esm.js} +1 -1
  22. package/dist/{create-webpack-config-for-production-48ad7e6a.cjs.dev.js → create-webpack-config-for-production-dfcafa81.cjs.dev.js} +1 -1
  23. package/dist/declarations/src/cli.d.ts +1 -1
  24. package/dist/declarations/src/utils/graphql-requests.d.ts +4 -8
  25. package/dist/{login-ce9906f4.esm.js → login-bdc2976a.esm.js} +17 -15
  26. package/dist/{login-c7baca5e.cjs.prod.js → login-dad3f3b8.cjs.prod.js} +17 -15
  27. package/dist/{login-bf79b277.cjs.dev.js → login-ed5c7f5e.cjs.dev.js} +17 -15
  28. package/dist/{package-663c0f80.cjs.prod.js → package-19e5588c.cjs.dev.js} +9 -8
  29. package/dist/{package-3ac48b2d.esm.js → package-47ad699b.esm.js} +9 -8
  30. package/dist/{package-bec920c0.cjs.dev.js → package-bbd49c17.cjs.prod.js} +9 -8
  31. package/dist/{start-70f1d650.cjs.dev.js → start-31119852.cjs.dev.js} +3 -3
  32. package/dist/{start-598dab76.esm.js → start-7ca70f00.esm.js} +3 -3
  33. package/dist/{start-9d376be4.cjs.prod.js → start-a2641c71.cjs.prod.js} +3 -3
  34. package/dist/{user-agent-cf9eb504.esm.js → user-agent-0a7ca83a.esm.js} +1 -1
  35. package/dist/{user-agent-d9cc2dfa.cjs.prod.js → user-agent-4b9aa874.cjs.prod.js} +1 -1
  36. package/dist/{user-agent-56268751.cjs.dev.js → user-agent-ff2423ef.cjs.dev.js} +1 -1
  37. package/package.json +9 -8
  38. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +2 -2
  39. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +2 -2
  40. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +2 -2
  41. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +4 -4
  42. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +4 -4
  43. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +4 -4
@@ -4,26 +4,28 @@ import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
4
4
  import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
5
5
  import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
6
6
  import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
7
+ import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
7
8
  import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
8
9
  import omit from 'lodash/omit';
9
10
  import prompts from 'prompts';
10
11
  import chalk from 'chalk';
11
12
  import { sanitizeSvg, processConfig } from '@commercetools-frontend/application-config';
12
- import { u as userAgent, C as CredentialsStorage } from './user-agent-cf9eb504.esm.js';
13
- import { GraphQLClient } from 'graphql-request';
14
- import { GRAPHQL_TARGETS } from '@commercetools-frontend/constants';
13
+ import { C as CredentialsStorage, u as userAgent } from './user-agent-0a7ca83a.esm.js';
14
+ import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
15
+ import _someInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/some';
16
+ import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
15
17
  import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
16
18
  import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
19
+ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
17
20
  import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
18
21
  import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
19
22
  import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
20
- import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
23
+ import { print } from 'graphql';
24
+ import { GraphQLClient, ClientError } from 'graphql-request';
25
+ import { GRAPHQL_TARGETS } from '@commercetools-frontend/constants';
21
26
  import _repeatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/repeat';
22
27
  import _Set from '@babel/runtime-corejs3/core-js-stable/set';
23
- import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
24
28
  import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
25
- import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
26
- import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
27
29
  import '@babel/runtime-corejs3/helpers/classCallCheck';
28
30
  import '@babel/runtime-corejs3/helpers/createClass';
29
31
  import '@babel/runtime-corejs3/core-js-stable/date/now';
@@ -31,45 +33,144 @@ import 'fs';
31
33
  import 'path';
32
34
  import 'os';
33
35
  import '@commercetools/http-user-agent';
34
- import './package-3ac48b2d.esm.js';
36
+ import './package-47ad699b.esm.js';
37
+
38
+ function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
35
39
 
40
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context7, _context8; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context7 = ownKeys$1(Object(source), !0)).call(_context7, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context8 = ownKeys$1(Object(source))).call(_context8, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
36
41
  var FetchCustomApplicationFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchCustomApplicationFromCli" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "entryPointUriPath" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "organizationExtensionForCustomApplication" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "entryPointUriPath" }, value: { kind: "Variable", name: { kind: "Name", value: "entryPointUriPath" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "organizationId" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "application" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "entryPointUriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "description" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "url" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "icon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "oAuthScopes" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "mainMenuLink" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "defaultLabel" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }] } }, { kind: "Field", name: { kind: "Name", value: "submenuLinks" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "defaultLabel" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }] } }] } }] } }] } }], loc: { start: 0, end: 647, source: { body: "query FetchCustomApplicationFromCli($entryPointUriPath: String!) {\n organizationExtensionForCustomApplication(\n entryPointUriPath: $entryPointUriPath\n ) {\n organizationId\n application {\n id\n entryPointUriPath\n name\n description\n url\n icon\n permissions {\n name\n oAuthScopes\n }\n mainMenuLink {\n defaultLabel\n permissions\n labelAllLocales {\n locale\n value\n }\n }\n submenuLinks {\n uriPath\n defaultLabel\n permissions\n labelAllLocales {\n locale\n value\n }\n }\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
37
42
  var UpdateCustomApplicationFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "mutation", name: { kind: "Name", value: "UpdateCustomApplicationFromCli" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "organizationId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "data" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "CustomApplicationDraftDataInput" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "applicationId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "ID" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "updateCustomApplication" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "organizationId" }, value: { kind: "Variable", name: { kind: "Name", value: "organizationId" } } }, { kind: "Argument", name: { kind: "Name", value: "data" }, value: { kind: "Variable", name: { kind: "Name", value: "data" } } }, { kind: "Argument", name: { kind: "Name", value: "applicationId" }, value: { kind: "Variable", name: { kind: "Name", value: "applicationId" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }] } }] } }], loc: { start: 0, end: 268, source: { body: "mutation UpdateCustomApplicationFromCli(\n $organizationId: String!\n $data: CustomApplicationDraftDataInput!\n $applicationId: ID!\n) {\n updateCustomApplication(\n organizationId: $organizationId\n data: $data\n applicationId: $applicationId\n ) {\n id\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
38
43
  var CreateCustomApplicationFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "mutation", name: { kind: "Name", value: "CreateCustomApplicationFromCli" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "organizationId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "data" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "CustomApplicationDraftDataInput" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "createCustomApplication" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "organizationId" }, value: { kind: "Variable", name: { kind: "Name", value: "organizationId" } } }, { kind: "Argument", name: { kind: "Name", value: "data" }, value: { kind: "Variable", name: { kind: "Name", value: "data" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }] } }] } }], loc: { start: 0, end: 201, source: { body: "mutation CreateCustomApplicationFromCli(\n $organizationId: String!\n $data: CustomApplicationDraftDataInput!\n) {\n createCustomApplication(organizationId: $organizationId, data: $data) {\n id\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
39
44
  var FetchMyOrganizationsFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchMyOrganizationsFromCli" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "myOrganizations" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "total" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "results" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }] } }] } }], loc: { start: 0, end: 112, source: { body: "query FetchMyOrganizationsFromCli {\n myOrganizations {\n total\n results {\n id\n name\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
45
+ var credentialsStorage$1 = new CredentialsStorage();
46
+ var client = new GraphQLClient('', // <-- Set on demand
47
+ {
48
+ headers: {
49
+ Accept: 'application/json',
50
+ 'Content-Type': 'application/json',
51
+ 'x-user-agent': userAgent
52
+ }
53
+ });
40
54
 
41
- var graphQLClient = function graphQLClient(url, token) {
42
- var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : GRAPHQL_TARGETS.SETTINGS_SERVICE;
43
- return new GraphQLClient("".concat(url, "/graphql"), {
44
- headers: {
45
- Accept: 'application/json',
46
- 'Content-Type': 'application/json',
47
- 'x-graphql-target': target,
48
- 'x-mc-cli-access-token': token,
49
- 'x-user-agent': userAgent
50
- }
51
- });
52
- };
55
+ function requestWithTokenRetry(_x, _x2) {
56
+ return _requestWithTokenRetry.apply(this, arguments);
57
+ }
58
+
59
+ function _requestWithTokenRetry() {
60
+ _requestWithTokenRetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(document, requestOptions) {
61
+ var retryCount,
62
+ token,
63
+ result,
64
+ refreshedSessionToken,
65
+ refreshedSessionTokenExpiresAt,
66
+ _context5,
67
+ isUnauthorizedError,
68
+ _args5 = arguments;
69
+
70
+ return _regeneratorRuntime.wrap(function _callee5$(_context6) {
71
+ while (1) {
72
+ switch (_context6.prev = _context6.next) {
73
+ case 0:
74
+ retryCount = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : 0;
75
+ token = credentialsStorage$1.getToken(requestOptions.mcApiUrl);
76
+ client.setEndpoint("".concat(requestOptions.mcApiUrl, "/graphql"));
77
+ client.setHeaders(requestOptions.headers);
78
+
79
+ if (token) {
80
+ client.setHeader('x-mc-cli-access-token', token);
81
+ }
82
+
83
+ _context6.prev = 5;
84
+ _context6.next = 8;
85
+ return client.rawRequest(print(document), requestOptions.variables);
86
+
87
+ case 8:
88
+ result = _context6.sent;
89
+ // In case a new session token is returned from the server, save it.
90
+ refreshedSessionToken = result.headers.get('x-refreshed-session-token');
91
+
92
+ if (refreshedSessionToken) {
93
+ console.log(chalk.green('Session token refreshed.'));
94
+ console.log();
95
+ refreshedSessionTokenExpiresAt = result.headers.get('x-refreshed-session-token-expires-at'); // Store the updated access token.
96
+
97
+ credentialsStorage$1.setToken(requestOptions.mcApiUrl, {
98
+ token: refreshedSessionToken,
99
+ expiresAt: Number(refreshedSessionTokenExpiresAt)
100
+ });
101
+ }
102
+
103
+ return _context6.abrupt("return", result.data);
104
+
105
+ case 14:
106
+ _context6.prev = 14;
107
+ _context6.t0 = _context6["catch"](5);
108
+
109
+ if (!(_context6.t0 instanceof ClientError)) {
110
+ _context6.next = 22;
111
+ break;
112
+ }
113
+
114
+ if (!(retryCount === 0 && _context6.t0.response.errors && _context6.t0.response.errors.length > 0)) {
115
+ _context6.next = 22;
116
+ break;
117
+ }
118
+
119
+ isUnauthorizedError = _someInstanceProperty(_context5 = _context6.t0.response.errors).call(_context5, function (graphqlError) {
120
+ var _graphqlError$extensi;
121
+
122
+ return ((_graphqlError$extensi = graphqlError.extensions) === null || _graphqlError$extensi === void 0 ? void 0 : _graphqlError$extensi.code) === 'UNAUTHENTICATED';
123
+ });
124
+
125
+ if (!isUnauthorizedError) {
126
+ _context6.next = 22;
127
+ break;
128
+ }
129
+
130
+ console.log(chalk.yellow('Expired or invalid session token, attempting to retry the request with a refreshed token...'));
131
+ return _context6.abrupt("return", requestWithTokenRetry(document, _objectSpread$1(_objectSpread$1({}, requestOptions), {}, {
132
+ headers: _objectSpread$1(_objectSpread$1({}, requestOptions.headers), {}, {
133
+ 'X-Force-Token': 'true'
134
+ })
135
+ }), retryCount + 1));
136
+
137
+ case 22:
138
+ throw _context6.t0;
139
+
140
+ case 23:
141
+ case "end":
142
+ return _context6.stop();
143
+ }
144
+ }
145
+ }, _callee5, null, [[5, 14]]);
146
+ }));
147
+ return _requestWithTokenRetry.apply(this, arguments);
148
+ }
53
149
 
54
150
  var fetchCustomApplication = /*#__PURE__*/function () {
55
151
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
56
- var mcApiUrl, token, entryPointUriPath, variables, customAppData;
152
+ var mcApiUrl, entryPointUriPath, customAppData;
57
153
  return _regeneratorRuntime.wrap(function _callee$(_context) {
58
154
  while (1) {
59
155
  switch (_context.prev = _context.next) {
60
156
  case 0:
61
- mcApiUrl = _ref.mcApiUrl, token = _ref.token, entryPointUriPath = _ref.entryPointUriPath;
62
- variables = {
63
- entryPointUriPath: entryPointUriPath
64
- };
65
- _context.next = 4;
66
- return graphQLClient(mcApiUrl, token).request(FetchCustomApplicationFromCli, variables);
67
-
68
- case 4:
157
+ mcApiUrl = _ref.mcApiUrl, entryPointUriPath = _ref.entryPointUriPath;
158
+ _context.next = 3;
159
+ return requestWithTokenRetry(FetchCustomApplicationFromCli, {
160
+ variables: {
161
+ entryPointUriPath: entryPointUriPath
162
+ },
163
+ mcApiUrl: mcApiUrl,
164
+ headers: {
165
+ 'x-graphql-target': GRAPHQL_TARGETS.SETTINGS_SERVICE
166
+ }
167
+ });
168
+
169
+ case 3:
69
170
  customAppData = _context.sent;
70
171
  return _context.abrupt("return", customAppData.organizationExtensionForCustomApplication);
71
172
 
72
- case 6:
173
+ case 5:
73
174
  case "end":
74
175
  return _context.stop();
75
176
  }
@@ -77,32 +178,37 @@ var fetchCustomApplication = /*#__PURE__*/function () {
77
178
  }, _callee);
78
179
  }));
79
180
 
80
- return function fetchCustomApplication(_x) {
181
+ return function fetchCustomApplication(_x3) {
81
182
  return _ref2.apply(this, arguments);
82
183
  };
83
184
  }();
84
185
 
85
186
  var updateCustomApplication = /*#__PURE__*/function () {
86
187
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
87
- var mcApiUrl, token, applicationId, organizationId, data, variables, updatedCustomAppsData;
188
+ var mcApiUrl, applicationId, organizationId, data, updatedCustomAppsData;
88
189
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
89
190
  while (1) {
90
191
  switch (_context2.prev = _context2.next) {
91
192
  case 0:
92
- mcApiUrl = _ref3.mcApiUrl, token = _ref3.token, applicationId = _ref3.applicationId, organizationId = _ref3.organizationId, data = _ref3.data;
93
- variables = {
94
- organizationId: organizationId,
95
- applicationId: applicationId,
96
- data: data
97
- };
98
- _context2.next = 4;
99
- return graphQLClient(mcApiUrl, token).request(UpdateCustomApplicationFromCli, variables);
193
+ mcApiUrl = _ref3.mcApiUrl, applicationId = _ref3.applicationId, organizationId = _ref3.organizationId, data = _ref3.data;
194
+ _context2.next = 3;
195
+ return requestWithTokenRetry(UpdateCustomApplicationFromCli, {
196
+ variables: {
197
+ organizationId: organizationId,
198
+ applicationId: applicationId,
199
+ data: data
200
+ },
201
+ mcApiUrl: mcApiUrl,
202
+ headers: {
203
+ 'x-graphql-target': GRAPHQL_TARGETS.SETTINGS_SERVICE
204
+ }
205
+ });
100
206
 
101
- case 4:
207
+ case 3:
102
208
  updatedCustomAppsData = _context2.sent;
103
209
  return _context2.abrupt("return", updatedCustomAppsData.updateCustomApplication);
104
210
 
105
- case 6:
211
+ case 5:
106
212
  case "end":
107
213
  return _context2.stop();
108
214
  }
@@ -110,31 +216,36 @@ var updateCustomApplication = /*#__PURE__*/function () {
110
216
  }, _callee2);
111
217
  }));
112
218
 
113
- return function updateCustomApplication(_x2) {
219
+ return function updateCustomApplication(_x4) {
114
220
  return _ref4.apply(this, arguments);
115
221
  };
116
222
  }();
117
223
 
118
224
  var createCustomApplication = /*#__PURE__*/function () {
119
225
  var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5) {
120
- var mcApiUrl, token, organizationId, data, variables, createdCustomAppData;
226
+ var mcApiUrl, organizationId, data, createdCustomAppData;
121
227
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
122
228
  while (1) {
123
229
  switch (_context3.prev = _context3.next) {
124
230
  case 0:
125
- mcApiUrl = _ref5.mcApiUrl, token = _ref5.token, organizationId = _ref5.organizationId, data = _ref5.data;
126
- variables = {
127
- organizationId: organizationId,
128
- data: data
129
- };
130
- _context3.next = 4;
131
- return graphQLClient(mcApiUrl, token).request(CreateCustomApplicationFromCli, variables);
231
+ mcApiUrl = _ref5.mcApiUrl, organizationId = _ref5.organizationId, data = _ref5.data;
232
+ _context3.next = 3;
233
+ return requestWithTokenRetry(CreateCustomApplicationFromCli, {
234
+ variables: {
235
+ organizationId: organizationId,
236
+ data: data
237
+ },
238
+ mcApiUrl: mcApiUrl,
239
+ headers: {
240
+ 'x-graphql-target': GRAPHQL_TARGETS.SETTINGS_SERVICE
241
+ }
242
+ });
132
243
 
133
- case 4:
244
+ case 3:
134
245
  createdCustomAppData = _context3.sent;
135
246
  return _context3.abrupt("return", createdCustomAppData.createCustomApplication);
136
247
 
137
- case 6:
248
+ case 5:
138
249
  case "end":
139
250
  return _context3.stop();
140
251
  }
@@ -142,21 +253,26 @@ var createCustomApplication = /*#__PURE__*/function () {
142
253
  }, _callee3);
143
254
  }));
144
255
 
145
- return function createCustomApplication(_x3) {
256
+ return function createCustomApplication(_x5) {
146
257
  return _ref6.apply(this, arguments);
147
258
  };
148
259
  }();
149
260
 
150
261
  var fetchUserOrganizations = /*#__PURE__*/function () {
151
262
  var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
152
- var mcApiUrl, token, userOrganizations;
263
+ var mcApiUrl, userOrganizations;
153
264
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
154
265
  while (1) {
155
266
  switch (_context4.prev = _context4.next) {
156
267
  case 0:
157
- mcApiUrl = _ref7.mcApiUrl, token = _ref7.token;
268
+ mcApiUrl = _ref7.mcApiUrl;
158
269
  _context4.next = 3;
159
- return graphQLClient(mcApiUrl, token, GRAPHQL_TARGETS.ADMINISTRATION_SERVICE).request(FetchMyOrganizationsFromCli);
270
+ return requestWithTokenRetry(FetchMyOrganizationsFromCli, {
271
+ mcApiUrl: mcApiUrl,
272
+ headers: {
273
+ 'x-graphql-target': GRAPHQL_TARGETS.ADMINISTRATION_SERVICE
274
+ }
275
+ });
160
276
 
161
277
  case 3:
162
278
  userOrganizations = _context4.sent;
@@ -170,7 +286,7 @@ var fetchUserOrganizations = /*#__PURE__*/function () {
170
286
  }, _callee4);
171
287
  }));
172
288
 
173
- return function fetchUserOrganizations(_x4) {
289
+ return function fetchUserOrganizations(_x6) {
174
290
  return _ref8.apply(this, arguments);
175
291
  };
176
292
  }();
@@ -614,225 +730,230 @@ function run(_x) {
614
730
 
615
731
  function _run() {
616
732
  _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
617
- var _context6;
733
+ var _context5;
618
734
 
619
- var applicationConfig, localCustomAppData, mcApiUrl, token, fetchedCustomApplication, _context4, _context5, userOrganizations, organizationId, organizationName, _userOrganizations$re, organization, _context3, organizationChoices, _yield$prompts, selectedOrganizationId, _yield$prompts2, _confirmation, _data, createdCustomApplication, _customAppLink, customAppLink, configDiff, _yield$prompts3, confirmation, data;
735
+ var applicationConfig, localCustomAppData, mcApiUrl, isSessionValid, fetchedCustomApplication, _context4, userOrganizations, organizationId, organizationName, _userOrganizations$re, organization, _context3, organizationChoices, _yield$prompts, selectedOrganizationId, _yield$prompts2, _confirmation, _data, createdCustomApplication, _customAppLink, customAppLink, configDiff, _yield$prompts3, confirmation, data;
620
736
 
621
- return _regeneratorRuntime.wrap(function _callee$(_context7) {
737
+ return _regeneratorRuntime.wrap(function _callee$(_context6) {
622
738
  while (1) {
623
- switch (_context7.prev = _context7.next) {
739
+ switch (_context6.prev = _context6.next) {
624
740
  case 0:
625
741
  applicationConfig = processConfig();
626
742
  localCustomAppData = applicationConfig.data;
627
743
  mcApiUrl = applicationConfig.env.mcApiUrl;
628
- token = credentialsStorage.getToken(mcApiUrl);
744
+ console.log("Using Merchant Center environment \"".concat(chalk.green(mcApiUrl), "\"."));
745
+ console.log();
746
+ isSessionValid = credentialsStorage.isSessionValid(mcApiUrl);
629
747
 
630
- if (token) {
631
- _context7.next = 6;
748
+ if (isSessionValid) {
749
+ _context6.next = 8;
632
750
  break;
633
751
  }
634
752
 
635
- throw new Error("You don't have a valid session for the ".concat(mcApiUrl, " environment. Please, run the \"mc-scripts login\" command to authenticate yourself."));
753
+ throw new Error("You don't have a valid session. Please, run the \"mc-scripts login\" command to authenticate yourself.");
636
754
 
637
- case 6:
638
- _context7.next = 8;
755
+ case 8:
756
+ _context6.next = 10;
639
757
  return fetchCustomApplication({
640
758
  mcApiUrl: mcApiUrl,
641
- token: token,
642
759
  entryPointUriPath: localCustomAppData.entryPointUriPath
643
760
  });
644
761
 
645
- case 8:
646
- fetchedCustomApplication = _context7.sent;
762
+ case 10:
763
+ fetchedCustomApplication = _context6.sent;
647
764
 
648
765
  if (fetchedCustomApplication) {
649
- _context7.next = 51;
766
+ _context6.next = 55;
650
767
  break;
651
768
  }
652
769
 
653
- _context7.next = 12;
770
+ _context6.next = 14;
654
771
  return fetchUserOrganizations({
655
- mcApiUrl: mcApiUrl,
656
- token: token
772
+ mcApiUrl: mcApiUrl
657
773
  });
658
774
 
659
- case 12:
660
- userOrganizations = _context7.sent;
775
+ case 14:
776
+ userOrganizations = _context6.sent;
661
777
 
662
778
  if (!(userOrganizations.total === 0)) {
663
- _context7.next = 15;
779
+ _context6.next = 17;
664
780
  break;
665
781
  }
666
782
 
667
783
  throw new Error("It seems you are not an admin of any Organization. Please make sure to be part of the Administrators team of the Organization you want the Custom Application to be configured to.");
668
784
 
669
- case 15:
785
+ case 17:
670
786
  if (!(userOrganizations.total === 1)) {
671
- _context7.next = 21;
787
+ _context6.next = 23;
672
788
  break;
673
789
  }
674
790
 
675
791
  _userOrganizations$re = _slicedToArray(userOrganizations.results, 1), organization = _userOrganizations$re[0];
676
792
  organizationId = organization.id;
677
793
  organizationName = organization.name;
678
- _context7.next = 30;
794
+ _context6.next = 32;
679
795
  break;
680
796
 
681
- case 21:
797
+ case 23:
682
798
  organizationChoices = _mapInstanceProperty(_context3 = userOrganizations.results).call(_context3, function (organization) {
683
799
  return {
684
800
  title: organization.name,
685
801
  value: organization.id
686
802
  };
687
803
  });
688
- _context7.next = 24;
804
+ _context6.next = 26;
689
805
  return prompts({
690
806
  type: 'select',
691
807
  name: 'organizationId',
692
- message: 'Select Organization',
808
+ message: 'Select an Organization',
693
809
  choices: organizationChoices,
694
810
  initial: 0
695
811
  });
696
812
 
697
- case 24:
698
- _yield$prompts = _context7.sent;
813
+ case 26:
814
+ _yield$prompts = _context6.sent;
699
815
  selectedOrganizationId = _yield$prompts.organizationId;
700
816
 
701
817
  if (selectedOrganizationId) {
702
- _context7.next = 28;
818
+ _context6.next = 30;
703
819
  break;
704
820
  }
705
821
 
706
822
  throw new Error("No Organization selected, aborting.");
707
823
 
708
- case 28:
824
+ case 30:
709
825
  organizationId = selectedOrganizationId;
710
826
  organizationName = _findInstanceProperty(organizationChoices).call(organizationChoices, function (_ref) {
711
827
  var value = _ref.value;
712
828
  return value === organizationId;
713
829
  }).title;
714
830
 
715
- case 30:
716
- _context7.next = 32;
831
+ case 32:
832
+ _context6.next = 34;
717
833
  return prompts({
718
834
  type: 'text',
719
835
  name: 'confirmation',
720
- message: _concatInstanceProperty(_context4 = "You are about to create a new Custom Application in the \"".concat(organizationName, "\" organization for the ")).call(_context4, mcApiUrl, " environment. Are you sure you want to proceed?"),
836
+ message: _filterInstanceProperty(_context4 = ["You are about to create a new Custom Application in the \"".concat(chalk.green(organizationName), "\" organization. Are you sure you want to proceed?"), options.dryRun && chalk.gray('Using "--dry-run", no data will be created.')]).call(_context4, Boolean).join('\n'),
721
837
  initial: 'yes'
722
838
  });
723
839
 
724
- case 32:
725
- _yield$prompts2 = _context7.sent;
840
+ case 34:
841
+ _yield$prompts2 = _context6.sent;
726
842
  _confirmation = _yield$prompts2.confirmation;
727
843
 
728
844
  if (!(!_confirmation || _confirmation.toLowerCase().charAt(0) !== 'y')) {
729
- _context7.next = 37;
845
+ _context6.next = 39;
730
846
  break;
731
847
  }
732
848
 
733
849
  console.log(chalk.red('Aborted.'));
734
- return _context7.abrupt("return");
850
+ return _context6.abrupt("return");
735
851
 
736
- case 37:
852
+ case 39:
737
853
  _data = omit(localCustomAppData, ['id']);
738
854
 
739
855
  if (!options.dryRun) {
740
- _context7.next = 43;
856
+ _context6.next = 46;
741
857
  break;
742
858
  }
743
859
 
744
- console.log(chalk.gray('DRY RUN mode'));
745
- console.log("A new Custom Application would be created for the Organization ".concat(organizationName, " with the following payload:"));
746
- console.log(_JSON$stringify(_data));
747
- return _context7.abrupt("return");
860
+ console.log();
861
+ console.log("The following payload would be used to create a new Custom Application.");
862
+ console.log();
863
+ console.log(chalk.gray(_JSON$stringify(_data, null, 2)));
864
+ return _context6.abrupt("return");
748
865
 
749
- case 43:
750
- _context7.next = 45;
866
+ case 46:
867
+ _context6.next = 48;
751
868
  return createCustomApplication({
752
869
  mcApiUrl: mcApiUrl,
753
- token: token,
754
870
  organizationId: organizationId,
755
871
  data: _data
756
872
  });
757
873
 
758
- case 45:
759
- createdCustomApplication = _context7.sent;
874
+ case 48:
875
+ createdCustomApplication = _context6.sent;
760
876
 
761
877
  if (createdCustomApplication) {
762
- _context7.next = 48;
878
+ _context6.next = 51;
763
879
  break;
764
880
  }
765
881
 
766
882
  throw new Error('Failed to create the Custom Application.');
767
883
 
768
- case 48:
884
+ case 51:
769
885
  _customAppLink = getMcUrlLink(mcApiUrl, organizationId, createdCustomApplication.id);
770
- console.log(chalk.green(_concatInstanceProperty(_context5 = "Custom Application created.\nThe \"applicationId\" in your local Custom Application config file should be updated with the application ID: ".concat(createdCustomApplication.id, ".\nYou can see the Custom Application data in the Merchant Center at ")).call(_context5, _customAppLink, ".")));
771
- return _context7.abrupt("return");
886
+ console.log(chalk.green("Custom Application created.\nPlease update the \"env.production.applicationId\" field in your local Custom Application config file with the following value: \"".concat(chalk.green(createdCustomApplication.id), "\".")));
887
+ console.log("You can inspect the Custom Application data in the Merchant Center at \"".concat(chalk.gray(_customAppLink), "\"."));
888
+ return _context6.abrupt("return");
772
889
 
773
- case 51:
890
+ case 55:
774
891
  customAppLink = getMcUrlLink(mcApiUrl, fetchedCustomApplication.organizationId, fetchedCustomApplication.application.id);
775
892
  configDiff = getConfigDiff(fetchedCustomApplication.application, localCustomAppData);
776
893
 
777
894
  if (configDiff) {
778
- _context7.next = 56;
895
+ _context6.next = 61;
779
896
  break;
780
897
  }
781
898
 
782
- console.log(chalk.green("Custom Application is already up to date.\nYou can see the Custom Application data in the Merchant Center at ".concat(customAppLink, ".")));
783
- return _context7.abrupt("return");
899
+ console.log(chalk.green("Custom Application up-to-date."));
900
+ console.log("You can inspect the Custom Application data in the Merchant Center at \"".concat(chalk.gray(customAppLink), "\"."));
901
+ return _context6.abrupt("return");
784
902
 
785
- case 56:
903
+ case 61:
904
+ console.log('Changes detected:');
786
905
  console.log(configDiff);
787
- _context7.next = 59;
906
+ console.log();
907
+ _context6.next = 66;
788
908
  return prompts({
789
909
  type: 'text',
790
910
  name: 'confirmation',
791
- message: _concatInstanceProperty(_context6 = "You are about to update the Custom Application \"".concat(localCustomAppData.entryPointUriPath, "\" with the changes above, in the ")).call(_context6, mcApiUrl, " environment. Are you sure you want to proceed?"),
911
+ message: _filterInstanceProperty(_context5 = ["You are about to update the Custom Application \"".concat(chalk.green(localCustomAppData.entryPointUriPath), "\" with the changes above. Are you sure you want to proceed?"), options.dryRun && chalk.gray('Using "--dry-run", no data will be updated.')]).call(_context5, Boolean).join('\n'),
792
912
  initial: 'yes'
793
913
  });
794
914
 
795
- case 59:
796
- _yield$prompts3 = _context7.sent;
915
+ case 66:
916
+ _yield$prompts3 = _context6.sent;
797
917
  confirmation = _yield$prompts3.confirmation;
798
918
 
799
919
  if (!(!confirmation || confirmation.toLowerCase().charAt(0) !== 'y')) {
800
- _context7.next = 64;
920
+ _context6.next = 71;
801
921
  break;
802
922
  }
803
923
 
804
924
  console.log(chalk.red('Aborted.'));
805
- return _context7.abrupt("return");
925
+ return _context6.abrupt("return");
806
926
 
807
- case 64:
927
+ case 71:
808
928
  data = omit(localCustomAppData, ['id']);
809
929
 
810
930
  if (!options.dryRun) {
811
- _context7.next = 70;
931
+ _context6.next = 78;
812
932
  break;
813
933
  }
814
934
 
815
- console.log(chalk.gray('DRY RUN mode'));
816
- console.log("The Custom Application ".concat(data.name, " would be updated with the following payload:"));
817
- console.log(_JSON$stringify(data));
818
- return _context7.abrupt("return");
935
+ console.log();
936
+ console.log("The following payload would be used to update the Custom Application \"".concat(chalk.green(data.entryPointUriPath), "\"."));
937
+ console.log();
938
+ console.log(chalk.gray(_JSON$stringify(data, null, 2)));
939
+ return _context6.abrupt("return");
819
940
 
820
- case 70:
821
- _context7.next = 72;
941
+ case 78:
942
+ _context6.next = 80;
822
943
  return updateCustomApplication({
823
944
  mcApiUrl: mcApiUrl,
824
- token: token,
825
945
  organizationId: fetchedCustomApplication.organizationId,
826
946
  data: omit(localCustomAppData, ['id']),
827
947
  applicationId: fetchedCustomApplication.application.id
828
948
  });
829
949
 
830
- case 72:
831
- console.log(chalk.green("Custom Application updated.\nYou can see the Custom Application data in the Merchant Center at ".concat(customAppLink, ".")));
950
+ case 80:
951
+ console.log(chalk.green("Custom Application updated."));
952
+ console.log("You can inspect the Custom Application data in the Merchant Center at \"".concat(chalk.gray(customAppLink), "\"."));
832
953
 
833
- case 73:
954
+ case 82:
834
955
  case "end":
835
- return _context7.stop();
956
+ return _context6.stop();
836
957
  }
837
958
  }
838
959
  }, _callee);