@madgex/fert 4.2.4 → 4.2.6

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.
@@ -1,9 +1,5 @@
1
1
  const { resolveConfig } = require('../utils/index.js');
2
- const {
3
- getConfigAPI,
4
- validateLocalConfigs,
5
- updateProjectConfigs,
6
- } = require('../utils/configs.js');
2
+ const { getConfigAPI, updateProjectConfigs } = require('../utils/configs.js');
7
3
  const chalk = require('chalk');
8
4
  const { log } = require('../utils/logging.js');
9
5
  const { getSchemaMeta } = require('../utils/getSchemaMeta.js');
@@ -97,9 +93,7 @@ const handlePublish = async (fertConfig, api, options) => {
97
93
  }
98
94
 
99
95
  try {
100
- await validateLocalConfigs(fertConfig, { catch: false });
101
96
  await updateProjectConfigs(fertConfig, { environment: options.publish });
102
- console.log('upload');
103
97
  } catch (err) {
104
98
  log.debug(err);
105
99
  process.exit(1);
@@ -5,10 +5,7 @@ const { resolveConfig } = require('../utils');
5
5
  const { log } = require('../utils/logging');
6
6
  const getAwsParam = require('./publish-tasks/get-aws-parameter');
7
7
  const AssetStoreUploader = require('./publish-tasks/asset-store-uploader');
8
- const {
9
- validateLocalConfigs,
10
- updateProjectConfigs,
11
- } = require('../utils/configs.js');
8
+ const { updateProjectConfigs } = require('../utils/configs.js');
12
9
  const {
13
10
  getCloudFrontDistributionsForDomain,
14
11
  } = require('../utils/lookup-cf-distribution-ids');
@@ -77,11 +74,9 @@ module.exports = async (root, options) => {
77
74
  const uploadResult = await assetStore.uploadDir(localDir);
78
75
 
79
76
  // validate & upload local configs to configuration API
80
- await validateLocalConfigs(fertConfig);
81
- await updateProjectConfigs(fertConfig),
82
- {
83
- environment: fertConfig.currBranch === 'master' ? 'production' : 'dev',
84
- };
77
+ await updateProjectConfigs(fertConfig, {
78
+ environment: fertConfig.currBranch === 'master' ? 'production' : 'dev',
79
+ });
85
80
 
86
81
  log.success(
87
82
  `Publish complete in ${(uploadResult.duration / 1000).toFixed(0)}s\n`
@@ -35,6 +35,15 @@ const validateLocalConfigs = async (fertConfig, options = { catch: true }) => {
35
35
  async (configName) => {
36
36
  try {
37
37
  const schema = api.getSchema(configName);
38
+ const isSchemaReadOnly = api._isSchemaReadOnly(schema);
39
+
40
+ if (isSchemaReadOnly) {
41
+ throw Error(
42
+ `You're trying to set values on a read-only (usually V5) config schema: ${configName}`
43
+ );
44
+ }
45
+
46
+ // check the entire config against the config validation
38
47
  const { error } = schema.validate(localConfigs[configName].data);
39
48
  if (error) {
40
49
  throw new Error(
@@ -42,6 +51,17 @@ const validateLocalConfigs = async (fertConfig, options = { catch: true }) => {
42
51
  );
43
52
  }
44
53
 
54
+ // validate all keys individually against the schema keys to ensure we're not trying to set any read-only keys
55
+ const config = localConfigs[configName].data;
56
+ for (const key in config) {
57
+ const keySchema = schema.extract(key);
58
+ if (api._isSchemaReadOnly(keySchema)) {
59
+ throw new Error(
60
+ `You're trying to set a read-only key on a config schema: ${configName}/${key}`
61
+ );
62
+ }
63
+ }
64
+
45
65
  log.success(`Config validated:`, chalk.bold(configName));
46
66
  } catch (err) {
47
67
  log.error(err.message);
@@ -125,6 +145,8 @@ const updateProjectConfigs = async (
125
145
  }
126
146
 
127
147
  try {
148
+ await validateLocalConfigs(fertConfig, { catch: false });
149
+
128
150
  const api = await getConfigAPI({
129
151
  clientPropertyId: fertConfig.clientPropertyId,
130
152
  environment,
@@ -135,7 +157,8 @@ const updateProjectConfigs = async (
135
157
  const { toRemove, toSet } = collateConfigs(api, localConfigs);
136
158
 
137
159
  spinner.text = 'Updating configs…';
138
- await Promise.all([removeConfigs(api, toRemove), setConfigs(api, toSet)]);
160
+ await setConfigs(api, toSet, spinner);
161
+ await removeConfigs(api, toRemove, spinner);
139
162
 
140
163
  const { host } = new URL(api.options.apiUrl);
141
164
  spinner.succeed(`Project configs applied to ${chalk.bold(host)}`);
@@ -204,24 +227,28 @@ const getUnsetKeysWithDefaults = (defaults = {}, config = {}) => {
204
227
  return diff;
205
228
  };
206
229
 
207
- const removeConfigs = async (api, toRemove) => {
230
+ const removeConfigs = async (api, toRemove, spinner) => {
208
231
  const deletePromises = Object.entries(toRemove).flatMap(
209
232
  ([configName, keys]) =>
210
- keys.map((key) =>
211
- api.deleteConfig(configName, key).catch((error) => {
233
+ keys.map(async (key) => {
234
+ try {
235
+ await api.deleteConfig(configName, key);
236
+ spinner.text = `Removed key ${chalk.bold(key)} from config: ${chalk.bold(configName)}`;
237
+ } catch (error) {
212
238
  log.error('Failed to remove config', { configName, key, error });
213
- })
214
- )
239
+ }
240
+ })
215
241
  );
216
242
 
217
243
  await Promise.all(deletePromises);
218
244
  };
219
245
 
220
- const setConfigs = async (api, toSet) => {
246
+ const setConfigs = async (api, toSet, spinner) => {
221
247
  const setPromises = Object.entries(toSet).flatMap(([configName, config]) =>
222
248
  Object.entries(config).map(async ([key, value]) => {
223
249
  try {
224
250
  await api.setConfig(configName, key, value);
251
+ spinner.text = `Set key ${chalk.bold(key)} for config: ${chalk.bold(configName)}`;
225
252
  } catch (error) {
226
253
  log.error('Failed to set config', { configName, key, value, error });
227
254
  }
@@ -230,6 +257,7 @@ const setConfigs = async (api, toSet) => {
230
257
 
231
258
  await Promise.all(setPromises);
232
259
  };
260
+
233
261
  module.exports = {
234
262
  getConfigAPI,
235
263
  validateLocalConfigs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madgex/fert",
3
- "version": "4.2.4",
3
+ "version": "4.2.6",
4
4
  "description": "Tool to help build the V6 branding",
5
5
  "bin": {
6
6
  "fert": "./bin/cli.js"