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