@commercetools-frontend/mc-scripts 21.23.10 → 21.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 (89) hide show
  1. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +120 -326
  2. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +120 -326
  3. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +116 -321
  4. package/dist/build-980cf2c9.cjs.prod.js +170 -0
  5. package/dist/build-c9601b07.esm.js +156 -0
  6. package/dist/build-e8a49b56.cjs.dev.js +170 -0
  7. package/dist/build-vite-b531d3d3.esm.js +118 -0
  8. package/dist/build-vite-c40a55c3.cjs.dev.js +129 -0
  9. package/dist/build-vite-d17432ec.cjs.prod.js +129 -0
  10. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +2 -2
  11. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +2 -2
  12. package/dist/commercetools-frontend-mc-scripts.esm.js +2 -2
  13. package/dist/compile-html-41195e35.cjs.dev.js +49 -0
  14. package/dist/compile-html-5abd78aa.cjs.prod.js +49 -0
  15. package/dist/compile-html-f9de842c.esm.js +40 -0
  16. package/dist/config-sync-0ecc13b3.cjs.dev.js +783 -0
  17. package/dist/config-sync-4b1ddec3.esm.js +759 -0
  18. package/dist/config-sync-bb59a82d.cjs.prod.js +778 -0
  19. package/dist/{create-postcss-config-f65c7e31.cjs.dev.js → create-postcss-config-5cc679d5.cjs.dev.js} +9 -14
  20. package/dist/{create-postcss-config-06b2e5c2.esm.js → create-postcss-config-a0d4cffa.esm.js} +9 -13
  21. package/dist/{create-postcss-config-787d905f.cjs.prod.js → create-postcss-config-f94c07fd.cjs.prod.js} +9 -14
  22. package/dist/{create-webpack-config-for-development-fd365d6a.esm.js → create-webpack-config-for-development-95334073.esm.js} +21 -25
  23. package/dist/{create-webpack-config-for-development-d46ef148.cjs.dev.js → create-webpack-config-for-development-a53bab71.cjs.dev.js} +24 -28
  24. package/dist/{create-webpack-config-for-development-59faaed8.cjs.prod.js → create-webpack-config-for-development-c915ec0c.cjs.prod.js} +24 -28
  25. package/dist/{create-webpack-config-for-production-b28b3d33.esm.js → create-webpack-config-for-production-342485cd.esm.js} +18 -21
  26. package/dist/{create-webpack-config-for-production-1af3a454.cjs.prod.js → create-webpack-config-for-production-af6f3138.cjs.prod.js} +20 -23
  27. package/dist/{create-webpack-config-for-production-e12e3c30.cjs.dev.js → create-webpack-config-for-production-db45d9ab.cjs.dev.js} +20 -23
  28. package/dist/{user-agent-9a470e39.cjs.dev.js → credentials-storage-a37a8915.cjs.dev.js} +24 -24
  29. package/dist/{user-agent-6e8d0e0b.cjs.prod.js → credentials-storage-b803a804.cjs.prod.js} +24 -24
  30. package/dist/{user-agent-4b60934e.esm.js → credentials-storage-cb88e8fc.esm.js} +22 -22
  31. package/dist/declarations/src/deprecated-entry-points.d.ts +1 -1
  32. package/dist/login-35040a86.cjs.dev.js +93 -0
  33. package/dist/login-6e17747d.esm.js +84 -0
  34. package/dist/login-90736d7e.cjs.prod.js +93 -0
  35. package/dist/{package-a5454c97.esm.js → package-17f18481.esm.js} +17 -16
  36. package/dist/{package-e2d9b5e0.cjs.dev.js → package-c42dc2ac.cjs.dev.js} +17 -16
  37. package/dist/{package-808a31f1.cjs.prod.js → package-db15171f.cjs.prod.js} +17 -16
  38. package/dist/{paths-76b66e74.cjs.prod.js → paths-284c77fb.cjs.prod.js} +6 -8
  39. package/dist/{paths-ed23d5a1.esm.js → paths-55c5d5a2.esm.js} +6 -8
  40. package/dist/{paths-16823f56.cjs.dev.js → paths-db35ac0f.cjs.dev.js} +6 -8
  41. package/dist/serve-41077dad.cjs.prod.js +48 -0
  42. package/dist/serve-660e2ee0.esm.js +41 -0
  43. package/dist/serve-b8063204.cjs.dev.js +48 -0
  44. package/dist/start-0aa71e9a.esm.js +166 -0
  45. package/dist/start-2e7ec87c.cjs.dev.js +180 -0
  46. package/dist/start-c0ffe8d7.cjs.prod.js +180 -0
  47. package/dist/start-vite-324af14d.cjs.prod.js +119 -0
  48. package/dist/start-vite-7d10ae71.esm.js +107 -0
  49. package/dist/start-vite-8f03b0df.cjs.dev.js +119 -0
  50. package/dist/{vendors-to-transpile-367e0ba8.cjs.prod.js → vendors-to-transpile-04a49d40.cjs.prod.js} +1 -1
  51. package/dist/{vendors-to-transpile-b51af5d3.cjs.dev.js → vendors-to-transpile-6ab4ea06.cjs.dev.js} +1 -1
  52. package/dist/{vendors-to-transpile-68e03526.esm.js → vendors-to-transpile-7dc84a72.esm.js} +1 -1
  53. package/dist/vite-plugin-svgr-9a4e7f77.cjs.prod.js +79 -0
  54. package/dist/vite-plugin-svgr-f17db78a.esm.js +55 -0
  55. package/dist/vite-plugin-svgr-fdb37ccf.cjs.dev.js +79 -0
  56. package/package.json +17 -16
  57. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +2 -4
  58. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +2 -4
  59. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +2 -4
  60. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +12 -13
  61. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +12 -13
  62. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +12 -13
  63. package/dist/build-0e6d74d1.esm.js +0 -209
  64. package/dist/build-9074fc85.cjs.dev.js +0 -224
  65. package/dist/build-ae132901.cjs.prod.js +0 -224
  66. package/dist/build-vite-482a21b8.cjs.dev.js +0 -151
  67. package/dist/build-vite-cc68e3bf.esm.js +0 -139
  68. package/dist/build-vite-f095b68d.cjs.prod.js +0 -151
  69. package/dist/compile-html-4361a0b3.esm.js +0 -77
  70. package/dist/compile-html-d6331c35.cjs.prod.js +0 -87
  71. package/dist/compile-html-d9e731aa.cjs.dev.js +0 -87
  72. package/dist/config-sync-2a9945bc.cjs.dev.js +0 -989
  73. package/dist/config-sync-43a80f60.cjs.prod.js +0 -984
  74. package/dist/config-sync-c6c4d1cf.esm.js +0 -964
  75. package/dist/login-7f1cc8d0.cjs.prod.js +0 -167
  76. package/dist/login-d21a49e8.esm.js +0 -157
  77. package/dist/login-ed827138.cjs.dev.js +0 -167
  78. package/dist/serve-12de323b.cjs.dev.js +0 -70
  79. package/dist/serve-784f4fcd.cjs.prod.js +0 -70
  80. package/dist/serve-d6b437b1.esm.js +0 -62
  81. package/dist/start-10a4d95a.esm.js +0 -194
  82. package/dist/start-d021fa98.cjs.prod.js +0 -209
  83. package/dist/start-eea524f2.cjs.dev.js +0 -209
  84. package/dist/start-vite-57ec5175.cjs.dev.js +0 -146
  85. package/dist/start-vite-94c2db8c.esm.js +0 -133
  86. package/dist/start-vite-fc0b15d3.cjs.prod.js +0 -146
  87. package/dist/vite-plugin-svgr-4205f2b5.cjs.dev.js +0 -110
  88. package/dist/vite-plugin-svgr-eb8524fa.esm.js +0 -85
  89. package/dist/vite-plugin-svgr-f3bbedbe.cjs.prod.js +0 -110
@@ -1,964 +0,0 @@
1
- import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
2
- import _asyncToGenerator from '@babel/runtime-corejs3/helpers/esm/asyncToGenerator';
3
- import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
4
- import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
5
- import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
6
- import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
7
- import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
8
- import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
9
- import omit from 'lodash/omit';
10
- import prompts from 'prompts';
11
- import chalk from 'chalk';
12
- import { sanitizeSvg, processConfig } from '@commercetools-frontend/application-config';
13
- import { C as CredentialsStorage, u as userAgent } from './user-agent-4b60934e.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';
17
- import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
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';
20
- import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
21
- import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
22
- import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
23
- import { print } from 'graphql';
24
- import { GraphQLClient, ClientError } from 'graphql-request';
25
- import { GRAPHQL_TARGETS } from '@commercetools-frontend/constants';
26
- import _repeatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/repeat';
27
- import _Set from '@babel/runtime-corejs3/core-js-stable/set';
28
- import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
29
- import '@babel/runtime-corejs3/helpers/classCallCheck';
30
- import '@babel/runtime-corejs3/helpers/createClass';
31
- import '@babel/runtime-corejs3/core-js-stable/date/now';
32
- import 'fs';
33
- import 'path';
34
- import 'os';
35
- import '@commercetools/http-user-agent';
36
- import './package-a5454c97.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; }
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; }
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 } } } };
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 } } } };
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 } } } };
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
- });
54
-
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
- }
149
-
150
- var fetchCustomApplication = /*#__PURE__*/function () {
151
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
152
- var mcApiUrl, entryPointUriPath, customAppData;
153
- return _regeneratorRuntime.wrap(function _callee$(_context) {
154
- while (1) {
155
- switch (_context.prev = _context.next) {
156
- case 0:
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:
170
- customAppData = _context.sent;
171
- return _context.abrupt("return", customAppData.organizationExtensionForCustomApplication);
172
-
173
- case 5:
174
- case "end":
175
- return _context.stop();
176
- }
177
- }
178
- }, _callee);
179
- }));
180
-
181
- return function fetchCustomApplication(_x3) {
182
- return _ref2.apply(this, arguments);
183
- };
184
- }();
185
-
186
- var updateCustomApplication = /*#__PURE__*/function () {
187
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
188
- var mcApiUrl, applicationId, organizationId, data, updatedCustomAppsData;
189
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
190
- while (1) {
191
- switch (_context2.prev = _context2.next) {
192
- case 0:
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
- });
206
-
207
- case 3:
208
- updatedCustomAppsData = _context2.sent;
209
- return _context2.abrupt("return", updatedCustomAppsData.updateCustomApplication);
210
-
211
- case 5:
212
- case "end":
213
- return _context2.stop();
214
- }
215
- }
216
- }, _callee2);
217
- }));
218
-
219
- return function updateCustomApplication(_x4) {
220
- return _ref4.apply(this, arguments);
221
- };
222
- }();
223
-
224
- var createCustomApplication = /*#__PURE__*/function () {
225
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5) {
226
- var mcApiUrl, organizationId, data, createdCustomAppData;
227
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
228
- while (1) {
229
- switch (_context3.prev = _context3.next) {
230
- case 0:
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
- });
243
-
244
- case 3:
245
- createdCustomAppData = _context3.sent;
246
- return _context3.abrupt("return", createdCustomAppData.createCustomApplication);
247
-
248
- case 5:
249
- case "end":
250
- return _context3.stop();
251
- }
252
- }
253
- }, _callee3);
254
- }));
255
-
256
- return function createCustomApplication(_x5) {
257
- return _ref6.apply(this, arguments);
258
- };
259
- }();
260
-
261
- var fetchUserOrganizations = /*#__PURE__*/function () {
262
- var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
263
- var mcApiUrl, userOrganizations;
264
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
265
- while (1) {
266
- switch (_context4.prev = _context4.next) {
267
- case 0:
268
- mcApiUrl = _ref7.mcApiUrl;
269
- _context4.next = 3;
270
- return requestWithTokenRetry(FetchMyOrganizationsFromCli, {
271
- mcApiUrl: mcApiUrl,
272
- headers: {
273
- 'x-graphql-target': GRAPHQL_TARGETS.ADMINISTRATION_SERVICE
274
- }
275
- });
276
-
277
- case 3:
278
- userOrganizations = _context4.sent;
279
- return _context4.abrupt("return", userOrganizations.myOrganizations);
280
-
281
- case 5:
282
- case "end":
283
- return _context4.stop();
284
- }
285
- }
286
- }, _callee4);
287
- }));
288
-
289
- return function fetchUserOrganizations(_x6) {
290
- return _ref8.apply(this, arguments);
291
- };
292
- }();
293
-
294
- function ownKeys(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; }
295
-
296
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context20, _context21; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context20 = ownKeys(Object(source), !0)).call(_context20, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context21 = ownKeys(Object(source))).call(_context21, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
297
- // during tests the color used is appended before the string instead of coloring it.
298
-
299
- var isTest = process.env.NODE_ENV === 'test';
300
-
301
- var red = function red(str) {
302
- if (isTest) return "<color-red>".concat(str, "</color-red>");
303
- return chalk.red(str);
304
- };
305
-
306
- var green = function green(str) {
307
- if (isTest) return "<color-green>".concat(str, "</color-green>");
308
- return chalk.green(str);
309
- }; // Two spaces are used for indentation.
310
-
311
-
312
- var indent = function indent(indentLevel) {
313
- var _context;
314
-
315
- return _repeatInstanceProperty(_context = ' ').call(_context, indentLevel);
316
- };
317
-
318
- var getStringDiff = function getStringDiff(_ref) {
319
- var previousValue = _ref.previousValue,
320
- nextValue = _ref.nextValue,
321
- label = _ref.label,
322
- _ref$indentLevel = _ref.indentLevel,
323
- indentLevel = _ref$indentLevel === void 0 ? 0 : _ref$indentLevel;
324
-
325
- if (!previousValue && nextValue) {
326
- var _context2, _context3;
327
-
328
- return _concatInstanceProperty(_context2 = _concatInstanceProperty(_context3 = "".concat(indent(indentLevel))).call(_context3, label, " added: ")).call(_context2, green(nextValue));
329
- }
330
-
331
- if (previousValue && !nextValue) {
332
- var _context4, _context5;
333
-
334
- return _concatInstanceProperty(_context4 = _concatInstanceProperty(_context5 = "".concat(indent(indentLevel))).call(_context5, label, " removed: ")).call(_context4, red(previousValue));
335
- }
336
-
337
- if (previousValue && nextValue && previousValue !== nextValue) {
338
- var _context6, _context7, _context8;
339
-
340
- return _concatInstanceProperty(_context6 = _concatInstanceProperty(_context7 = _concatInstanceProperty(_context8 = "".concat(indent(indentLevel))).call(_context8, label, " changed: ")).call(_context7, red(previousValue), " => ")).call(_context6, green(nextValue));
341
- }
342
-
343
- return null;
344
- };
345
-
346
- // NOTE: this assumes that the array values are scalar values (not objects).
347
- var getArrayDiff = function getArrayDiff(_ref2) {
348
- var previousValue = _ref2.previousValue,
349
- nextValue = _ref2.nextValue,
350
- label = _ref2.label,
351
- _ref2$indentLevel = _ref2.indentLevel,
352
- indentLevel = _ref2$indentLevel === void 0 ? 0 : _ref2$indentLevel;
353
- var oldArraySet = new _Set(previousValue);
354
- var arrayDiff = [];
355
- nextValue === null || nextValue === void 0 ? void 0 : _forEachInstanceProperty(nextValue).call(nextValue, function (item) {
356
- if (oldArraySet.has(item)) {
357
- oldArraySet.delete(item);
358
- } else {
359
- arrayDiff.push(getStringDiff({
360
- nextValue: item,
361
- label: label,
362
- indentLevel: indentLevel
363
- }));
364
- }
365
- });
366
-
367
- _forEachInstanceProperty(oldArraySet).call(oldArraySet, function (item) {
368
- arrayDiff.push(getStringDiff({
369
- previousValue: item,
370
- label: label,
371
- indentLevel: indentLevel
372
- }));
373
- });
374
-
375
- return arrayDiff.join('\n');
376
- };
377
-
378
- var getPermissionsDiff = function getPermissionsDiff(_ref3) {
379
- var _context11;
380
-
381
- var previousValue = _ref3.previousValue,
382
- nextValue = _ref3.nextValue;
383
- var permissionDiff = ['permissions changed'];
384
-
385
- var mappedOldPermissions = _reduceInstanceProperty(previousValue).call(previousValue, function (previousPermission, _ref4) {
386
- var name = _ref4.name,
387
- oAuthScopes = _ref4.oAuthScopes;
388
- return _objectSpread(_objectSpread({}, previousPermission), {}, _defineProperty({}, name, oAuthScopes));
389
- }, {});
390
-
391
- var indentLevel = 1;
392
-
393
- _forEachInstanceProperty(nextValue).call(nextValue, function (newPermission) {
394
- var _context9;
395
-
396
- var currentDiff = [_concatInstanceProperty(_context9 = "".concat(indent(indentLevel), "\"")).call(_context9, newPermission.name, "\" changed")]; // if the permission name is not in the old config, it means it is a new addition.
397
-
398
- if (!mappedOldPermissions[newPermission.name]) {
399
- var _context10;
400
-
401
- permissionDiff.push(_concatInstanceProperty(_context10 = "".concat(indent(indentLevel), "\"")).call(_context10, green(newPermission.name), "\" was added"));
402
- } // if permission name is in the old config, now we check if there was a change
403
- else {
404
- currentDiff.push(getArrayDiff({
405
- previousValue: mappedOldPermissions[newPermission.name],
406
- nextValue: newPermission.oAuthScopes,
407
- label: 'oauth scope',
408
- indentLevel: 2
409
- }));
410
- delete mappedOldPermissions[newPermission.name];
411
- }
412
-
413
- _filterInstanceProperty(currentDiff).call(currentDiff, Boolean).length > 1 && permissionDiff.push(currentDiff.join('\n'));
414
- }); // if there are old permissions left, it means they were deleted in the new Permissions.
415
-
416
-
417
- _forEachInstanceProperty(_context11 = _Object$keys(mappedOldPermissions)).call(_context11, function (oldPermissionName) {
418
- var _context12;
419
-
420
- permissionDiff.push(_concatInstanceProperty(_context12 = "".concat(indent(indentLevel), "\"")).call(_context12, red(oldPermissionName), "\" was removed"));
421
- });
422
-
423
- if (permissionDiff.length > 1) return permissionDiff.join('\n');
424
- return null;
425
- };
426
-
427
- var getLabelAllLocalesDiff = function getLabelAllLocalesDiff(_ref5) {
428
- var _context16;
429
-
430
- var _ref5$previousValue = _ref5.previousValue,
431
- previousValue = _ref5$previousValue === void 0 ? [] : _ref5$previousValue,
432
- _ref5$nextValue = _ref5.nextValue,
433
- nextValue = _ref5$nextValue === void 0 ? [] : _ref5$nextValue,
434
- _ref5$indentLevel = _ref5.indentLevel,
435
- indentLevel = _ref5$indentLevel === void 0 ? 0 : _ref5$indentLevel;
436
- var labelAllLocalesDiff = ["".concat(indent(indentLevel - 1), "labelAllLocales changed")];
437
-
438
- var mappedOldLabelAllLocales = _reduceInstanceProperty(previousValue).call(previousValue, function (previousLabelAllLocale, _ref6) {
439
- var locale = _ref6.locale,
440
- value = _ref6.value;
441
- return _objectSpread(_objectSpread({}, previousLabelAllLocale), {}, _defineProperty({}, locale, value));
442
- }, {});
443
-
444
- _forEachInstanceProperty(nextValue).call(nextValue, function (newLabelAllLocale) {
445
- if (newLabelAllLocale.locale in mappedOldLabelAllLocales) {
446
- var oldLocaleValue = mappedOldLabelAllLocales[newLabelAllLocale.locale];
447
-
448
- if (oldLocaleValue !== newLabelAllLocale.value) {
449
- var _context13, _context14, _context15;
450
-
451
- labelAllLocalesDiff.push(_concatInstanceProperty(_context13 = _concatInstanceProperty(_context14 = _concatInstanceProperty(_context15 = "".concat(indent(indentLevel), "locale \"")).call(_context15, newLabelAllLocale.locale, "\" changed: ")).call(_context14, red(oldLocaleValue), " => ")).call(_context13, green(newLabelAllLocale.value)));
452
- }
453
-
454
- delete mappedOldLabelAllLocales[newLabelAllLocale.locale];
455
- } else {
456
- var localeDiff = getStringDiff({
457
- nextValue: newLabelAllLocale.locale,
458
- label: 'locale',
459
- indentLevel: indentLevel
460
- });
461
-
462
- if (localeDiff) {
463
- labelAllLocalesDiff.push(localeDiff);
464
- }
465
- }
466
- });
467
-
468
- _forEachInstanceProperty(_context16 = _Object$keys(mappedOldLabelAllLocales)).call(_context16, function (key) {
469
- var localeDiff = getStringDiff({
470
- previousValue: key,
471
- label: 'locale',
472
- indentLevel: indentLevel
473
- });
474
-
475
- if (localeDiff) {
476
- labelAllLocalesDiff.push(localeDiff);
477
- }
478
- });
479
-
480
- if (labelAllLocalesDiff.length > 1) return labelAllLocalesDiff.join('\n');
481
- return null;
482
- };
483
-
484
- var getMainMenuLinkDiff = function getMainMenuLinkDiff(_ref7) {
485
- var previousValue = _ref7.previousValue,
486
- nextValue = _ref7.nextValue;
487
- var mainMenuLinkDiff = ['mainMenuLink changed'];
488
- var menuDiff = getStringDiff({
489
- previousValue: previousValue.defaultLabel,
490
- nextValue: nextValue.defaultLabel,
491
- label: 'defaultLabel',
492
- indentLevel: 1
493
- });
494
-
495
- if (menuDiff) {
496
- mainMenuLinkDiff.push(menuDiff);
497
- }
498
-
499
- var mainMenuLinkPermissionsDiff = getArrayDiff({
500
- previousValue: previousValue.permissions,
501
- nextValue: nextValue.permissions,
502
- label: 'applied permission',
503
- indentLevel: 2
504
- });
505
-
506
- if (mainMenuLinkPermissionsDiff.length > 0) {
507
- mainMenuLinkDiff.push("".concat(indent(1), "permissions changed"));
508
- mainMenuLinkDiff.push(mainMenuLinkPermissionsDiff);
509
- }
510
-
511
- var menuLabelsDiff = getLabelAllLocalesDiff({
512
- previousValue: previousValue.labelAllLocales,
513
- nextValue: nextValue.labelAllLocales,
514
- indentLevel: 2
515
- });
516
-
517
- if (menuLabelsDiff) {
518
- mainMenuLinkDiff.push(menuLabelsDiff);
519
- }
520
-
521
- var filteredMainMenuLinkDiff = _filterInstanceProperty(mainMenuLinkDiff).call(mainMenuLinkDiff, Boolean);
522
-
523
- if (filteredMainMenuLinkDiff.length > 1) return filteredMainMenuLinkDiff.join('\n');
524
- return null;
525
- };
526
-
527
- var getSubmenuLinksDiff = function getSubmenuLinksDiff(_ref8) {
528
- var _context19;
529
-
530
- var previousValue = _ref8.previousValue,
531
- nextValue = _ref8.nextValue;
532
- var submenuLinksDiff = ['submenuLink changed'];
533
-
534
- var mappedSubmenuLinks = _reduceInstanceProperty(previousValue).call(previousValue, function (previousSubmenuLink, currentSubmenuLink) {
535
- return _objectSpread(_objectSpread({}, previousSubmenuLink), {}, _defineProperty({}, currentSubmenuLink.uriPath, currentSubmenuLink));
536
- }, {});
537
-
538
- _forEachInstanceProperty(nextValue).call(nextValue, function (newSubmenuLink) {
539
- var oldSubMenuLink = mappedSubmenuLinks[newSubmenuLink.uriPath];
540
-
541
- if (newSubmenuLink.uriPath in mappedSubmenuLinks) {
542
- var _context17, _context18;
543
-
544
- var submenuLinkDiff = [_concatInstanceProperty(_context17 = "".concat(indent(1), "menu link \"")).call(_context17, newSubmenuLink.uriPath, "\" changed")];
545
-
546
- _forEachInstanceProperty(_context18 = _Object$keys(mappedSubmenuLinks[newSubmenuLink.uriPath])).call(_context18, function (key) {
547
- switch (key) {
548
- case 'defaultLabel':
549
- {
550
- var labelDiff = getStringDiff({
551
- previousValue: oldSubMenuLink.defaultLabel,
552
- nextValue: newSubmenuLink.defaultLabel,
553
- label: 'defaultLabel',
554
- indentLevel: 2
555
- });
556
-
557
- if (labelDiff) {
558
- submenuLinkDiff.push(labelDiff);
559
- }
560
-
561
- break;
562
- }
563
-
564
- case 'permissions':
565
- {
566
- var submenuLinkPermissionsDiff = getArrayDiff({
567
- previousValue: oldSubMenuLink.permissions,
568
- nextValue: newSubmenuLink.permissions,
569
- label: 'applied permission',
570
- indentLevel: 3
571
- });
572
-
573
- if (submenuLinkPermissionsDiff.length > 0) {
574
- submenuLinkDiff.push("".concat(indent(2), "permissions changed"));
575
- submenuLinkDiff.push(submenuLinkPermissionsDiff);
576
- }
577
-
578
- break;
579
- }
580
-
581
- case 'labelAllLocales':
582
- {
583
- var labelsDiff = getLabelAllLocalesDiff({
584
- previousValue: oldSubMenuLink.labelAllLocales,
585
- nextValue: newSubmenuLink.labelAllLocales,
586
- indentLevel: 3
587
- });
588
-
589
- if (labelsDiff) {
590
- submenuLinkDiff.push(labelsDiff);
591
- }
592
-
593
- break;
594
- }
595
- }
596
- });
597
-
598
- delete mappedSubmenuLinks[newSubmenuLink.uriPath];
599
-
600
- var filteredSubmenuLinksDiff = _filterInstanceProperty(submenuLinkDiff).call(submenuLinkDiff, Boolean);
601
-
602
- if (filteredSubmenuLinksDiff.length > 1) {
603
- submenuLinksDiff.push(filteredSubmenuLinksDiff.join('\n'));
604
- }
605
- } else {
606
- var linksDiff = getStringDiff({
607
- nextValue: newSubmenuLink.uriPath,
608
- label: 'menu link',
609
- indentLevel: 1
610
- });
611
-
612
- if (linksDiff) {
613
- submenuLinksDiff.push(linksDiff);
614
- }
615
- }
616
- });
617
-
618
- _forEachInstanceProperty(_context19 = _Object$keys(mappedSubmenuLinks)).call(_context19, function (key) {
619
- var linksDiff = getStringDiff({
620
- previousValue: key,
621
- label: 'menu link',
622
- indentLevel: 1
623
- });
624
- if (linksDiff) submenuLinksDiff.push(linksDiff);
625
- });
626
-
627
- if (submenuLinksDiff.length > 1) return submenuLinksDiff.join('\n');
628
- return null;
629
- }; // Compute diff changes of the Custom Application config.
630
- // NOTE: Only known keys are evaluated.
631
-
632
-
633
- var getConfigDiff = function getConfigDiff(oldConfig, newConfig) {
634
- var diff = []; // Name
635
-
636
- var nameDiff = getStringDiff({
637
- previousValue: oldConfig.name,
638
- nextValue: newConfig.name,
639
- label: 'name'
640
- });
641
-
642
- if (nameDiff) {
643
- diff.push(nameDiff);
644
- } // Description
645
-
646
-
647
- var descriptionDiff = getStringDiff({
648
- previousValue: oldConfig.description,
649
- nextValue: newConfig.description,
650
- label: 'description'
651
- });
652
-
653
- if (descriptionDiff) {
654
- diff.push(descriptionDiff);
655
- } // URL
656
-
657
-
658
- var urlDiff = getStringDiff({
659
- previousValue: oldConfig.url,
660
- nextValue: newConfig.url,
661
- label: 'url'
662
- });
663
-
664
- if (urlDiff) {
665
- diff.push(urlDiff);
666
- } // Icon
667
-
668
-
669
- var iconDiff = getStringDiff({
670
- // This icon stored in the database has already been sanitized.
671
- previousValue: oldConfig.icon,
672
- // Sanitize the raw icon as-if it was stored in the database,
673
- // to ensure the data can be safely compared.
674
- nextValue: sanitizeSvg(newConfig.icon),
675
- label: 'icon'
676
- });
677
-
678
- if (iconDiff) {
679
- diff.push(iconDiff);
680
- } // Permissions
681
-
682
-
683
- var permissionsDiff = getPermissionsDiff({
684
- previousValue: oldConfig.permissions,
685
- nextValue: newConfig.permissions
686
- });
687
-
688
- if (permissionsDiff) {
689
- diff.push(permissionsDiff);
690
- } // Main menu link
691
-
692
-
693
- var mainMenuDiff = getMainMenuLinkDiff({
694
- previousValue: oldConfig.mainMenuLink,
695
- nextValue: newConfig.mainMenuLink
696
- });
697
-
698
- if (mainMenuDiff) {
699
- diff.push(mainMenuDiff);
700
- } // Submenu links
701
-
702
-
703
- var submenuDiff = getSubmenuLinksDiff({
704
- previousValue: oldConfig.submenuLinks,
705
- nextValue: newConfig.submenuLinks
706
- });
707
-
708
- if (submenuDiff) {
709
- diff.push(submenuDiff);
710
- }
711
-
712
- return diff.join('\n');
713
- };
714
-
715
- var credentialsStorage = new CredentialsStorage();
716
-
717
- var getMcUrlLink = function getMcUrlLink(mcApiUrl, organizationId, applicationId) {
718
- var _context, _context2;
719
-
720
- var mcUrl = mcApiUrl.replace('mc-api', 'mc');
721
-
722
- var customAppLink = _concatInstanceProperty(_context = _concatInstanceProperty(_context2 = "".concat(mcUrl, "/account/organizations/")).call(_context2, organizationId, "/custom-applications/owned/")).call(_context, applicationId);
723
-
724
- return customAppLink;
725
- };
726
-
727
- function run(_x) {
728
- return _run.apply(this, arguments);
729
- }
730
-
731
- function _run() {
732
- _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
733
- var _context5;
734
-
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;
736
-
737
- return _regeneratorRuntime.wrap(function _callee$(_context6) {
738
- while (1) {
739
- switch (_context6.prev = _context6.next) {
740
- case 0:
741
- applicationConfig = processConfig();
742
- localCustomAppData = applicationConfig.data;
743
- mcApiUrl = applicationConfig.env.mcApiUrl;
744
- console.log("Using Merchant Center environment \"".concat(chalk.green(mcApiUrl), "\"."));
745
- console.log();
746
- isSessionValid = credentialsStorage.isSessionValid(mcApiUrl);
747
-
748
- if (isSessionValid) {
749
- _context6.next = 8;
750
- break;
751
- }
752
-
753
- throw new Error("You don't have a valid session. Please, run the \"mc-scripts login\" command to authenticate yourself.");
754
-
755
- case 8:
756
- _context6.next = 10;
757
- return fetchCustomApplication({
758
- mcApiUrl: mcApiUrl,
759
- entryPointUriPath: localCustomAppData.entryPointUriPath
760
- });
761
-
762
- case 10:
763
- fetchedCustomApplication = _context6.sent;
764
-
765
- if (fetchedCustomApplication) {
766
- _context6.next = 55;
767
- break;
768
- }
769
-
770
- _context6.next = 14;
771
- return fetchUserOrganizations({
772
- mcApiUrl: mcApiUrl
773
- });
774
-
775
- case 14:
776
- userOrganizations = _context6.sent;
777
-
778
- if (!(userOrganizations.total === 0)) {
779
- _context6.next = 17;
780
- break;
781
- }
782
-
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.");
784
-
785
- case 17:
786
- if (!(userOrganizations.total === 1)) {
787
- _context6.next = 23;
788
- break;
789
- }
790
-
791
- _userOrganizations$re = _slicedToArray(userOrganizations.results, 1), organization = _userOrganizations$re[0];
792
- organizationId = organization.id;
793
- organizationName = organization.name;
794
- _context6.next = 32;
795
- break;
796
-
797
- case 23:
798
- organizationChoices = _mapInstanceProperty(_context3 = userOrganizations.results).call(_context3, function (organization) {
799
- return {
800
- title: organization.name,
801
- value: organization.id
802
- };
803
- });
804
- _context6.next = 26;
805
- return prompts({
806
- type: 'select',
807
- name: 'organizationId',
808
- message: 'Select an Organization',
809
- choices: organizationChoices,
810
- initial: 0
811
- });
812
-
813
- case 26:
814
- _yield$prompts = _context6.sent;
815
- selectedOrganizationId = _yield$prompts.organizationId;
816
-
817
- if (selectedOrganizationId) {
818
- _context6.next = 30;
819
- break;
820
- }
821
-
822
- throw new Error("No Organization selected, aborting.");
823
-
824
- case 30:
825
- organizationId = selectedOrganizationId;
826
- organizationName = _findInstanceProperty(organizationChoices).call(organizationChoices, function (_ref) {
827
- var value = _ref.value;
828
- return value === organizationId;
829
- }).title;
830
-
831
- case 32:
832
- _context6.next = 34;
833
- return prompts({
834
- type: 'text',
835
- name: 'confirmation',
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'),
837
- initial: 'yes'
838
- });
839
-
840
- case 34:
841
- _yield$prompts2 = _context6.sent;
842
- _confirmation = _yield$prompts2.confirmation;
843
-
844
- if (!(!_confirmation || _confirmation.toLowerCase().charAt(0) !== 'y')) {
845
- _context6.next = 39;
846
- break;
847
- }
848
-
849
- console.log(chalk.red('Aborted.'));
850
- return _context6.abrupt("return");
851
-
852
- case 39:
853
- _data = omit(localCustomAppData, ['id']);
854
-
855
- if (!options.dryRun) {
856
- _context6.next = 46;
857
- break;
858
- }
859
-
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");
865
-
866
- case 46:
867
- _context6.next = 48;
868
- return createCustomApplication({
869
- mcApiUrl: mcApiUrl,
870
- organizationId: organizationId,
871
- data: _data
872
- });
873
-
874
- case 48:
875
- createdCustomApplication = _context6.sent;
876
-
877
- if (createdCustomApplication) {
878
- _context6.next = 51;
879
- break;
880
- }
881
-
882
- throw new Error('Failed to create the Custom Application.');
883
-
884
- case 51:
885
- _customAppLink = getMcUrlLink(mcApiUrl, organizationId, createdCustomApplication.id);
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");
889
-
890
- case 55:
891
- customAppLink = getMcUrlLink(mcApiUrl, fetchedCustomApplication.organizationId, fetchedCustomApplication.application.id);
892
- configDiff = getConfigDiff(fetchedCustomApplication.application, localCustomAppData);
893
-
894
- if (configDiff) {
895
- _context6.next = 61;
896
- break;
897
- }
898
-
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");
902
-
903
- case 61:
904
- console.log('Changes detected:');
905
- console.log(configDiff);
906
- console.log();
907
- _context6.next = 66;
908
- return prompts({
909
- type: 'text',
910
- name: 'confirmation',
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'),
912
- initial: 'yes'
913
- });
914
-
915
- case 66:
916
- _yield$prompts3 = _context6.sent;
917
- confirmation = _yield$prompts3.confirmation;
918
-
919
- if (!(!confirmation || confirmation.toLowerCase().charAt(0) !== 'y')) {
920
- _context6.next = 71;
921
- break;
922
- }
923
-
924
- console.log(chalk.red('Aborted.'));
925
- return _context6.abrupt("return");
926
-
927
- case 71:
928
- data = omit(localCustomAppData, ['id']);
929
-
930
- if (!options.dryRun) {
931
- _context6.next = 78;
932
- break;
933
- }
934
-
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");
940
-
941
- case 78:
942
- _context6.next = 80;
943
- return updateCustomApplication({
944
- mcApiUrl: mcApiUrl,
945
- organizationId: fetchedCustomApplication.organizationId,
946
- data: omit(localCustomAppData, ['id']),
947
- applicationId: fetchedCustomApplication.application.id
948
- });
949
-
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), "\"."));
953
-
954
- case 82:
955
- case "end":
956
- return _context6.stop();
957
- }
958
- }
959
- }, _callee);
960
- }));
961
- return _run.apply(this, arguments);
962
- }
963
-
964
- export { run as default };