@commercetools-frontend/mc-scripts 0.0.0-FEC-157-preview-releases-20241126230331

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 (156) 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.d.ts.map +1 -0
  5. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.dev.js +7 -0
  6. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.js +7 -0
  7. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js +7 -0
  8. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.esm.js +5 -0
  9. package/application-runtime/package.json +4 -0
  10. package/bin/cli.js +8 -0
  11. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts +2 -0
  12. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts.map +1 -0
  13. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +211 -0
  14. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.js +7 -0
  15. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +211 -0
  16. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +196 -0
  17. package/cli/package.json +4 -0
  18. package/config/create-webpack-config-for-development.js +8 -0
  19. package/config/create-webpack-config-for-production.js +8 -0
  20. package/config/vendors-to-transpile.js +6 -0
  21. package/dist/build-99744dae.cjs.prod.js +166 -0
  22. package/dist/build-a93715aa.esm.js +152 -0
  23. package/dist/build-f56ce7ec.cjs.dev.js +166 -0
  24. package/dist/build-vite-000f0a2d.cjs.prod.js +193 -0
  25. package/dist/build-vite-722f0dcf.esm.js +182 -0
  26. package/dist/build-vite-838c8e01.cjs.dev.js +193 -0
  27. package/dist/commercetools-frontend-mc-scripts.cjs.d.ts +2 -0
  28. package/dist/commercetools-frontend-mc-scripts.cjs.d.ts.map +1 -0
  29. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +29 -0
  30. package/dist/commercetools-frontend-mc-scripts.cjs.js +7 -0
  31. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +29 -0
  32. package/dist/commercetools-frontend-mc-scripts.esm.js +21 -0
  33. package/dist/compile-html-025cd493.esm.js +34 -0
  34. package/dist/compile-html-50fd05ec.cjs.prod.js +42 -0
  35. package/dist/compile-html-f4ac88cc.cjs.dev.js +42 -0
  36. package/dist/config-sync-2ff62f08.cjs.dev.js +845 -0
  37. package/dist/config-sync-b57f79e2.cjs.prod.js +839 -0
  38. package/dist/config-sync-cda7662e.esm.js +823 -0
  39. package/dist/create-postcss-config-2f709335.esm.js +75 -0
  40. package/dist/create-postcss-config-3b540c7c.cjs.prod.js +81 -0
  41. package/dist/create-postcss-config-5962fa01.cjs.dev.js +81 -0
  42. package/dist/create-webpack-config-for-development-7d9e4dc4.cjs.prod.js +463 -0
  43. package/dist/create-webpack-config-for-development-86baace3.esm.js +438 -0
  44. package/dist/create-webpack-config-for-development-b379913b.cjs.dev.js +463 -0
  45. package/dist/create-webpack-config-for-production-3a40f56b.cjs.dev.js +518 -0
  46. package/dist/create-webpack-config-for-production-5ec9d0e2.cjs.prod.js +518 -0
  47. package/dist/create-webpack-config-for-production-b6ee3116.esm.js +488 -0
  48. package/dist/credentials-storage-3cea94ea.cjs.dev.js +95 -0
  49. package/dist/credentials-storage-b13e1406.esm.js +83 -0
  50. package/dist/credentials-storage-dc849808.cjs.prod.js +95 -0
  51. package/dist/declarations/src/application-runtime.d.ts +1 -0
  52. package/dist/declarations/src/cli.d.ts +4 -0
  53. package/dist/declarations/src/commands/build-vite.d.ts +2 -0
  54. package/dist/declarations/src/commands/build.d.ts +2 -0
  55. package/dist/declarations/src/commands/compile-html.d.ts +3 -0
  56. package/dist/declarations/src/commands/config-sync.d.ts +3 -0
  57. package/dist/declarations/src/commands/deployment-previews-set.d.ts +3 -0
  58. package/dist/declarations/src/commands/login.d.ts +2 -0
  59. package/dist/declarations/src/commands/serve.d.ts +2 -0
  60. package/dist/declarations/src/commands/start-vite.d.ts +2 -0
  61. package/dist/declarations/src/commands/start.d.ts +2 -0
  62. package/dist/declarations/src/config/create-postcss-config.d.ts +4 -0
  63. package/dist/declarations/src/config/create-webpack-config-for-development.d.ts +10 -0
  64. package/dist/declarations/src/config/create-webpack-config-for-production.d.ts +10 -0
  65. package/dist/declarations/src/config/has-jsx-runtime.d.ts +2 -0
  66. package/dist/declarations/src/config/moment-locales.d.ts +2 -0
  67. package/dist/declarations/src/config/optimizations.d.ts +2 -0
  68. package/dist/declarations/src/config/paths.d.ts +12 -0
  69. package/dist/declarations/src/config/vendors-to-transpile.d.ts +2 -0
  70. package/dist/declarations/src/config/webpack-dev-server.config.d.ts +6 -0
  71. package/dist/declarations/src/deprecated-entry-points.d.ts +7 -0
  72. package/dist/declarations/src/generated/core.d.ts +739 -0
  73. package/dist/declarations/src/generated/settings.d.ts +2116 -0
  74. package/dist/declarations/src/index.d.ts +3 -0
  75. package/dist/declarations/src/postcss.d.ts +1 -0
  76. package/dist/declarations/src/types.d.ts +87 -0
  77. package/dist/declarations/src/utils/auth.d.ts +6 -0
  78. package/dist/declarations/src/utils/credentials-storage.d.ts +11 -0
  79. package/dist/declarations/src/utils/does-file-exist.d.ts +2 -0
  80. package/dist/declarations/src/utils/get-config-diff.d.ts +3 -0
  81. package/dist/declarations/src/utils/graphql-requests.d.ts +172 -0
  82. package/dist/declarations/src/utils/i18n-message-complilation.d.ts +4 -0
  83. package/dist/declarations/src/utils/user-agent.d.ts +2 -0
  84. package/dist/declarations/src/version.d.ts +2 -0
  85. package/dist/declarations/src/vite-plugins/vite-plugin-dynamic-base-assets-globals.d.ts +3 -0
  86. package/dist/declarations/src/vite-plugins/vite-plugin-i18n-message-compilation.d.ts +3 -0
  87. package/dist/declarations/src/vite-plugins/vite-plugin-merchant-center-customization.d.ts +4 -0
  88. package/dist/declarations/src/vite-plugins/vite-plugin-svgr.d.ts +3 -0
  89. package/dist/declarations/src/webpack-loaders/i18n-message-compilation-loader.d.ts +3 -0
  90. package/dist/declarations/src/webpack-plugins/final-stats-writer-plugin.d.ts +12 -0
  91. package/dist/declarations/src/webpack-plugins/local-html-webpack-plugin.d.ts +5 -0
  92. package/dist/declarations/src/webpack.d.ts +2 -0
  93. package/dist/deployment-previews-set-173d8491.cjs.dev.js +203 -0
  94. package/dist/deployment-previews-set-923f79de.esm.js +192 -0
  95. package/dist/deployment-previews-set-f451242a.cjs.prod.js +203 -0
  96. package/dist/does-file-exist-32618334.esm.js +12 -0
  97. package/dist/does-file-exist-be53305d.cjs.prod.js +18 -0
  98. package/dist/does-file-exist-eb86baca.cjs.dev.js +18 -0
  99. package/dist/graphql-requests-0e427050.esm.js +243 -0
  100. package/dist/graphql-requests-733aac06.cjs.dev.js +266 -0
  101. package/dist/graphql-requests-db54706e.cjs.prod.js +266 -0
  102. package/dist/has-jsx-runtime-aa5d21ee.cjs.dev.js +15 -0
  103. package/dist/has-jsx-runtime-c3202df5.cjs.prod.js +15 -0
  104. package/dist/has-jsx-runtime-e3ecb09b.esm.js +13 -0
  105. package/dist/i18n-message-complilation-21d3b0aa.esm.js +15 -0
  106. package/dist/i18n-message-complilation-7311cb29.cjs.dev.js +23 -0
  107. package/dist/i18n-message-complilation-7762da61.cjs.prod.js +23 -0
  108. package/dist/login-35f578e3.esm.js +86 -0
  109. package/dist/login-65c78b83.cjs.dev.js +103 -0
  110. package/dist/login-c616d769.cjs.prod.js +103 -0
  111. package/dist/optimizations-7789145e.cjs.dev.js +85 -0
  112. package/dist/optimizations-bf991634.esm.js +67 -0
  113. package/dist/optimizations-fb93514f.cjs.prod.js +85 -0
  114. package/dist/package-436331e6.cjs.dev.js +151 -0
  115. package/dist/package-a7096308.cjs.prod.js +151 -0
  116. package/dist/package-b2f2b4e5.esm.js +149 -0
  117. package/dist/paths-39f22b8b.esm.js +36 -0
  118. package/dist/paths-7768b440.cjs.prod.js +44 -0
  119. package/dist/paths-b76fc753.cjs.dev.js +44 -0
  120. package/dist/serve-5666b16a.cjs.prod.js +48 -0
  121. package/dist/serve-6a951584.esm.js +41 -0
  122. package/dist/serve-f898c45e.cjs.dev.js +48 -0
  123. package/dist/start-4e79e08f.esm.js +164 -0
  124. package/dist/start-569eb0f9.cjs.dev.js +177 -0
  125. package/dist/start-b0765c9a.cjs.prod.js +177 -0
  126. package/dist/start-vite-45bfc42f.esm.js +110 -0
  127. package/dist/start-vite-a68e1b9f.cjs.prod.js +122 -0
  128. package/dist/start-vite-a787f80d.cjs.dev.js +122 -0
  129. package/dist/vendors-to-transpile-04a49d40.cjs.prod.js +5 -0
  130. package/dist/vendors-to-transpile-6ab4ea06.cjs.dev.js +5 -0
  131. package/dist/vendors-to-transpile-7dc84a72.esm.js +3 -0
  132. package/dist/vite-plugin-svgr-069f402d.esm.js +83 -0
  133. package/dist/vite-plugin-svgr-7fb42bbf.cjs.dev.js +108 -0
  134. package/dist/vite-plugin-svgr-b080c510.cjs.prod.js +108 -0
  135. package/package.json +147 -0
  136. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts +2 -0
  137. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts.map +1 -0
  138. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +12 -0
  139. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.js +7 -0
  140. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +12 -0
  141. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +4 -0
  142. package/postcss/package.json +4 -0
  143. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts +2 -0
  144. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts.map +1 -0
  145. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +57 -0
  146. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.js +7 -0
  147. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +57 -0
  148. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +48 -0
  149. package/webpack/package.json +4 -0
  150. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.d.ts +3 -0
  151. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.d.ts.map +1 -0
  152. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.dev.js +30 -0
  153. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.js +7 -0
  154. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.prod.js +30 -0
  155. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.esm.js +26 -0
  156. package/webpack-loaders/i18n-message-compilation-loader/package.json +4 -0
@@ -0,0 +1,192 @@
1
+ import _URL from '@babel/runtime-corejs3/core-js-stable/url';
2
+ import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
3
+ import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
4
+ import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
5
+ import chalk from 'chalk';
6
+ import prompts from 'prompts';
7
+ import { processConfig } from '@commercetools-frontend/application-config';
8
+ import { C as CredentialsStorage } from './credentials-storage-b13e1406.esm.js';
9
+ import { f as fetchCustomApplication, g as updateCustomApplicationDeploymentPreview, h as createCustomApplicationDeploymentPreview } from './graphql-requests-0e427050.esm.js';
10
+ import '@commercetools/http-user-agent';
11
+ import './package-b2f2b4e5.esm.js';
12
+ import '@babel/runtime-corejs3/helpers/classCallCheck';
13
+ import '@babel/runtime-corejs3/helpers/createClass';
14
+ import '@babel/runtime-corejs3/core-js-stable/json/stringify';
15
+ import '@babel/runtime-corejs3/core-js-stable/date/now';
16
+ import 'fs';
17
+ import 'os';
18
+ import 'path';
19
+ import './does-file-exist-32618334.esm.js';
20
+ import 'node:fs';
21
+ import '@babel/runtime-corejs3/core-js-stable/object/keys';
22
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
23
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
24
+ import '@babel/runtime-corejs3/core-js-stable/instance/for-each';
25
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
26
+ import '@babel/runtime-corejs3/core-js-stable/object/define-properties';
27
+ import '@babel/runtime-corejs3/core-js-stable/object/define-property';
28
+ import '@babel/runtime-corejs3/helpers/defineProperty';
29
+ import '@babel/runtime-corejs3/core-js-stable/instance/some';
30
+ import 'graphql';
31
+ import 'graphql-request';
32
+ import '@commercetools-frontend/constants';
33
+
34
+ const credentialsStorage = new CredentialsStorage();
35
+ const validateUrl = function () {
36
+ let url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
37
+ try {
38
+ var _context;
39
+ const urlSchema = new _URL(url);
40
+ return _includesInstanceProperty(_context = ['http:', 'https:']).call(_context, urlSchema.protocol);
41
+ } catch (error) {
42
+ return false;
43
+ }
44
+ };
45
+ const validateAlias = function () {
46
+ let alias = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
47
+ try {
48
+ new _URL(`https://${alias}.commercetools.com/`);
49
+ return true;
50
+ } catch (error) {
51
+ return false;
52
+ }
53
+ };
54
+ const getMcUrlLink = _ref => {
55
+ let mcApiUrl = _ref.mcApiUrl,
56
+ organizationId = _ref.organizationId,
57
+ customEntityId = _ref.customEntityId,
58
+ isCustomView = _ref.isCustomView;
59
+ const mcUrl = mcApiUrl.replace('mc-api', 'mc');
60
+ const customEntityLink = `${mcUrl}/account/organizations/${organizationId}/custom-${isCustomView ? 'views' : 'applications'}/owned/${customEntityId}/deployment-previews`;
61
+ return customEntityLink;
62
+ };
63
+ const isCustomViewData = data => data.entryPointUriPath === undefined;
64
+ async function setDeploymentPreview(_ref2) {
65
+ var _context3;
66
+ let mcApiUrl = _ref2.mcApiUrl,
67
+ applicationId = _ref2.applicationId,
68
+ applicationIdentifier = _ref2.applicationIdentifier,
69
+ localCustomEntityData = _ref2.localCustomEntityData,
70
+ isCustomView = _ref2.isCustomView,
71
+ options = _ref2.options;
72
+ /*
73
+ 1. Check if the Custom Application exists in the Merchant Center.
74
+ 2. Ask for the alias and URL of the deployment preview.
75
+ 3. Check whether it exists a deployment preview with the same alias.
76
+ 4. If it exists, ask for confirmation to update it.
77
+ 5. If it doesn't exist, ask for confirmation to create it.
78
+ */
79
+
80
+ const fetchedCustomApplication = await fetchCustomApplication({
81
+ mcApiUrl,
82
+ entryPointUriPath: localCustomEntityData.entryPointUriPath,
83
+ applicationIdentifier
84
+ });
85
+ if (!fetchedCustomApplication) {
86
+ throw new Error(`The Custom Application "${applicationIdentifier}" does not exist in the Merchant Center. Please create a Custom Application first before configuring deployment previews.`);
87
+ }
88
+ let deploymentAlias = options.alias;
89
+ // If the alias was not provided as an argument to the script, let's ask for it.
90
+ if (!deploymentAlias) {
91
+ var _context2;
92
+ const _await$prompts = await prompts({
93
+ type: 'text',
94
+ name: 'alias',
95
+ message: _filterInstanceProperty(_context2 = [`Enter the alias for the deployment preview`, options.dryRun && chalk.gray('Using "--dry-run", no deployment preview will be created.')]).call(_context2, Boolean).join('\n'),
96
+ validate: value => validateAlias(value)
97
+ }),
98
+ alias = _await$prompts.alias;
99
+ deploymentAlias = alias;
100
+ }
101
+ const existingDeploymentPreview = _findInstanceProperty(_context3 = fetchedCustomApplication.application.deployments).call(_context3, deployment => deployment.alias === deploymentAlias);
102
+ if (!options.alias && !options.url && existingDeploymentPreview) {
103
+ var _context4;
104
+ const _await$prompts2 = await prompts({
105
+ type: 'confirm',
106
+ name: 'aliasOverrideConfirmation',
107
+ message: _filterInstanceProperty(_context4 = [`The alias "${chalk.green(deploymentAlias)}" already exists. Do you want to proceed and update the URL?`, options.dryRun && chalk.gray('Using "--dry-run", no deployment preview will be created.')]).call(_context4, Boolean).join('\n'),
108
+ initial: false
109
+ }),
110
+ aliasOverrideConfirmation = _await$prompts2.aliasOverrideConfirmation;
111
+ if (!aliasOverrideConfirmation) {
112
+ console.log(chalk.red('Aborted.'));
113
+ return;
114
+ }
115
+ }
116
+ let deploymentUrl = options.url;
117
+ if (!deploymentUrl) {
118
+ var _context5;
119
+ const _await$prompts3 = await prompts({
120
+ type: 'text',
121
+ name: 'url',
122
+ message: _filterInstanceProperty(_context5 = [`Enter the URL for the deployment preview`, options.dryRun && chalk.gray('Using "--dry-run", no deployment preview will be created.')]).call(_context5, Boolean).join('\n'),
123
+ validate: value => validateUrl(value)
124
+ }),
125
+ url = _await$prompts3.url;
126
+ deploymentUrl = url;
127
+ }
128
+ if (options.dryRun) {
129
+ 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}".`;
130
+ console.log(`\n${message}\n`);
131
+ return;
132
+ }
133
+ const mcDeploymentPreviewsLink = getMcUrlLink({
134
+ mcApiUrl,
135
+ organizationId: fetchedCustomApplication.organizationId,
136
+ customEntityId: fetchedCustomApplication.application.id,
137
+ isCustomView
138
+ });
139
+ if (existingDeploymentPreview) {
140
+ await updateCustomApplicationDeploymentPreview({
141
+ mcApiUrl,
142
+ organizationId: fetchedCustomApplication.organizationId,
143
+ applicationIdentifier,
144
+ deploymentId: existingDeploymentPreview.id,
145
+ data: {
146
+ url: deploymentUrl
147
+ }
148
+ });
149
+ console.log(chalk.green(`Deployment preview with alias "${deploymentAlias}" updated successfully with URL "${deploymentUrl}".`));
150
+ console.log(chalk.green(`You can access the deployment previews at: ${mcDeploymentPreviewsLink}`));
151
+ } else {
152
+ await createCustomApplicationDeploymentPreview({
153
+ mcApiUrl,
154
+ organizationId: fetchedCustomApplication.organizationId,
155
+ applicationIdentifier,
156
+ applicationId,
157
+ data: {
158
+ alias: deploymentAlias,
159
+ url: deploymentUrl
160
+ }
161
+ });
162
+ console.log(chalk.green(`Deployment preview with alias "${deploymentAlias}" created successfully with URL "${deploymentUrl}".`));
163
+ console.log(chalk.green(`You can access the deployment previews at: ${mcDeploymentPreviewsLink}`));
164
+ }
165
+ }
166
+ async function run(options) {
167
+ const applicationConfig = processConfig();
168
+ const localCustomEntityData = applicationConfig.data;
169
+ const _applicationConfig$en = applicationConfig.env,
170
+ mcApiUrl = _applicationConfig$en.mcApiUrl,
171
+ applicationIdentifier = _applicationConfig$en.applicationIdentifier;
172
+ const isCustomView = isCustomViewData(localCustomEntityData);
173
+ console.log(`Using Merchant Center environment "${chalk.green(mcApiUrl)}".`);
174
+ console.log();
175
+ const isSessionValid = credentialsStorage.isSessionValid(mcApiUrl);
176
+ if (!isSessionValid) {
177
+ throw new Error(`You don't have a valid session. Please, run the "mc-scripts login" command to authenticate yourself.`);
178
+ }
179
+ if (isCustomView) {
180
+ throw new Error('Deployments previews are not supported for Custom Views.');
181
+ }
182
+ await setDeploymentPreview({
183
+ mcApiUrl,
184
+ applicationId: localCustomEntityData.id,
185
+ applicationIdentifier,
186
+ localCustomEntityData,
187
+ isCustomView,
188
+ options
189
+ });
190
+ }
191
+
192
+ export { run as default };
@@ -0,0 +1,203 @@
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-dc849808.cjs.prod.js');
11
+ var graphqlRequests = require('./graphql-requests-db54706e.cjs.prod.js');
12
+ require('@commercetools/http-user-agent');
13
+ require('./package-a7096308.cjs.prod.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('fs');
19
+ require('os');
20
+ require('path');
21
+ require('./does-file-exist-be53305d.cjs.prod.js');
22
+ require('node:fs');
23
+ require('@babel/runtime-corejs3/core-js-stable/object/keys');
24
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
25
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
26
+ require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
27
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
28
+ require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
29
+ require('@babel/runtime-corejs3/core-js-stable/object/define-property');
30
+ require('@babel/runtime-corejs3/helpers/defineProperty');
31
+ require('@babel/runtime-corejs3/core-js-stable/instance/some');
32
+ require('graphql');
33
+ require('graphql-request');
34
+ require('@commercetools-frontend/constants');
35
+
36
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
37
+
38
+ var _URL__default = /*#__PURE__*/_interopDefault(_URL);
39
+ var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
40
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
41
+ var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
42
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
43
+ var prompts__default = /*#__PURE__*/_interopDefault(prompts);
44
+
45
+ const credentialsStorage = new credentialsStorage$1.CredentialsStorage();
46
+ const validateUrl = function () {
47
+ let url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
48
+ try {
49
+ var _context;
50
+ const urlSchema = new _URL__default["default"](url);
51
+ return _includesInstanceProperty__default["default"](_context = ['http:', 'https:']).call(_context, urlSchema.protocol);
52
+ } catch (error) {
53
+ return false;
54
+ }
55
+ };
56
+ const validateAlias = function () {
57
+ let alias = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
58
+ try {
59
+ new _URL__default["default"](`https://${alias}.commercetools.com/`);
60
+ return true;
61
+ } catch (error) {
62
+ return false;
63
+ }
64
+ };
65
+ const getMcUrlLink = _ref => {
66
+ let mcApiUrl = _ref.mcApiUrl,
67
+ organizationId = _ref.organizationId,
68
+ customEntityId = _ref.customEntityId,
69
+ isCustomView = _ref.isCustomView;
70
+ const mcUrl = mcApiUrl.replace('mc-api', 'mc');
71
+ const customEntityLink = `${mcUrl}/account/organizations/${organizationId}/custom-${isCustomView ? 'views' : 'applications'}/owned/${customEntityId}/deployment-previews`;
72
+ return customEntityLink;
73
+ };
74
+ const isCustomViewData = data => data.entryPointUriPath === undefined;
75
+ async function setDeploymentPreview(_ref2) {
76
+ var _context3;
77
+ let mcApiUrl = _ref2.mcApiUrl,
78
+ applicationId = _ref2.applicationId,
79
+ applicationIdentifier = _ref2.applicationIdentifier,
80
+ localCustomEntityData = _ref2.localCustomEntityData,
81
+ isCustomView = _ref2.isCustomView,
82
+ options = _ref2.options;
83
+ /*
84
+ 1. Check if the Custom Application exists in the Merchant Center.
85
+ 2. Ask for the alias and URL of the deployment preview.
86
+ 3. Check whether it exists a deployment preview with the same alias.
87
+ 4. If it exists, ask for confirmation to update it.
88
+ 5. If it doesn't exist, ask for confirmation to create it.
89
+ */
90
+
91
+ const fetchedCustomApplication = await graphqlRequests.fetchCustomApplication({
92
+ mcApiUrl,
93
+ entryPointUriPath: localCustomEntityData.entryPointUriPath,
94
+ applicationIdentifier
95
+ });
96
+ if (!fetchedCustomApplication) {
97
+ throw new Error(`The Custom Application "${applicationIdentifier}" does not exist in the Merchant Center. Please create a Custom Application first before configuring deployment previews.`);
98
+ }
99
+ let deploymentAlias = options.alias;
100
+ // If the alias was not provided as an argument to the script, let's ask for it.
101
+ if (!deploymentAlias) {
102
+ var _context2;
103
+ const _await$prompts = await prompts__default["default"]({
104
+ type: 'text',
105
+ name: 'alias',
106
+ 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'),
107
+ validate: value => validateAlias(value)
108
+ }),
109
+ alias = _await$prompts.alias;
110
+ deploymentAlias = alias;
111
+ }
112
+ const existingDeploymentPreview = _findInstanceProperty__default["default"](_context3 = fetchedCustomApplication.application.deployments).call(_context3, deployment => deployment.alias === deploymentAlias);
113
+ if (!options.alias && !options.url && existingDeploymentPreview) {
114
+ var _context4;
115
+ const _await$prompts2 = await prompts__default["default"]({
116
+ type: 'confirm',
117
+ name: 'aliasOverrideConfirmation',
118
+ 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'),
119
+ initial: false
120
+ }),
121
+ aliasOverrideConfirmation = _await$prompts2.aliasOverrideConfirmation;
122
+ if (!aliasOverrideConfirmation) {
123
+ console.log(chalk__default["default"].red('Aborted.'));
124
+ return;
125
+ }
126
+ }
127
+ let deploymentUrl = options.url;
128
+ if (!deploymentUrl) {
129
+ var _context5;
130
+ const _await$prompts3 = await prompts__default["default"]({
131
+ type: 'text',
132
+ name: 'url',
133
+ 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'),
134
+ validate: value => validateUrl(value)
135
+ }),
136
+ url = _await$prompts3.url;
137
+ deploymentUrl = url;
138
+ }
139
+ if (options.dryRun) {
140
+ 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}".`;
141
+ console.log(`\n${message}\n`);
142
+ return;
143
+ }
144
+ const mcDeploymentPreviewsLink = getMcUrlLink({
145
+ mcApiUrl,
146
+ organizationId: fetchedCustomApplication.organizationId,
147
+ customEntityId: fetchedCustomApplication.application.id,
148
+ isCustomView
149
+ });
150
+ if (existingDeploymentPreview) {
151
+ await graphqlRequests.updateCustomApplicationDeploymentPreview({
152
+ mcApiUrl,
153
+ organizationId: fetchedCustomApplication.organizationId,
154
+ applicationIdentifier,
155
+ deploymentId: existingDeploymentPreview.id,
156
+ data: {
157
+ url: deploymentUrl
158
+ }
159
+ });
160
+ console.log(chalk__default["default"].green(`Deployment preview with alias "${deploymentAlias}" updated successfully with URL "${deploymentUrl}".`));
161
+ console.log(chalk__default["default"].green(`You can access the deployment previews at: ${mcDeploymentPreviewsLink}`));
162
+ } else {
163
+ await graphqlRequests.createCustomApplicationDeploymentPreview({
164
+ mcApiUrl,
165
+ organizationId: fetchedCustomApplication.organizationId,
166
+ applicationIdentifier,
167
+ applicationId,
168
+ data: {
169
+ alias: deploymentAlias,
170
+ url: deploymentUrl
171
+ }
172
+ });
173
+ console.log(chalk__default["default"].green(`Deployment preview with alias "${deploymentAlias}" created successfully with URL "${deploymentUrl}".`));
174
+ console.log(chalk__default["default"].green(`You can access the deployment previews at: ${mcDeploymentPreviewsLink}`));
175
+ }
176
+ }
177
+ async function run(options) {
178
+ const applicationConfig$1 = applicationConfig.processConfig();
179
+ const localCustomEntityData = applicationConfig$1.data;
180
+ const _applicationConfig$en = applicationConfig$1.env,
181
+ mcApiUrl = _applicationConfig$en.mcApiUrl,
182
+ applicationIdentifier = _applicationConfig$en.applicationIdentifier;
183
+ const isCustomView = isCustomViewData(localCustomEntityData);
184
+ console.log(`Using Merchant Center environment "${chalk__default["default"].green(mcApiUrl)}".`);
185
+ console.log();
186
+ const isSessionValid = credentialsStorage.isSessionValid(mcApiUrl);
187
+ if (!isSessionValid) {
188
+ throw new Error(`You don't have a valid session. Please, run the "mc-scripts login" command to authenticate yourself.`);
189
+ }
190
+ if (isCustomView) {
191
+ throw new Error('Deployments previews are not supported for Custom Views.');
192
+ }
193
+ await setDeploymentPreview({
194
+ mcApiUrl,
195
+ applicationId: localCustomEntityData.id,
196
+ applicationIdentifier,
197
+ localCustomEntityData,
198
+ isCustomView,
199
+ options
200
+ });
201
+ }
202
+
203
+ 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;