@commercetools-frontend/mc-scripts 0.0.0-CRAFT-1791-20251006162610

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 (121) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.d.ts +2 -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/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js +7 -0
  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 +8 -0
  10. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts +2 -0
  11. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +199 -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 +199 -0
  14. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +184 -0
  15. package/cli/package.json +4 -0
  16. package/config/create-webpack-config-for-development.js +8 -0
  17. package/config/create-webpack-config-for-production.js +8 -0
  18. package/config/vendors-to-transpile.js +6 -0
  19. package/dist/build-2a0a18bd.esm.js +155 -0
  20. package/dist/build-521f3f9f.cjs.prod.js +169 -0
  21. package/dist/build-988fc0f7.cjs.dev.js +169 -0
  22. package/dist/build-vite-16b1a575.cjs.dev.js +238 -0
  23. package/dist/build-vite-59e1f185.esm.js +208 -0
  24. package/dist/build-vite-5d317720.cjs.prod.js +238 -0
  25. package/dist/commercetools-frontend-mc-scripts.cjs.d.ts +2 -0
  26. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +29 -0
  27. package/dist/commercetools-frontend-mc-scripts.cjs.js +7 -0
  28. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +29 -0
  29. package/dist/commercetools-frontend-mc-scripts.esm.js +21 -0
  30. package/dist/compile-html-025cd493.esm.js +34 -0
  31. package/dist/compile-html-50fd05ec.cjs.prod.js +42 -0
  32. package/dist/compile-html-f4ac88cc.cjs.dev.js +42 -0
  33. package/dist/config-sync-70a16916.cjs.dev.js +852 -0
  34. package/dist/config-sync-72c20d80.cjs.prod.js +846 -0
  35. package/dist/config-sync-bc895390.esm.js +830 -0
  36. package/dist/create-postcss-config-cb7be312.cjs.dev.js +81 -0
  37. package/dist/create-postcss-config-dde0ccf1.esm.js +75 -0
  38. package/dist/create-postcss-config-edca0c33.cjs.prod.js +81 -0
  39. package/dist/create-webpack-config-for-development-1aed1cc0.cjs.prod.js +465 -0
  40. package/dist/create-webpack-config-for-development-a95f3634.esm.js +440 -0
  41. package/dist/create-webpack-config-for-development-d003697b.cjs.dev.js +465 -0
  42. package/dist/create-webpack-config-for-production-15fbe7db.cjs.dev.js +523 -0
  43. package/dist/create-webpack-config-for-production-764c482f.cjs.prod.js +523 -0
  44. package/dist/create-webpack-config-for-production-9f42c336.esm.js +493 -0
  45. package/dist/credentials-storage-66c1e51f.cjs.prod.js +95 -0
  46. package/dist/credentials-storage-d001f726.esm.js +83 -0
  47. package/dist/credentials-storage-e7884d17.cjs.dev.js +95 -0
  48. package/dist/declarations/src/application-runtime.d.ts +1 -0
  49. package/dist/declarations/src/cli.d.ts +4 -0
  50. package/dist/declarations/src/config/create-postcss-config.d.ts +4 -0
  51. package/dist/declarations/src/config/create-webpack-config-for-development.d.ts +10 -0
  52. package/dist/declarations/src/config/create-webpack-config-for-production.d.ts +10 -0
  53. package/dist/declarations/src/config/vendors-to-transpile.d.ts +2 -0
  54. package/dist/declarations/src/deprecated-entry-points.d.ts +7 -0
  55. package/dist/declarations/src/index.d.ts +3 -0
  56. package/dist/declarations/src/postcss.d.ts +1 -0
  57. package/dist/declarations/src/types.d.ts +94 -0
  58. package/dist/declarations/src/version.d.ts +2 -0
  59. package/dist/declarations/src/webpack-loaders/i18n-message-compilation-loader.d.ts +3 -0
  60. package/dist/declarations/src/webpack.d.ts +2 -0
  61. package/dist/deployment-previews-set-17e8ed48.cjs.prod.js +202 -0
  62. package/dist/deployment-previews-set-3648972f.esm.js +191 -0
  63. package/dist/deployment-previews-set-37aef990.cjs.dev.js +202 -0
  64. package/dist/does-file-exist-32618334.esm.js +12 -0
  65. package/dist/does-file-exist-be53305d.cjs.prod.js +18 -0
  66. package/dist/does-file-exist-eb86baca.cjs.dev.js +18 -0
  67. package/dist/graphql-requests-6a47ad5b.esm.js +247 -0
  68. package/dist/graphql-requests-779b867b.cjs.dev.js +270 -0
  69. package/dist/graphql-requests-8086eba7.cjs.prod.js +270 -0
  70. package/dist/has-jsx-runtime-aa5d21ee.cjs.dev.js +15 -0
  71. package/dist/has-jsx-runtime-c3202df5.cjs.prod.js +15 -0
  72. package/dist/has-jsx-runtime-e3ecb09b.esm.js +13 -0
  73. package/dist/i18n-message-complilation-21d3b0aa.esm.js +15 -0
  74. package/dist/i18n-message-complilation-7311cb29.cjs.dev.js +23 -0
  75. package/dist/i18n-message-complilation-7762da61.cjs.prod.js +23 -0
  76. package/dist/login-0a728449.esm.js +229 -0
  77. package/dist/login-817a5a26.cjs.dev.js +270 -0
  78. package/dist/login-85c25393.cjs.prod.js +270 -0
  79. package/dist/optimizations-7789145e.cjs.dev.js +85 -0
  80. package/dist/optimizations-bf991634.esm.js +67 -0
  81. package/dist/optimizations-fb93514f.cjs.prod.js +85 -0
  82. package/dist/package-7e170dc4.cjs.dev.js +160 -0
  83. package/dist/package-940b0a2a.cjs.prod.js +160 -0
  84. package/dist/package-99e547a7.esm.js +158 -0
  85. package/dist/paths-39f22b8b.esm.js +36 -0
  86. package/dist/paths-7768b440.cjs.prod.js +44 -0
  87. package/dist/paths-b76fc753.cjs.dev.js +44 -0
  88. package/dist/serve-1036c2de.esm.js +55 -0
  89. package/dist/serve-50d33f0b.cjs.dev.js +64 -0
  90. package/dist/serve-8a506da6.cjs.prod.js +64 -0
  91. package/dist/start-1d677ad8.cjs.dev.js +177 -0
  92. package/dist/start-2a7ae03d.esm.js +164 -0
  93. package/dist/start-f56cb5f7.cjs.prod.js +177 -0
  94. package/dist/start-vite-068e9f73.cjs.dev.js +128 -0
  95. package/dist/start-vite-29078b3a.cjs.prod.js +128 -0
  96. package/dist/start-vite-7d1161e8.esm.js +116 -0
  97. package/dist/vendors-to-transpile-04a49d40.cjs.prod.js +5 -0
  98. package/dist/vendors-to-transpile-6ab4ea06.cjs.dev.js +5 -0
  99. package/dist/vendors-to-transpile-7dc84a72.esm.js +3 -0
  100. package/dist/vite-plugin-svgr-4034a834.cjs.prod.js +151 -0
  101. package/dist/vite-plugin-svgr-7d06f400.cjs.dev.js +151 -0
  102. package/dist/vite-plugin-svgr-de6ee7da.esm.js +125 -0
  103. package/package.json +156 -0
  104. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts +2 -0
  105. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +12 -0
  106. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.js +7 -0
  107. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +12 -0
  108. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +4 -0
  109. package/postcss/package.json +4 -0
  110. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts +2 -0
  111. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +57 -0
  112. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.js +7 -0
  113. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +57 -0
  114. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +48 -0
  115. package/webpack/package.json +4 -0
  116. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.d.ts +3 -0
  117. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.dev.js +30 -0
  118. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.js +7 -0
  119. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.prod.js +30 -0
  120. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.esm.js +26 -0
  121. package/webpack-loaders/i18n-message-compilation-loader/package.json +4 -0
@@ -0,0 +1,202 @@
1
+ 'use strict';
2
+
3
+ var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
4
+ var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
5
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
6
+ var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
7
+ var chalk = require('chalk');
8
+ var prompts = require('prompts');
9
+ var applicationConfig = require('@commercetools-frontend/application-config');
10
+ var credentialsStorage$1 = require('./credentials-storage-e7884d17.cjs.dev.js');
11
+ var graphqlRequests = require('./graphql-requests-779b867b.cjs.dev.js');
12
+ require('@commercetools/http-user-agent');
13
+ require('./package-7e170dc4.cjs.dev.js');
14
+ require('@babel/runtime-corejs3/helpers/classCallCheck');
15
+ require('@babel/runtime-corejs3/helpers/createClass');
16
+ require('@babel/runtime-corejs3/core-js-stable/json/stringify');
17
+ require('@babel/runtime-corejs3/core-js-stable/date/now');
18
+ require('node:fs');
19
+ require('node:os');
20
+ require('node:path');
21
+ require('./does-file-exist-eb86baca.cjs.dev.js');
22
+ require('@babel/runtime-corejs3/core-js-stable/object/keys');
23
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
24
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
25
+ require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
26
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
27
+ require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
28
+ require('@babel/runtime-corejs3/core-js-stable/object/define-property');
29
+ require('@babel/runtime-corejs3/helpers/defineProperty');
30
+ require('@babel/runtime-corejs3/core-js-stable/instance/some');
31
+ require('graphql');
32
+ require('graphql-request');
33
+ require('@commercetools-frontend/constants');
34
+
35
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
36
+
37
+ var _URL__default = /*#__PURE__*/_interopDefault(_URL);
38
+ var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
39
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
40
+ var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
41
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
42
+ var prompts__default = /*#__PURE__*/_interopDefault(prompts);
43
+
44
+ const credentialsStorage = new credentialsStorage$1.CredentialsStorage();
45
+ const validateUrl = function () {
46
+ let url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
47
+ try {
48
+ var _context;
49
+ const urlSchema = new _URL__default["default"](url);
50
+ return _includesInstanceProperty__default["default"](_context = ['http:', 'https:']).call(_context, urlSchema.protocol);
51
+ } catch (error) {
52
+ return false;
53
+ }
54
+ };
55
+ const validateAlias = function () {
56
+ let alias = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
57
+ try {
58
+ new _URL__default["default"](`https://${alias}.commercetools.com/`);
59
+ return true;
60
+ } catch (error) {
61
+ return false;
62
+ }
63
+ };
64
+ const getMcUrlLink = _ref => {
65
+ let mcApiUrl = _ref.mcApiUrl,
66
+ organizationId = _ref.organizationId,
67
+ customEntityId = _ref.customEntityId,
68
+ isCustomView = _ref.isCustomView;
69
+ const mcUrl = mcApiUrl.replace('mc-api', 'mc');
70
+ const customEntityLink = `${mcUrl}/account/organizations/${organizationId}/custom-${isCustomView ? 'views' : 'applications'}/owned/${customEntityId}/deployment-previews`;
71
+ return customEntityLink;
72
+ };
73
+ const isCustomViewData = data => data.entryPointUriPath === undefined;
74
+ async function setDeploymentPreview(_ref2) {
75
+ var _context3;
76
+ let mcApiUrl = _ref2.mcApiUrl,
77
+ applicationId = _ref2.applicationId,
78
+ applicationIdentifier = _ref2.applicationIdentifier,
79
+ localCustomEntityData = _ref2.localCustomEntityData,
80
+ isCustomView = _ref2.isCustomView,
81
+ options = _ref2.options;
82
+ /*
83
+ 1. Check if the Custom Application exists in the Merchant Center.
84
+ 2. Ask for the alias and URL of the deployment preview.
85
+ 3. Check whether it exists a deployment preview with the same alias.
86
+ 4. If it exists, ask for confirmation to update it.
87
+ 5. If it doesn't exist, ask for confirmation to create it.
88
+ */
89
+
90
+ const fetchedCustomApplication = await graphqlRequests.fetchCustomApplication({
91
+ mcApiUrl,
92
+ entryPointUriPath: localCustomEntityData.entryPointUriPath,
93
+ applicationIdentifier
94
+ });
95
+ if (!fetchedCustomApplication) {
96
+ throw new Error(`The Custom Application "${applicationIdentifier}" does not exist in the Merchant Center. Please create a Custom Application first before configuring deployment previews.`);
97
+ }
98
+ let deploymentAlias = options.alias;
99
+ // If the alias was not provided as an argument to the script, let's ask for it.
100
+ if (!deploymentAlias) {
101
+ var _context2;
102
+ const _await$prompts = await prompts__default["default"]({
103
+ type: 'text',
104
+ name: 'alias',
105
+ message: _filterInstanceProperty__default["default"](_context2 = [`Enter the alias for the deployment preview`, options.dryRun && chalk__default["default"].gray('Using "--dry-run", no deployment preview will be created.')]).call(_context2, Boolean).join('\n'),
106
+ validate: value => validateAlias(value)
107
+ }),
108
+ alias = _await$prompts.alias;
109
+ deploymentAlias = alias;
110
+ }
111
+ const existingDeploymentPreview = _findInstanceProperty__default["default"](_context3 = fetchedCustomApplication.application.deployments).call(_context3, deployment => deployment.alias === deploymentAlias);
112
+ if (!options.alias && !options.url && existingDeploymentPreview) {
113
+ var _context4;
114
+ const _await$prompts2 = await prompts__default["default"]({
115
+ type: 'confirm',
116
+ name: 'aliasOverrideConfirmation',
117
+ message: _filterInstanceProperty__default["default"](_context4 = [`The alias "${chalk__default["default"].green(deploymentAlias)}" already exists. Do you want to proceed and update the URL?`, options.dryRun && chalk__default["default"].gray('Using "--dry-run", no deployment preview will be created.')]).call(_context4, Boolean).join('\n'),
118
+ initial: false
119
+ }),
120
+ aliasOverrideConfirmation = _await$prompts2.aliasOverrideConfirmation;
121
+ if (!aliasOverrideConfirmation) {
122
+ console.log(chalk__default["default"].red('Aborted.'));
123
+ return;
124
+ }
125
+ }
126
+ let deploymentUrl = options.url;
127
+ if (!deploymentUrl) {
128
+ var _context5;
129
+ const _await$prompts3 = await prompts__default["default"]({
130
+ type: 'text',
131
+ name: 'url',
132
+ message: _filterInstanceProperty__default["default"](_context5 = [`Enter the URL for the deployment preview`, options.dryRun && chalk__default["default"].gray('Using "--dry-run", no deployment preview will be created.')]).call(_context5, Boolean).join('\n'),
133
+ validate: value => validateUrl(value)
134
+ }),
135
+ url = _await$prompts3.url;
136
+ deploymentUrl = url;
137
+ }
138
+ if (options.dryRun) {
139
+ const message = existingDeploymentPreview ? `The existing deployment preview with alias "${deploymentAlias}" would have been updated with this url: "${deploymentUrl}".` : `A new deployment preview with alias "${deploymentAlias}" would have been created with this url: "${deploymentUrl}".`;
140
+ console.log(`\n${message}\n`);
141
+ return;
142
+ }
143
+ const mcDeploymentPreviewsLink = getMcUrlLink({
144
+ mcApiUrl,
145
+ organizationId: fetchedCustomApplication.organizationId,
146
+ customEntityId: fetchedCustomApplication.application.id,
147
+ isCustomView
148
+ });
149
+ if (existingDeploymentPreview) {
150
+ await graphqlRequests.updateCustomApplicationDeploymentPreview({
151
+ mcApiUrl,
152
+ organizationId: fetchedCustomApplication.organizationId,
153
+ applicationIdentifier,
154
+ deploymentId: existingDeploymentPreview.id,
155
+ data: {
156
+ url: deploymentUrl
157
+ }
158
+ });
159
+ console.log(chalk__default["default"].green(`Deployment preview with alias "${deploymentAlias}" updated successfully with URL "${deploymentUrl}".`));
160
+ console.log(chalk__default["default"].green(`You can access the deployment previews at: ${mcDeploymentPreviewsLink}`));
161
+ } else {
162
+ await graphqlRequests.createCustomApplicationDeploymentPreview({
163
+ mcApiUrl,
164
+ organizationId: fetchedCustomApplication.organizationId,
165
+ applicationIdentifier,
166
+ applicationId,
167
+ data: {
168
+ alias: deploymentAlias,
169
+ url: deploymentUrl
170
+ }
171
+ });
172
+ console.log(chalk__default["default"].green(`Deployment preview with alias "${deploymentAlias}" created successfully with URL "${deploymentUrl}".`));
173
+ console.log(chalk__default["default"].green(`You can access the deployment previews at: ${mcDeploymentPreviewsLink}`));
174
+ }
175
+ }
176
+ async function run(options) {
177
+ const applicationConfig$1 = await applicationConfig.processConfig();
178
+ const localCustomEntityData = applicationConfig$1.data;
179
+ const _applicationConfig$en = applicationConfig$1.env,
180
+ mcApiUrl = _applicationConfig$en.mcApiUrl,
181
+ applicationIdentifier = _applicationConfig$en.applicationIdentifier;
182
+ const isCustomView = isCustomViewData(localCustomEntityData);
183
+ console.log(`Using Merchant Center environment "${chalk__default["default"].green(mcApiUrl)}".`);
184
+ console.log();
185
+ const isSessionValid = credentialsStorage.isSessionValid(mcApiUrl);
186
+ if (!isSessionValid) {
187
+ throw new Error(`You don't have a valid session. Please, run the "mc-scripts login" command to authenticate yourself.`);
188
+ }
189
+ if (isCustomView) {
190
+ throw new Error('Deployments previews are not supported for Custom Views.');
191
+ }
192
+ await setDeploymentPreview({
193
+ mcApiUrl,
194
+ applicationId: localCustomEntityData.id,
195
+ applicationIdentifier,
196
+ localCustomEntityData,
197
+ isCustomView,
198
+ options
199
+ });
200
+ }
201
+
202
+ exports["default"] = run;
@@ -0,0 +1,12 @@
1
+ import fs from 'node:fs';
2
+
3
+ function doesFileExist(path) {
4
+ try {
5
+ fs.accessSync(path);
6
+ return true;
7
+ } catch (error) {
8
+ return false;
9
+ }
10
+ }
11
+
12
+ export { doesFileExist as d };
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ var fs = require('node:fs');
4
+
5
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
6
+
7
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
8
+
9
+ function doesFileExist(path) {
10
+ try {
11
+ fs__default["default"].accessSync(path);
12
+ return true;
13
+ } catch (error) {
14
+ return false;
15
+ }
16
+ }
17
+
18
+ exports.doesFileExist = doesFileExist;
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ var fs = require('node:fs');
4
+
5
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
6
+
7
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
8
+
9
+ function doesFileExist(path) {
10
+ try {
11
+ fs__default["default"].accessSync(path);
12
+ return true;
13
+ } catch (error) {
14
+ return false;
15
+ }
16
+ }
17
+
18
+ exports.doesFileExist = doesFileExist;
@@ -0,0 +1,247 @@
1
+ import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
2
+ import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
3
+ import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
4
+ import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
5
+ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
6
+ import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
7
+ import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
8
+ import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
9
+ import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
10
+ import _someInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/some';
11
+ import chalk from 'chalk';
12
+ import { print } from 'graphql';
13
+ import { GraphQLClient, ClientError } from 'graphql-request';
14
+ import { GRAPHQL_TARGETS, SUPPORTED_HEADERS } from '@commercetools-frontend/constants';
15
+ import { C as CredentialsStorage, u as userAgent } from './credentials-storage-d001f726.esm.js';
16
+
17
+ function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context3 = ownKeys(Object(t))).call(_context3, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
19
+ var CreateCustomApplicationDeploymentPreviewFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "mutation", name: { kind: "Name", value: "CreateCustomApplicationDeploymentPreview" }, 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: "applicationId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "ID" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "data" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "CustomApplicationDeploymentPreviewCreateInput" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "createCustomApplicationDeploymentPreview" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "organizationId" }, value: { kind: "Variable", name: { kind: "Name", value: "organizationId" } } }, { kind: "Argument", name: { kind: "Name", value: "applicationId" }, value: { kind: "Variable", name: { kind: "Name", value: "applicationId" } } }, { 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: [] }, { kind: "Field", name: { kind: "Name", value: "alias" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "url" }, arguments: [], directives: [] }] } }] } }], loc: { start: 0, end: 327, source: { body: "mutation CreateCustomApplicationDeploymentPreview(\n $organizationId: String!\n $applicationId: ID!\n $data: CustomApplicationDeploymentPreviewCreateInput!\n) {\n createCustomApplicationDeploymentPreview(\n organizationId: $organizationId\n applicationId: $applicationId\n data: $data\n ) {\n id\n alias\n url\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
20
+ 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 } } } };
21
+ var CreateCustomViewFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "mutation", name: { kind: "Name", value: "CreateCustomViewFromCli" }, 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: "CustomViewDraftDataInput" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "createCustomView" }, 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: 180, source: { body: "mutation CreateCustomViewFromCli(\n $organizationId: String!\n $data: CustomViewDraftDataInput!\n) {\n createCustomView(organizationId: $organizationId, data: $data) {\n id\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
22
+ 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: [] }] } }] } }, { kind: "Field", name: { kind: "Name", value: "deployments" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "url" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alias" }, arguments: [], directives: [] }] } }] } }] } }] } }], loc: { start: 0, end: 712, 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 deployments {\n id\n url\n alias\n }\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
23
+ var FetchCustomViewFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchCustomViewFromCli" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "customViewId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "organizationExtensionForCustomView" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "customViewId" }, value: { kind: "Variable", name: { kind: "Name", value: "customViewId" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "organizationId" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "customView" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "defaultLabel" }, 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: "url" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "typeSettings" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "size" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "locators" }, 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: [] }] } }] } }] } }] } }], loc: { start: 0, end: 399, source: { body: "query FetchCustomViewFromCli($customViewId: String!) {\n organizationExtensionForCustomView(customViewId: $customViewId) {\n organizationId\n customView {\n id\n defaultLabel\n labelAllLocales {\n locale\n value\n }\n url\n type\n typeSettings {\n size\n }\n locators\n permissions {\n name\n oAuthScopes\n }\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
24
+ 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 } } } };
25
+ var UpdateCustomApplicationDeploymentPreviewFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "mutation", name: { kind: "Name", value: "UpdateCustomApplicationDeploymentPreview" }, 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: "deploymentId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "ID" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "data" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "CustomApplicationDeploymentPreviewUpdateInput" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "updateCustomApplicationDeploymentPreview" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "organizationId" }, value: { kind: "Variable", name: { kind: "Name", value: "organizationId" } } }, { kind: "Argument", name: { kind: "Name", value: "deploymentId" }, value: { kind: "Variable", name: { kind: "Name", value: "deploymentId" } } }, { 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: [] }, { kind: "Field", name: { kind: "Name", value: "alias" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "url" }, arguments: [], directives: [] }] } }] } }], loc: { start: 0, end: 324, source: { body: "mutation UpdateCustomApplicationDeploymentPreview(\n $organizationId: String!\n $deploymentId: ID!\n $data: CustomApplicationDeploymentPreviewUpdateInput!\n) {\n updateCustomApplicationDeploymentPreview(\n organizationId: $organizationId\n deploymentId: $deploymentId\n data: $data\n ) {\n id\n alias\n url\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
26
+ 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 } } } };
27
+ var UpdateCustomViewFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "mutation", name: { kind: "Name", value: "UpdateCustomViewFromCli" }, 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: "CustomViewDraftDataInput" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "customViewId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "updateCustomView" }, 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: "customViewId" }, value: { kind: "Variable", name: { kind: "Name", value: "customViewId" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }] } }] } }], loc: { start: 0, end: 248, source: { body: "mutation UpdateCustomViewFromCli(\n $organizationId: String!\n $data: CustomViewDraftDataInput!\n $customViewId: String!\n) {\n updateCustomView(\n organizationId: $organizationId\n data: $data\n customViewId: $customViewId\n ) {\n id\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
28
+ const credentialsStorage = new CredentialsStorage();
29
+ async function requestWithTokenRetry(document, requestOptions) {
30
+ let retryCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
31
+ const shouldUseExperimentalIdentityAuthFlow = process.env.ENABLE_EXPERIMENTAL_IDENTITY_AUTH_FLOW === 'true';
32
+ const token = credentialsStorage.getToken(requestOptions.mcApiUrl);
33
+ const tokenHeader = shouldUseExperimentalIdentityAuthFlow ? {
34
+ [SUPPORTED_HEADERS.AUTHORIZATION]: `Bearer ${token}`
35
+ } : {
36
+ 'x-mc-cli-access-token': token
37
+ };
38
+ const client = new GraphQLClient(`${requestOptions.mcApiUrl}/graphql`, {
39
+ headers: _objectSpread(_objectSpread({
40
+ Accept: 'application/json',
41
+ 'Content-Type': 'application/json',
42
+ 'x-user-agent': userAgent
43
+ }, token ? tokenHeader : {}), requestOptions.headers)
44
+ });
45
+ try {
46
+ const result = await client.rawRequest(print(document), requestOptions.variables);
47
+
48
+ // In case a new session token is returned from the server, save it.
49
+ const refreshedSessionToken = result.headers.get('x-refreshed-session-token');
50
+ if (refreshedSessionToken) {
51
+ console.log(chalk.green('Session token refreshed.'));
52
+ console.log();
53
+ const refreshedSessionTokenExpiresAt = result.headers.get('x-refreshed-session-token-expires-at');
54
+ // Store the updated access token.
55
+ credentialsStorage.setToken(requestOptions.mcApiUrl, {
56
+ token: refreshedSessionToken,
57
+ expiresAt: Number(refreshedSessionTokenExpiresAt)
58
+ });
59
+ }
60
+ return result.data;
61
+ } catch (error) {
62
+ if (error instanceof ClientError) {
63
+ // If it's an unauthorized error, retry the request to force the token to be refreshed.
64
+ if (retryCount === 0 && error.response.errors && error.response.errors.length > 0) {
65
+ var _context;
66
+ const isUnauthorizedError = _someInstanceProperty(_context = error.response.errors).call(_context, graphqlError => graphqlError.extensions?.code === 'UNAUTHENTICATED');
67
+ if (isUnauthorizedError) {
68
+ console.log(chalk.yellow('Expired or invalid session token, attempting to retry the request with a refreshed token...'));
69
+ return requestWithTokenRetry(document, _objectSpread(_objectSpread({}, requestOptions), {}, {
70
+ headers: _objectSpread(_objectSpread({}, requestOptions.headers), {}, {
71
+ 'X-Force-Token': 'true'
72
+ })
73
+ }), retryCount + 1);
74
+ }
75
+ }
76
+ }
77
+ throw error;
78
+ }
79
+ }
80
+ const fetchCustomApplication = async _ref => {
81
+ let mcApiUrl = _ref.mcApiUrl,
82
+ entryPointUriPath = _ref.entryPointUriPath,
83
+ applicationIdentifier = _ref.applicationIdentifier;
84
+ const customAppData = await requestWithTokenRetry(FetchCustomApplicationFromCli, {
85
+ variables: {
86
+ entryPointUriPath
87
+ },
88
+ mcApiUrl,
89
+ headers: {
90
+ 'x-application-id': applicationIdentifier,
91
+ 'x-graphql-target': GRAPHQL_TARGETS.SETTINGS_SERVICE
92
+ }
93
+ });
94
+ return customAppData.organizationExtensionForCustomApplication;
95
+ };
96
+ const fetchCustomView = async _ref2 => {
97
+ let mcApiUrl = _ref2.mcApiUrl,
98
+ customViewId = _ref2.customViewId,
99
+ applicationIdentifier = _ref2.applicationIdentifier;
100
+ const customViewData = await requestWithTokenRetry(FetchCustomViewFromCli, {
101
+ variables: {
102
+ customViewId
103
+ },
104
+ mcApiUrl,
105
+ headers: {
106
+ 'x-custom-view-id': customViewId,
107
+ 'x-application-id': applicationIdentifier,
108
+ 'x-graphql-target': GRAPHQL_TARGETS.SETTINGS_SERVICE
109
+ }
110
+ });
111
+ return customViewData.organizationExtensionForCustomView;
112
+ };
113
+ const updateCustomApplication = async _ref3 => {
114
+ let mcApiUrl = _ref3.mcApiUrl,
115
+ applicationId = _ref3.applicationId,
116
+ organizationId = _ref3.organizationId,
117
+ data = _ref3.data,
118
+ applicationIdentifier = _ref3.applicationIdentifier;
119
+ const updatedCustomAppsData = await requestWithTokenRetry(UpdateCustomApplicationFromCli, {
120
+ variables: {
121
+ organizationId,
122
+ applicationId,
123
+ data
124
+ },
125
+ mcApiUrl,
126
+ headers: {
127
+ 'x-application-id': applicationIdentifier,
128
+ 'x-graphql-target': GRAPHQL_TARGETS.SETTINGS_SERVICE
129
+ }
130
+ });
131
+ return updatedCustomAppsData.updateCustomApplication;
132
+ };
133
+ const updateCustomView = async _ref4 => {
134
+ let mcApiUrl = _ref4.mcApiUrl,
135
+ organizationId = _ref4.organizationId,
136
+ data = _ref4.data,
137
+ customViewId = _ref4.customViewId,
138
+ applicationIdentifier = _ref4.applicationIdentifier;
139
+ const updatedCustomViewData = await requestWithTokenRetry(UpdateCustomViewFromCli, {
140
+ variables: {
141
+ organizationId,
142
+ customViewId,
143
+ data
144
+ },
145
+ mcApiUrl,
146
+ headers: {
147
+ 'x-custom-view-id': customViewId,
148
+ 'x-application-id': applicationIdentifier,
149
+ 'x-graphql-target': GRAPHQL_TARGETS.SETTINGS_SERVICE
150
+ }
151
+ });
152
+ return updatedCustomViewData.updateCustomView;
153
+ };
154
+ const createCustomApplication = async _ref5 => {
155
+ let mcApiUrl = _ref5.mcApiUrl,
156
+ organizationId = _ref5.organizationId,
157
+ data = _ref5.data,
158
+ applicationIdentifier = _ref5.applicationIdentifier;
159
+ const createdCustomAppData = await requestWithTokenRetry(CreateCustomApplicationFromCli, {
160
+ variables: {
161
+ organizationId,
162
+ data
163
+ },
164
+ mcApiUrl,
165
+ headers: {
166
+ 'x-application-id': applicationIdentifier,
167
+ 'x-graphql-target': GRAPHQL_TARGETS.SETTINGS_SERVICE
168
+ }
169
+ });
170
+ return createdCustomAppData.createCustomApplication;
171
+ };
172
+ const createCustomView = async _ref6 => {
173
+ let mcApiUrl = _ref6.mcApiUrl,
174
+ organizationId = _ref6.organizationId,
175
+ data = _ref6.data,
176
+ applicationIdentifier = _ref6.applicationIdentifier;
177
+ const createdCustomViewData = await requestWithTokenRetry(CreateCustomViewFromCli, {
178
+ variables: {
179
+ organizationId,
180
+ data
181
+ },
182
+ mcApiUrl,
183
+ headers: {
184
+ 'x-application-id': applicationIdentifier,
185
+ 'x-graphql-target': GRAPHQL_TARGETS.SETTINGS_SERVICE
186
+ }
187
+ });
188
+ return createdCustomViewData.createCustomView;
189
+ };
190
+ const fetchUserOrganizations = async _ref7 => {
191
+ let mcApiUrl = _ref7.mcApiUrl,
192
+ applicationIdentifier = _ref7.applicationIdentifier,
193
+ customViewId = _ref7.customViewId;
194
+ const userOrganizations = await requestWithTokenRetry(FetchMyOrganizationsFromCli, {
195
+ mcApiUrl,
196
+ headers: _objectSpread(_objectSpread({
197
+ 'x-application-id': applicationIdentifier
198
+ }, customViewId && {
199
+ 'x-custom-view-id': customViewId
200
+ }), {}, {
201
+ 'x-graphql-target': GRAPHQL_TARGETS.ADMINISTRATION_SERVICE
202
+ })
203
+ });
204
+ return userOrganizations.myOrganizations;
205
+ };
206
+ const createCustomApplicationDeploymentPreview = async _ref8 => {
207
+ let mcApiUrl = _ref8.mcApiUrl,
208
+ organizationId = _ref8.organizationId,
209
+ applicationId = _ref8.applicationId,
210
+ applicationIdentifier = _ref8.applicationIdentifier,
211
+ data = _ref8.data;
212
+ const createdDeploymentPreviewResult = await requestWithTokenRetry(CreateCustomApplicationDeploymentPreviewFromCli, {
213
+ variables: {
214
+ organizationId,
215
+ applicationId,
216
+ data
217
+ },
218
+ mcApiUrl,
219
+ headers: {
220
+ 'x-application-id': applicationIdentifier,
221
+ 'x-graphql-target': GRAPHQL_TARGETS.SETTINGS_SERVICE
222
+ }
223
+ });
224
+ return createdDeploymentPreviewResult.createCustomApplicationDeploymentPreview;
225
+ };
226
+ const updateCustomApplicationDeploymentPreview = async _ref9 => {
227
+ let mcApiUrl = _ref9.mcApiUrl,
228
+ organizationId = _ref9.organizationId,
229
+ deploymentId = _ref9.deploymentId,
230
+ data = _ref9.data,
231
+ applicationIdentifier = _ref9.applicationIdentifier;
232
+ const updatedDeploymentPreviewResult = await requestWithTokenRetry(UpdateCustomApplicationDeploymentPreviewFromCli, {
233
+ variables: {
234
+ organizationId,
235
+ deploymentId,
236
+ data
237
+ },
238
+ mcApiUrl,
239
+ headers: {
240
+ 'x-application-id': applicationIdentifier,
241
+ 'x-graphql-target': GRAPHQL_TARGETS.SETTINGS_SERVICE
242
+ }
243
+ });
244
+ return updatedDeploymentPreviewResult.updateCustomApplicationDeploymentPreview;
245
+ };
246
+
247
+ export { fetchUserOrganizations as a, fetchCustomView as b, createCustomApplication as c, createCustomView as d, updateCustomView as e, fetchCustomApplication as f, updateCustomApplicationDeploymentPreview as g, createCustomApplicationDeploymentPreview as h, updateCustomApplication as u };