@commercetools-frontend/mc-scripts 21.7.0 → 21.9.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 (152) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -42
  3. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.d.ts +1 -0
  4. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.dev.js +7 -0
  5. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.js +7 -0
  6. package/{build/config/application-runtime.js → application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js} +2 -2
  7. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.esm.js +5 -0
  8. package/application-runtime/package.json +4 -0
  9. package/bin/cli.js +1 -1
  10. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts +1 -0
  11. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +361 -0
  12. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.js +7 -0
  13. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +361 -0
  14. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +345 -0
  15. package/cli/package.json +4 -0
  16. package/config/create-webpack-config-for-development.js +7 -1
  17. package/config/create-webpack-config-for-production.js +7 -1
  18. package/config/vendors-to-transpile.js +5 -1
  19. package/dist/build-5357ad26.cjs.prod.js +224 -0
  20. package/dist/build-9b6d7eee.cjs.dev.js +224 -0
  21. package/dist/build-c483e87f.esm.js +209 -0
  22. package/dist/build-vite-3b82522e.cjs.dev.js +151 -0
  23. package/dist/build-vite-93abdc95.esm.js +139 -0
  24. package/dist/build-vite-b7cd993a.cjs.prod.js +151 -0
  25. package/dist/commercetools-frontend-mc-scripts.cjs.d.ts +1 -0
  26. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +30 -0
  27. package/dist/commercetools-frontend-mc-scripts.cjs.js +7 -0
  28. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +30 -0
  29. package/dist/commercetools-frontend-mc-scripts.esm.js +22 -0
  30. package/dist/compile-html-4361a0b3.esm.js +77 -0
  31. package/dist/compile-html-d6331c35.cjs.prod.js +87 -0
  32. package/dist/compile-html-d9e731aa.cjs.dev.js +87 -0
  33. package/dist/config-sync-6b31d972.esm.js +840 -0
  34. package/dist/config-sync-a478bc0f.cjs.dev.js +864 -0
  35. package/dist/config-sync-f07734e4.cjs.prod.js +859 -0
  36. package/{build/config/create-postcss-config.js → dist/create-postcss-config-04243dea.esm.js} +27 -25
  37. package/dist/create-postcss-config-760e2dc5.cjs.dev.js +90 -0
  38. package/dist/create-postcss-config-ddc3abee.cjs.prod.js +90 -0
  39. package/dist/create-webpack-config-for-development-76fdab59.cjs.prod.js +419 -0
  40. package/{build/config/create-webpack-config-for-development.js → dist/create-webpack-config-for-development-d93ae4b2.esm.js} +94 -57
  41. package/dist/create-webpack-config-for-development-dfd1c174.cjs.dev.js +419 -0
  42. package/{build/config/create-webpack-config-for-production.js → dist/create-webpack-config-for-production-9290479a.esm.js} +120 -54
  43. package/dist/create-webpack-config-for-production-bc8c1f37.cjs.dev.js +469 -0
  44. package/dist/create-webpack-config-for-production-d652ad1a.cjs.prod.js +469 -0
  45. package/dist/declarations/src/application-runtime.d.ts +1 -0
  46. package/dist/declarations/src/cli.d.ts +4 -0
  47. package/dist/declarations/src/commands/build-vite.d.ts +2 -0
  48. package/dist/declarations/src/commands/build.d.ts +2 -0
  49. package/dist/declarations/src/commands/compile-html.d.ts +3 -0
  50. package/dist/declarations/src/commands/config-sync.d.ts +3 -0
  51. package/dist/declarations/src/commands/login.d.ts +2 -0
  52. package/dist/declarations/src/commands/serve.d.ts +2 -0
  53. package/dist/declarations/src/commands/start-vite.d.ts +2 -0
  54. package/dist/declarations/src/commands/start.d.ts +2 -0
  55. package/dist/declarations/src/config/create-postcss-config.d.ts +4 -0
  56. package/dist/declarations/src/config/create-webpack-config-for-development.d.ts +10 -0
  57. package/dist/declarations/src/config/create-webpack-config-for-production.d.ts +10 -0
  58. package/dist/declarations/src/config/has-jsx-runtime.d.ts +2 -0
  59. package/dist/declarations/src/config/moment-locales.d.ts +2 -0
  60. package/dist/declarations/src/config/paths.d.ts +12 -0
  61. package/dist/declarations/src/config/vendors-to-transpile.d.ts +2 -0
  62. package/dist/declarations/src/config/webpack-dev-server.config.d.ts +6 -0
  63. package/dist/declarations/src/deprecated-entry-points.d.ts +7 -0
  64. package/dist/declarations/src/generated/core.d.ts +710 -0
  65. package/dist/declarations/src/generated/settings.d.ts +2485 -0
  66. package/dist/declarations/src/index.d.ts +3 -0
  67. package/dist/declarations/src/postcss.d.ts +1 -0
  68. package/dist/declarations/src/types.d.ts +82 -0
  69. package/dist/declarations/src/utils/auth.d.ts +6 -0
  70. package/dist/declarations/src/utils/credentials-storage.d.ts +11 -0
  71. package/dist/declarations/src/utils/get-config-diff.d.ts +3 -0
  72. package/dist/declarations/src/utils/graphql-requests.d.ts +80 -0
  73. package/dist/declarations/src/utils/user-agent.d.ts +2 -0
  74. package/dist/declarations/src/version.d.ts +2 -0
  75. package/dist/declarations/src/vite-plugins/vite-plugin-custom-application.d.ts +4 -0
  76. package/dist/declarations/src/vite-plugins/vite-plugin-dynamic-base-assets-globals.d.ts +3 -0
  77. package/dist/declarations/src/vite-plugins/vite-plugin-svgr.d.ts +3 -0
  78. package/dist/declarations/src/webpack-plugins/final-stats-writer-plugin.d.ts +12 -0
  79. package/dist/declarations/src/webpack-plugins/local-html-webpack-plugin.d.ts +5 -0
  80. package/dist/declarations/src/webpack.d.ts +2 -0
  81. package/dist/has-jsx-runtime-0b03b72e.cjs.prod.js +17 -0
  82. package/dist/has-jsx-runtime-3d4bb633.cjs.dev.js +17 -0
  83. package/{build/config/has-jsx-runtime.js → dist/has-jsx-runtime-8314226e.esm.js} +1 -3
  84. package/dist/login-7b7ae27e.esm.js +155 -0
  85. package/dist/login-b13f26e7.cjs.dev.js +165 -0
  86. package/dist/login-c11fb977.cjs.prod.js +165 -0
  87. package/dist/package-4b4fcf02.cjs.prod.js +139 -0
  88. package/dist/package-4c3e3fb7.cjs.dev.js +139 -0
  89. package/dist/package-8e6305bd.esm.js +137 -0
  90. package/dist/paths-16823f56.cjs.dev.js +55 -0
  91. package/dist/paths-76b66e74.cjs.prod.js +55 -0
  92. package/dist/paths-ed23d5a1.esm.js +46 -0
  93. package/dist/serve-12de323b.cjs.dev.js +70 -0
  94. package/dist/serve-784f4fcd.cjs.prod.js +70 -0
  95. package/dist/serve-d6b437b1.esm.js +62 -0
  96. package/dist/start-1b7dad90.cjs.prod.js +209 -0
  97. package/dist/start-45ca01f2.cjs.dev.js +209 -0
  98. package/dist/start-600d06a3.esm.js +194 -0
  99. package/dist/start-vite-22de08dc.cjs.dev.js +151 -0
  100. package/dist/start-vite-dc046cba.esm.js +138 -0
  101. package/dist/start-vite-fe13330b.cjs.prod.js +151 -0
  102. package/dist/user-agent-5f8ec93d.cjs.prod.js +106 -0
  103. package/dist/user-agent-ca628320.esm.js +94 -0
  104. package/dist/user-agent-ee57c98a.cjs.dev.js +106 -0
  105. package/dist/vendors-to-transpile-367e0ba8.cjs.prod.js +5 -0
  106. package/dist/vendors-to-transpile-68e03526.esm.js +3 -0
  107. package/dist/vendors-to-transpile-b51af5d3.cjs.dev.js +5 -0
  108. package/dist/vite-plugin-svgr-4205f2b5.cjs.dev.js +110 -0
  109. package/dist/vite-plugin-svgr-eb8524fa.esm.js +85 -0
  110. package/dist/vite-plugin-svgr-f3bbedbe.cjs.prod.js +110 -0
  111. package/package.json +56 -50
  112. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts +1 -0
  113. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +14 -0
  114. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.js +7 -0
  115. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +14 -0
  116. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +6 -0
  117. package/postcss/package.json +4 -0
  118. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts +1 -0
  119. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +51 -0
  120. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.js +7 -0
  121. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +51 -0
  122. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +42 -0
  123. package/webpack/package.json +4 -0
  124. package/build/bin/cli.js +0 -264
  125. package/build/commands/build-vite.js +0 -91
  126. package/build/commands/build.js +0 -140
  127. package/build/commands/compile-html.js +0 -53
  128. package/build/commands/config-sync.js +0 -176
  129. package/build/commands/login.js +0 -60
  130. package/build/commands/serve.js +0 -37
  131. package/build/commands/start-vite.js +0 -138
  132. package/build/commands/start.js +0 -108
  133. package/build/config/paths.js +0 -38
  134. package/build/config/vendors-to-transpile.js +0 -3
  135. package/build/config/webpack-dev-server.config.js +0 -69
  136. package/build/index.js +0 -16
  137. package/build/utils/auth.js +0 -34
  138. package/build/utils/auth.spec.js +0 -61
  139. package/build/utils/create-custom-application.settings.graphql +0 -8
  140. package/build/utils/credentials-storage.js +0 -72
  141. package/build/utils/credentials-storage.spec.js +0 -69
  142. package/build/utils/fetch-custom-application.settings.graphql +0 -36
  143. package/build/utils/fetch-user-organizations.core.graphql +0 -9
  144. package/build/utils/get-config-diff.js +0 -308
  145. package/build/utils/get-config-diff.spec.js +0 -285
  146. package/build/utils/graphql-requests.js +0 -105
  147. package/build/utils/graphql-requests.spec.js +0 -159
  148. package/build/utils/require-graphql.js +0 -15
  149. package/build/utils/update-custom-application.settings.graphql +0 -13
  150. package/build/utils/user-agent.js +0 -15
  151. package/build/webpack-plugins/final-stats-writer-plugin.js +0 -50
  152. package/build/webpack-plugins/local-html-webpack-plugin.js +0 -38
@@ -0,0 +1,840 @@
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 _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
8
+ import omit from 'lodash/omit';
9
+ import prompts from 'prompts';
10
+ import chalk from 'chalk';
11
+ import { processConfig } from '@commercetools-frontend/application-config';
12
+ import { u as userAgent, C as CredentialsStorage } from './user-agent-ca628320.esm.js';
13
+ import { GraphQLClient } from 'graphql-request';
14
+ import { GRAPHQL_TARGETS } from '@commercetools-frontend/constants';
15
+ import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
16
+ import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
17
+ import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
18
+ import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
19
+ import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
20
+ import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
21
+ import _repeatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/repeat';
22
+ import _Set from '@babel/runtime-corejs3/core-js-stable/set';
23
+ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
24
+ import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
25
+ import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
26
+ import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
27
+ import '@babel/runtime-corejs3/helpers/classCallCheck';
28
+ import '@babel/runtime-corejs3/helpers/createClass';
29
+ import '@babel/runtime-corejs3/core-js-stable/date/now';
30
+ import 'fs';
31
+ import 'path';
32
+ import 'os';
33
+ import '@commercetools/http-user-agent';
34
+ import './package-8e6305bd.esm.js';
35
+
36
+ var FetchCustomApplicationFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchCustomApplicationFromCli" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "entryPointUriPath" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "organizationExtensionForCustomApplication" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "entryPointUriPath" }, value: { kind: "Variable", name: { kind: "Name", value: "entryPointUriPath" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "organizationId" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "application" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "entryPointUriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "description" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "url" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "icon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "oAuthScopes" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "mainMenuLink" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "defaultLabel" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }] } }, { kind: "Field", name: { kind: "Name", value: "submenuLinks" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "defaultLabel" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }] } }] } }] } }] } }], loc: { start: 0, end: 647, source: { body: "query FetchCustomApplicationFromCli($entryPointUriPath: String!) {\n organizationExtensionForCustomApplication(\n entryPointUriPath: $entryPointUriPath\n ) {\n organizationId\n application {\n id\n entryPointUriPath\n name\n description\n url\n icon\n permissions {\n name\n oAuthScopes\n }\n mainMenuLink {\n defaultLabel\n permissions\n labelAllLocales {\n locale\n value\n }\n }\n submenuLinks {\n uriPath\n defaultLabel\n permissions\n labelAllLocales {\n locale\n value\n }\n }\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
37
+ var UpdateCustomApplicationFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "mutation", name: { kind: "Name", value: "UpdateCustomApplicationFromCli" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "organizationId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "data" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "CustomApplicationDraftDataInput" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "applicationId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "ID" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "updateCustomApplication" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "organizationId" }, value: { kind: "Variable", name: { kind: "Name", value: "organizationId" } } }, { kind: "Argument", name: { kind: "Name", value: "data" }, value: { kind: "Variable", name: { kind: "Name", value: "data" } } }, { kind: "Argument", name: { kind: "Name", value: "applicationId" }, value: { kind: "Variable", name: { kind: "Name", value: "applicationId" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }] } }] } }], loc: { start: 0, end: 268, source: { body: "mutation UpdateCustomApplicationFromCli(\n $organizationId: String!\n $data: CustomApplicationDraftDataInput!\n $applicationId: ID!\n) {\n updateCustomApplication(\n organizationId: $organizationId\n data: $data\n applicationId: $applicationId\n ) {\n id\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
38
+ var CreateCustomApplicationFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "mutation", name: { kind: "Name", value: "CreateCustomApplicationFromCli" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "organizationId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "data" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "CustomApplicationDraftDataInput" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "createCustomApplication" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "organizationId" }, value: { kind: "Variable", name: { kind: "Name", value: "organizationId" } } }, { kind: "Argument", name: { kind: "Name", value: "data" }, value: { kind: "Variable", name: { kind: "Name", value: "data" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }] } }] } }], loc: { start: 0, end: 201, source: { body: "mutation CreateCustomApplicationFromCli(\n $organizationId: String!\n $data: CustomApplicationDraftDataInput!\n) {\n createCustomApplication(organizationId: $organizationId, data: $data) {\n id\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
39
+ 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 } } } };
40
+
41
+ var graphQLClient = function graphQLClient(url, token) {
42
+ var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : GRAPHQL_TARGETS.SETTINGS_SERVICE;
43
+ return new GraphQLClient("".concat(url, "/graphql"), {
44
+ headers: {
45
+ Accept: 'application/json',
46
+ 'Content-Type': 'application/json',
47
+ 'x-graphql-target': target,
48
+ 'x-mc-cli-access-token': token,
49
+ 'x-user-agent': userAgent
50
+ }
51
+ });
52
+ };
53
+
54
+ var fetchCustomApplication = /*#__PURE__*/function () {
55
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
56
+ var mcApiUrl, token, entryPointUriPath, variables, customAppData;
57
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
58
+ while (1) {
59
+ switch (_context.prev = _context.next) {
60
+ case 0:
61
+ mcApiUrl = _ref.mcApiUrl, token = _ref.token, entryPointUriPath = _ref.entryPointUriPath;
62
+ variables = {
63
+ entryPointUriPath: entryPointUriPath
64
+ };
65
+ _context.next = 4;
66
+ return graphQLClient(mcApiUrl, token).request(FetchCustomApplicationFromCli, variables);
67
+
68
+ case 4:
69
+ customAppData = _context.sent;
70
+ return _context.abrupt("return", customAppData.organizationExtensionForCustomApplication);
71
+
72
+ case 6:
73
+ case "end":
74
+ return _context.stop();
75
+ }
76
+ }
77
+ }, _callee);
78
+ }));
79
+
80
+ return function fetchCustomApplication(_x) {
81
+ return _ref2.apply(this, arguments);
82
+ };
83
+ }();
84
+
85
+ var updateCustomApplication = /*#__PURE__*/function () {
86
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
87
+ var mcApiUrl, token, applicationId, organizationId, data, variables, updatedCustomAppsData;
88
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
89
+ while (1) {
90
+ switch (_context2.prev = _context2.next) {
91
+ case 0:
92
+ mcApiUrl = _ref3.mcApiUrl, token = _ref3.token, applicationId = _ref3.applicationId, organizationId = _ref3.organizationId, data = _ref3.data;
93
+ variables = {
94
+ organizationId: organizationId,
95
+ applicationId: applicationId,
96
+ data: data
97
+ };
98
+ _context2.next = 4;
99
+ return graphQLClient(mcApiUrl, token).request(UpdateCustomApplicationFromCli, variables);
100
+
101
+ case 4:
102
+ updatedCustomAppsData = _context2.sent;
103
+ return _context2.abrupt("return", updatedCustomAppsData.updateCustomApplication);
104
+
105
+ case 6:
106
+ case "end":
107
+ return _context2.stop();
108
+ }
109
+ }
110
+ }, _callee2);
111
+ }));
112
+
113
+ return function updateCustomApplication(_x2) {
114
+ return _ref4.apply(this, arguments);
115
+ };
116
+ }();
117
+
118
+ var createCustomApplication = /*#__PURE__*/function () {
119
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5) {
120
+ var mcApiUrl, token, organizationId, data, variables, createdCustomAppData;
121
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
122
+ while (1) {
123
+ switch (_context3.prev = _context3.next) {
124
+ case 0:
125
+ mcApiUrl = _ref5.mcApiUrl, token = _ref5.token, organizationId = _ref5.organizationId, data = _ref5.data;
126
+ variables = {
127
+ organizationId: organizationId,
128
+ data: data
129
+ };
130
+ _context3.next = 4;
131
+ return graphQLClient(mcApiUrl, token).request(CreateCustomApplicationFromCli, variables);
132
+
133
+ case 4:
134
+ createdCustomAppData = _context3.sent;
135
+ return _context3.abrupt("return", createdCustomAppData.createCustomApplication);
136
+
137
+ case 6:
138
+ case "end":
139
+ return _context3.stop();
140
+ }
141
+ }
142
+ }, _callee3);
143
+ }));
144
+
145
+ return function createCustomApplication(_x3) {
146
+ return _ref6.apply(this, arguments);
147
+ };
148
+ }();
149
+
150
+ var fetchUserOrganizations = /*#__PURE__*/function () {
151
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
152
+ var mcApiUrl, token, userOrganizations;
153
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
154
+ while (1) {
155
+ switch (_context4.prev = _context4.next) {
156
+ case 0:
157
+ mcApiUrl = _ref7.mcApiUrl, token = _ref7.token;
158
+ _context4.next = 3;
159
+ return graphQLClient(mcApiUrl, token, GRAPHQL_TARGETS.ADMINISTRATION_SERVICE).request(FetchMyOrganizationsFromCli);
160
+
161
+ case 3:
162
+ userOrganizations = _context4.sent;
163
+ return _context4.abrupt("return", userOrganizations.myOrganizations);
164
+
165
+ case 5:
166
+ case "end":
167
+ return _context4.stop();
168
+ }
169
+ }
170
+ }, _callee4);
171
+ }));
172
+
173
+ return function fetchUserOrganizations(_x4) {
174
+ return _ref8.apply(this, arguments);
175
+ };
176
+ }();
177
+
178
+ 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; }
179
+
180
+ 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; }
181
+ // Since not all terminal supports colors, to make things more consistent for testing purposes,
182
+ // during tests the color used is appended before the string instead of coloring it.
183
+ var isTest = process.env.NODE_ENV === 'test';
184
+
185
+ var red = function red(str) {
186
+ if (isTest) return "<color-red>".concat(str, "</color-red>");
187
+ return chalk.red(str);
188
+ };
189
+
190
+ var green = function green(str) {
191
+ if (isTest) return "<color-green>".concat(str, "</color-green>");
192
+ return chalk.green(str);
193
+ }; // Two spaces are used for indentation.
194
+
195
+
196
+ var indent = function indent(indentLevel) {
197
+ var _context;
198
+
199
+ return _repeatInstanceProperty(_context = ' ').call(_context, indentLevel);
200
+ };
201
+
202
+ var getStringDiff = function getStringDiff(_ref) {
203
+ var previousValue = _ref.previousValue,
204
+ nextValue = _ref.nextValue,
205
+ label = _ref.label,
206
+ _ref$indentLevel = _ref.indentLevel,
207
+ indentLevel = _ref$indentLevel === void 0 ? 0 : _ref$indentLevel;
208
+
209
+ if (!previousValue && nextValue) {
210
+ var _context2, _context3;
211
+
212
+ return _concatInstanceProperty(_context2 = _concatInstanceProperty(_context3 = "".concat(indent(indentLevel))).call(_context3, label, " added: ")).call(_context2, green(nextValue));
213
+ }
214
+
215
+ if (previousValue && !nextValue) {
216
+ var _context4, _context5;
217
+
218
+ return _concatInstanceProperty(_context4 = _concatInstanceProperty(_context5 = "".concat(indent(indentLevel))).call(_context5, label, " removed: ")).call(_context4, red(previousValue));
219
+ }
220
+
221
+ if (previousValue && nextValue && previousValue !== nextValue) {
222
+ var _context6, _context7, _context8;
223
+
224
+ return _concatInstanceProperty(_context6 = _concatInstanceProperty(_context7 = _concatInstanceProperty(_context8 = "".concat(indent(indentLevel))).call(_context8, label, " changed: ")).call(_context7, red(previousValue), " => ")).call(_context6, green(nextValue));
225
+ }
226
+
227
+ return null;
228
+ };
229
+
230
+ // NOTE: this assumes that the array values are scalar values (not objects).
231
+ var getArrayDiff = function getArrayDiff(_ref2) {
232
+ var previousValue = _ref2.previousValue,
233
+ nextValue = _ref2.nextValue,
234
+ label = _ref2.label,
235
+ _ref2$indentLevel = _ref2.indentLevel,
236
+ indentLevel = _ref2$indentLevel === void 0 ? 0 : _ref2$indentLevel;
237
+ var oldArraySet = new _Set(previousValue);
238
+ var arrayDiff = [];
239
+ nextValue === null || nextValue === void 0 ? void 0 : _forEachInstanceProperty(nextValue).call(nextValue, function (item) {
240
+ if (oldArraySet.has(item)) {
241
+ oldArraySet.delete(item);
242
+ } else {
243
+ arrayDiff.push(getStringDiff({
244
+ nextValue: item,
245
+ label: label,
246
+ indentLevel: indentLevel
247
+ }));
248
+ }
249
+ });
250
+
251
+ _forEachInstanceProperty(oldArraySet).call(oldArraySet, function (item) {
252
+ arrayDiff.push(getStringDiff({
253
+ previousValue: item,
254
+ label: label,
255
+ indentLevel: indentLevel
256
+ }));
257
+ });
258
+
259
+ return arrayDiff.join('\n');
260
+ };
261
+
262
+ var getPermissionsDiff = function getPermissionsDiff(_ref3) {
263
+ var _context11;
264
+
265
+ var previousValue = _ref3.previousValue,
266
+ nextValue = _ref3.nextValue;
267
+ var permissionDiff = ['permissions changed'];
268
+
269
+ var mappedOldPermissions = _reduceInstanceProperty(previousValue).call(previousValue, function (previousPermission, _ref4) {
270
+ var name = _ref4.name,
271
+ oAuthScopes = _ref4.oAuthScopes;
272
+ return _objectSpread(_objectSpread({}, previousPermission), {}, _defineProperty({}, name, oAuthScopes));
273
+ }, {});
274
+
275
+ var indentLevel = 1;
276
+
277
+ _forEachInstanceProperty(nextValue).call(nextValue, function (newPermission) {
278
+ var _context9;
279
+
280
+ 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.
281
+
282
+ if (!mappedOldPermissions[newPermission.name]) {
283
+ var _context10;
284
+
285
+ permissionDiff.push(_concatInstanceProperty(_context10 = "".concat(indent(indentLevel), "\"")).call(_context10, green(newPermission.name), "\" was added"));
286
+ } // if permission name is in the old config, now we check if there was a change
287
+ else {
288
+ currentDiff.push(getArrayDiff({
289
+ previousValue: mappedOldPermissions[newPermission.name],
290
+ nextValue: newPermission.oAuthScopes,
291
+ label: 'oauth scope',
292
+ indentLevel: 2
293
+ }));
294
+ delete mappedOldPermissions[newPermission.name];
295
+ }
296
+
297
+ _filterInstanceProperty(currentDiff).call(currentDiff, Boolean).length > 1 && permissionDiff.push(currentDiff.join('\n'));
298
+ }); // if there are old permissions left, it means they were deleted in the new Permissions.
299
+
300
+
301
+ _forEachInstanceProperty(_context11 = _Object$keys(mappedOldPermissions)).call(_context11, function (oldPermissionName) {
302
+ var _context12;
303
+
304
+ permissionDiff.push(_concatInstanceProperty(_context12 = "".concat(indent(indentLevel), "\"")).call(_context12, red(oldPermissionName), "\" was removed"));
305
+ });
306
+
307
+ if (permissionDiff.length > 1) return permissionDiff.join('\n');
308
+ return null;
309
+ };
310
+
311
+ var getLabelAllLocalesDiff = function getLabelAllLocalesDiff(_ref5) {
312
+ var _context16;
313
+
314
+ var _ref5$previousValue = _ref5.previousValue,
315
+ previousValue = _ref5$previousValue === void 0 ? [] : _ref5$previousValue,
316
+ _ref5$nextValue = _ref5.nextValue,
317
+ nextValue = _ref5$nextValue === void 0 ? [] : _ref5$nextValue,
318
+ _ref5$indentLevel = _ref5.indentLevel,
319
+ indentLevel = _ref5$indentLevel === void 0 ? 0 : _ref5$indentLevel;
320
+ var labelAllLocalesDiff = ["".concat(indent(indentLevel - 1), "labelAllLocales changed")];
321
+
322
+ var mappedOldLabelAllLocales = _reduceInstanceProperty(previousValue).call(previousValue, function (previousLabelAllLocale, _ref6) {
323
+ var locale = _ref6.locale,
324
+ value = _ref6.value;
325
+ return _objectSpread(_objectSpread({}, previousLabelAllLocale), {}, _defineProperty({}, locale, value));
326
+ }, {});
327
+
328
+ _forEachInstanceProperty(nextValue).call(nextValue, function (newLabelAllLocale) {
329
+ if (newLabelAllLocale.locale in mappedOldLabelAllLocales) {
330
+ var oldLocaleValue = mappedOldLabelAllLocales[newLabelAllLocale.locale];
331
+
332
+ if (oldLocaleValue !== newLabelAllLocale.value) {
333
+ var _context13, _context14, _context15;
334
+
335
+ 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)));
336
+ }
337
+
338
+ delete mappedOldLabelAllLocales[newLabelAllLocale.locale];
339
+ } else {
340
+ var localeDiff = getStringDiff({
341
+ nextValue: newLabelAllLocale.locale,
342
+ label: 'locale',
343
+ indentLevel: indentLevel
344
+ });
345
+
346
+ if (localeDiff) {
347
+ labelAllLocalesDiff.push(localeDiff);
348
+ }
349
+ }
350
+ });
351
+
352
+ _forEachInstanceProperty(_context16 = _Object$keys(mappedOldLabelAllLocales)).call(_context16, function (key) {
353
+ var localeDiff = getStringDiff({
354
+ previousValue: key,
355
+ label: 'locale',
356
+ indentLevel: indentLevel
357
+ });
358
+
359
+ if (localeDiff) {
360
+ labelAllLocalesDiff.push(localeDiff);
361
+ }
362
+ });
363
+
364
+ if (labelAllLocalesDiff.length > 1) return labelAllLocalesDiff.join('\n');
365
+ return null;
366
+ };
367
+
368
+ var getMainMenuLinkDiff = function getMainMenuLinkDiff(_ref7) {
369
+ var previousValue = _ref7.previousValue,
370
+ nextValue = _ref7.nextValue;
371
+ var mainMenuLinkDiff = ['mainMenuLink changed'];
372
+ var menuDiff = getStringDiff({
373
+ previousValue: previousValue.defaultLabel,
374
+ nextValue: nextValue.defaultLabel,
375
+ label: 'defaultLabel',
376
+ indentLevel: 1
377
+ });
378
+
379
+ if (menuDiff) {
380
+ mainMenuLinkDiff.push(menuDiff);
381
+ }
382
+
383
+ var mainMenuLinkPermissionsDiff = getArrayDiff({
384
+ previousValue: previousValue.permissions,
385
+ nextValue: nextValue.permissions,
386
+ label: 'applied permission',
387
+ indentLevel: 2
388
+ });
389
+
390
+ if (mainMenuLinkPermissionsDiff.length > 0) {
391
+ mainMenuLinkDiff.push("".concat(indent(1), "permissions changed"));
392
+ mainMenuLinkDiff.push(mainMenuLinkPermissionsDiff);
393
+ }
394
+
395
+ var menuLabelsDiff = getLabelAllLocalesDiff({
396
+ previousValue: previousValue.labelAllLocales,
397
+ nextValue: nextValue.labelAllLocales,
398
+ indentLevel: 2
399
+ });
400
+
401
+ if (menuLabelsDiff) {
402
+ mainMenuLinkDiff.push(menuLabelsDiff);
403
+ }
404
+
405
+ var filteredMainMenuLinkDiff = _filterInstanceProperty(mainMenuLinkDiff).call(mainMenuLinkDiff, Boolean);
406
+
407
+ if (filteredMainMenuLinkDiff.length > 1) return filteredMainMenuLinkDiff.join('\n');
408
+ return null;
409
+ };
410
+
411
+ var getSubmenuLinksDiff = function getSubmenuLinksDiff(_ref8) {
412
+ var _context19;
413
+
414
+ var previousValue = _ref8.previousValue,
415
+ nextValue = _ref8.nextValue;
416
+ var submenuLinksDiff = ['submenuLink changed'];
417
+
418
+ var mappedSubmenuLinks = _reduceInstanceProperty(previousValue).call(previousValue, function (previousSubmenuLink, currentSubmenuLink) {
419
+ return _objectSpread(_objectSpread({}, previousSubmenuLink), {}, _defineProperty({}, currentSubmenuLink.uriPath, currentSubmenuLink));
420
+ }, {});
421
+
422
+ _forEachInstanceProperty(nextValue).call(nextValue, function (newSubmenuLink) {
423
+ var oldSubMenuLink = mappedSubmenuLinks[newSubmenuLink.uriPath];
424
+
425
+ if (newSubmenuLink.uriPath in mappedSubmenuLinks) {
426
+ var _context17, _context18;
427
+
428
+ var submenuLinkDiff = [_concatInstanceProperty(_context17 = "".concat(indent(1), "menu link \"")).call(_context17, newSubmenuLink.uriPath, "\" changed")];
429
+
430
+ _forEachInstanceProperty(_context18 = _Object$keys(mappedSubmenuLinks[newSubmenuLink.uriPath])).call(_context18, function (key) {
431
+ switch (key) {
432
+ case 'defaultLabel':
433
+ {
434
+ var labelDiff = getStringDiff({
435
+ previousValue: oldSubMenuLink.defaultLabel,
436
+ nextValue: newSubmenuLink.defaultLabel,
437
+ label: 'defaultLabel',
438
+ indentLevel: 2
439
+ });
440
+
441
+ if (labelDiff) {
442
+ submenuLinkDiff.push(labelDiff);
443
+ }
444
+
445
+ break;
446
+ }
447
+
448
+ case 'permissions':
449
+ {
450
+ var submenuLinkPermissionsDiff = getArrayDiff({
451
+ previousValue: oldSubMenuLink.permissions,
452
+ nextValue: newSubmenuLink.permissions,
453
+ label: 'applied permission',
454
+ indentLevel: 3
455
+ });
456
+
457
+ if (submenuLinkPermissionsDiff.length > 0) {
458
+ submenuLinkDiff.push("".concat(indent(2), "permissions changed"));
459
+ submenuLinkDiff.push(submenuLinkPermissionsDiff);
460
+ }
461
+
462
+ break;
463
+ }
464
+
465
+ case 'labelAllLocales':
466
+ {
467
+ var labelsDiff = getLabelAllLocalesDiff({
468
+ previousValue: oldSubMenuLink.labelAllLocales,
469
+ nextValue: newSubmenuLink.labelAllLocales,
470
+ indentLevel: 3
471
+ });
472
+
473
+ if (labelsDiff) {
474
+ submenuLinkDiff.push(labelsDiff);
475
+ }
476
+
477
+ break;
478
+ }
479
+ }
480
+ });
481
+
482
+ delete mappedSubmenuLinks[newSubmenuLink.uriPath];
483
+
484
+ var filteredSubmenuLinksDiff = _filterInstanceProperty(submenuLinkDiff).call(submenuLinkDiff, Boolean);
485
+
486
+ if (filteredSubmenuLinksDiff.length > 1) {
487
+ submenuLinksDiff.push(filteredSubmenuLinksDiff.join('\n'));
488
+ }
489
+ } else {
490
+ var linksDiff = getStringDiff({
491
+ nextValue: newSubmenuLink.uriPath,
492
+ label: 'menu link',
493
+ indentLevel: 1
494
+ });
495
+
496
+ if (linksDiff) {
497
+ submenuLinksDiff.push(linksDiff);
498
+ }
499
+ }
500
+ });
501
+
502
+ _forEachInstanceProperty(_context19 = _Object$keys(mappedSubmenuLinks)).call(_context19, function (key) {
503
+ var linksDiff = getStringDiff({
504
+ previousValue: key,
505
+ label: 'menu link',
506
+ indentLevel: 1
507
+ });
508
+ if (linksDiff) submenuLinksDiff.push(linksDiff);
509
+ });
510
+
511
+ if (submenuLinksDiff.length > 1) return submenuLinksDiff.join('\n');
512
+ return null;
513
+ }; // Compute diff changes of the Custom Application config.
514
+ // NOTE: Only known keys are evaluated.
515
+
516
+
517
+ var getConfigDiff = function getConfigDiff(oldConfig, newConfig) {
518
+ var diff = []; // Name
519
+
520
+ var nameDiff = getStringDiff({
521
+ previousValue: oldConfig.name,
522
+ nextValue: newConfig.name,
523
+ label: 'name'
524
+ });
525
+
526
+ if (nameDiff) {
527
+ diff.push(nameDiff);
528
+ } // Description
529
+
530
+
531
+ var descriptionDiff = getStringDiff({
532
+ previousValue: oldConfig.description,
533
+ nextValue: newConfig.description,
534
+ label: 'description'
535
+ });
536
+
537
+ if (descriptionDiff) {
538
+ diff.push(descriptionDiff);
539
+ } // URL
540
+
541
+
542
+ var urlDiff = getStringDiff({
543
+ previousValue: oldConfig.url,
544
+ nextValue: newConfig.url,
545
+ label: 'url'
546
+ });
547
+
548
+ if (urlDiff) {
549
+ diff.push(urlDiff);
550
+ } // Icon
551
+
552
+
553
+ var iconDiff = getStringDiff({
554
+ previousValue: oldConfig.icon,
555
+ nextValue: newConfig.icon,
556
+ label: 'icon'
557
+ });
558
+
559
+ if (iconDiff) {
560
+ diff.push(iconDiff);
561
+ } // Permissions
562
+
563
+
564
+ var permissionsDiff = getPermissionsDiff({
565
+ previousValue: oldConfig.permissions,
566
+ nextValue: newConfig.permissions
567
+ });
568
+
569
+ if (permissionsDiff) {
570
+ diff.push(permissionsDiff);
571
+ } // Main menu link
572
+
573
+
574
+ var mainMenuDiff = getMainMenuLinkDiff({
575
+ previousValue: oldConfig.mainMenuLink,
576
+ nextValue: newConfig.mainMenuLink
577
+ });
578
+
579
+ if (mainMenuDiff) {
580
+ diff.push(mainMenuDiff);
581
+ } // Submenu links
582
+
583
+
584
+ var submenuDiff = getSubmenuLinksDiff({
585
+ previousValue: oldConfig.submenuLinks,
586
+ nextValue: newConfig.submenuLinks
587
+ });
588
+
589
+ if (submenuDiff) {
590
+ diff.push(submenuDiff);
591
+ }
592
+
593
+ return diff.join('\n');
594
+ };
595
+
596
+ var credentialsStorage = new CredentialsStorage();
597
+
598
+ var getMcUrlLink = function getMcUrlLink(mcApiUrl, organizationId, applicationId) {
599
+ var _context, _context2;
600
+
601
+ var mcUrl = mcApiUrl.replace('mc-api', 'mc');
602
+
603
+ var customAppLink = _concatInstanceProperty(_context = _concatInstanceProperty(_context2 = "".concat(mcUrl, "/account/organizations/")).call(_context2, organizationId, "/custom-applications/owned/")).call(_context, applicationId);
604
+
605
+ return customAppLink;
606
+ };
607
+
608
+ function run(_x) {
609
+ return _run.apply(this, arguments);
610
+ }
611
+
612
+ function _run() {
613
+ _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
614
+ var _context6;
615
+
616
+ var applicationConfig, localCustomAppData, mcApiUrl, token, fetchedCustomApplication, _context4, _context5, userOrganizations, organizationId, organizationName, _userOrganizations$re, organization, _context3, organizationChoices, _yield$prompts, selectedOrganizationId, _yield$prompts2, _confirmation, _data, createdCustomApplication, _customAppLink, customAppLink, configDiff, _yield$prompts3, confirmation, data;
617
+
618
+ return _regeneratorRuntime.wrap(function _callee$(_context7) {
619
+ while (1) {
620
+ switch (_context7.prev = _context7.next) {
621
+ case 0:
622
+ applicationConfig = processConfig();
623
+ localCustomAppData = applicationConfig.data;
624
+ mcApiUrl = applicationConfig.env.mcApiUrl;
625
+ token = credentialsStorage.getToken(mcApiUrl);
626
+
627
+ if (token) {
628
+ _context7.next = 6;
629
+ break;
630
+ }
631
+
632
+ 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."));
633
+
634
+ case 6:
635
+ _context7.next = 8;
636
+ return fetchCustomApplication({
637
+ mcApiUrl: mcApiUrl,
638
+ token: token,
639
+ entryPointUriPath: localCustomAppData.entryPointUriPath
640
+ });
641
+
642
+ case 8:
643
+ fetchedCustomApplication = _context7.sent;
644
+
645
+ if (fetchedCustomApplication) {
646
+ _context7.next = 51;
647
+ break;
648
+ }
649
+
650
+ _context7.next = 12;
651
+ return fetchUserOrganizations({
652
+ mcApiUrl: mcApiUrl,
653
+ token: token
654
+ });
655
+
656
+ case 12:
657
+ userOrganizations = _context7.sent;
658
+
659
+ if (!(userOrganizations.total === 0)) {
660
+ _context7.next = 15;
661
+ break;
662
+ }
663
+
664
+ 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.");
665
+
666
+ case 15:
667
+ if (!(userOrganizations.total === 1)) {
668
+ _context7.next = 21;
669
+ break;
670
+ }
671
+
672
+ _userOrganizations$re = _slicedToArray(userOrganizations.results, 1), organization = _userOrganizations$re[0];
673
+ organizationId = organization.id;
674
+ organizationName = organization.name;
675
+ _context7.next = 30;
676
+ break;
677
+
678
+ case 21:
679
+ organizationChoices = _mapInstanceProperty(_context3 = userOrganizations.results).call(_context3, function (organization) {
680
+ return {
681
+ title: organization.name,
682
+ value: organization.id
683
+ };
684
+ });
685
+ _context7.next = 24;
686
+ return prompts({
687
+ type: 'select',
688
+ name: 'organizationId',
689
+ message: 'Select Organization',
690
+ choices: organizationChoices,
691
+ initial: 0
692
+ });
693
+
694
+ case 24:
695
+ _yield$prompts = _context7.sent;
696
+ selectedOrganizationId = _yield$prompts.organizationId;
697
+
698
+ if (selectedOrganizationId) {
699
+ _context7.next = 28;
700
+ break;
701
+ }
702
+
703
+ throw new Error("No Organization selected, aborting.");
704
+
705
+ case 28:
706
+ organizationId = selectedOrganizationId;
707
+ organizationName = _findInstanceProperty(organizationChoices).call(organizationChoices, function (_ref) {
708
+ var value = _ref.value;
709
+ return value === organizationId;
710
+ }).title;
711
+
712
+ case 30:
713
+ _context7.next = 32;
714
+ return prompts({
715
+ type: 'text',
716
+ name: 'confirmation',
717
+ message: _concatInstanceProperty(_context4 = "You are about to create a new Custom Application in the \"".concat(organizationName, "\" organization for the ")).call(_context4, mcApiUrl, " environment. Are you sure you want to proceed?"),
718
+ initial: 'yes'
719
+ });
720
+
721
+ case 32:
722
+ _yield$prompts2 = _context7.sent;
723
+ _confirmation = _yield$prompts2.confirmation;
724
+
725
+ if (!(!_confirmation || _confirmation.toLowerCase().charAt(0) !== 'y')) {
726
+ _context7.next = 37;
727
+ break;
728
+ }
729
+
730
+ console.log(chalk.red('Aborted.'));
731
+ return _context7.abrupt("return");
732
+
733
+ case 37:
734
+ _data = omit(localCustomAppData, ['id']);
735
+
736
+ if (!options.dryRun) {
737
+ _context7.next = 43;
738
+ break;
739
+ }
740
+
741
+ console.log(chalk.gray('DRY RUN mode'));
742
+ console.log("A new Custom Application would be created for the Organization ".concat(organizationName, " with the following payload:"));
743
+ console.log(_JSON$stringify(_data));
744
+ return _context7.abrupt("return");
745
+
746
+ case 43:
747
+ _context7.next = 45;
748
+ return createCustomApplication({
749
+ mcApiUrl: mcApiUrl,
750
+ token: token,
751
+ organizationId: organizationId,
752
+ data: _data
753
+ });
754
+
755
+ case 45:
756
+ createdCustomApplication = _context7.sent;
757
+
758
+ if (createdCustomApplication) {
759
+ _context7.next = 48;
760
+ break;
761
+ }
762
+
763
+ throw new Error('Failed to create the Custom Application.');
764
+
765
+ case 48:
766
+ _customAppLink = getMcUrlLink(mcApiUrl, organizationId, createdCustomApplication.id);
767
+ console.log(chalk.green(_concatInstanceProperty(_context5 = "Custom Application created.\nThe \"applicationId\" in your local Custom Application config file should be updated with the application ID: ".concat(createdCustomApplication.id, ".\nYou can see the Custom Application data in the Merchant Center at ")).call(_context5, _customAppLink, ".")));
768
+ return _context7.abrupt("return");
769
+
770
+ case 51:
771
+ customAppLink = getMcUrlLink(mcApiUrl, fetchedCustomApplication.organizationId, fetchedCustomApplication.application.id);
772
+ configDiff = getConfigDiff(fetchedCustomApplication.application, localCustomAppData);
773
+
774
+ if (configDiff) {
775
+ _context7.next = 56;
776
+ break;
777
+ }
778
+
779
+ console.log(chalk.green("Custom Application is already up to date.\nYou can see the Custom Application data in the Merchant Center at ".concat(customAppLink, ".")));
780
+ return _context7.abrupt("return");
781
+
782
+ case 56:
783
+ console.log(configDiff);
784
+ _context7.next = 59;
785
+ return prompts({
786
+ type: 'text',
787
+ name: 'confirmation',
788
+ message: _concatInstanceProperty(_context6 = "You are about to update the Custom Application \"".concat(localCustomAppData.entryPointUriPath, "\" with the changes above, in the ")).call(_context6, mcApiUrl, " environment. Are you sure you want to proceed?"),
789
+ initial: 'yes'
790
+ });
791
+
792
+ case 59:
793
+ _yield$prompts3 = _context7.sent;
794
+ confirmation = _yield$prompts3.confirmation;
795
+
796
+ if (!(!confirmation || confirmation.toLowerCase().charAt(0) !== 'y')) {
797
+ _context7.next = 64;
798
+ break;
799
+ }
800
+
801
+ console.log(chalk.red('Aborted.'));
802
+ return _context7.abrupt("return");
803
+
804
+ case 64:
805
+ data = omit(localCustomAppData, ['id']);
806
+
807
+ if (!options.dryRun) {
808
+ _context7.next = 70;
809
+ break;
810
+ }
811
+
812
+ console.log(chalk.gray('DRY RUN mode'));
813
+ console.log("The Custom Application ".concat(data.name, " would be updated with the following payload:"));
814
+ console.log(_JSON$stringify(data));
815
+ return _context7.abrupt("return");
816
+
817
+ case 70:
818
+ _context7.next = 72;
819
+ return updateCustomApplication({
820
+ mcApiUrl: mcApiUrl,
821
+ token: token,
822
+ organizationId: fetchedCustomApplication.organizationId,
823
+ data: omit(localCustomAppData, ['id']),
824
+ applicationId: fetchedCustomApplication.application.id
825
+ });
826
+
827
+ case 72:
828
+ console.log(chalk.green("Custom Application updated.\nYou can see the Custom Application data in the Merchant Center at ".concat(customAppLink, ".")));
829
+
830
+ case 73:
831
+ case "end":
832
+ return _context7.stop();
833
+ }
834
+ }
835
+ }, _callee);
836
+ }));
837
+ return _run.apply(this, arguments);
838
+ }
839
+
840
+ export { run as default };