@appdirect/sfb-toolkit 4.0.6 → 4.0.8

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 (42) hide show
  1. package/Dockerfile +1 -1
  2. package/bin/index.js +12 -4
  3. package/config/index.js +1 -3
  4. package/coverage/clover.xml +166 -161
  5. package/coverage/coverage-final.json +7 -7
  6. package/coverage/lcov-report/constants/customUserAttributesMock.js.html +1 -1
  7. package/coverage/lcov-report/constants/index.html +1 -1
  8. package/coverage/lcov-report/constants/pageUrls.js.html +1 -1
  9. package/coverage/lcov-report/constants/userMock.js.html +1 -1
  10. package/coverage/lcov-report/controllers/controllers-utils/assetsUtils.js.html +1 -1
  11. package/coverage/lcov-report/controllers/controllers-utils/index.html +1 -1
  12. package/coverage/lcov-report/controllers/data-filters/bootstrap-data-filter.js.html +4 -4
  13. package/coverage/lcov-report/controllers/data-filters/call-to-actions-filter.js.html +4 -4
  14. package/coverage/lcov-report/controllers/data-filters/index.html +1 -1
  15. package/coverage/lcov-report/controllers/index.html +21 -21
  16. package/coverage/lcov-report/controllers/index.js.html +164 -128
  17. package/coverage/lcov-report/front-end-utils/src/components/base/ResultItem.js.html +7 -7
  18. package/coverage/lcov-report/front-end-utils/src/components/base/SearchBar.js.html +3 -3
  19. package/coverage/lcov-report/front-end-utils/src/components/base/index.html +1 -1
  20. package/coverage/lcov-report/front-end-utils/src/components/base/item.js.html +11 -11
  21. package/coverage/lcov-report/front-end-utils/src/components/container.js.html +1 -1
  22. package/coverage/lcov-report/front-end-utils/src/components/data-view.js.html +1 -1
  23. package/coverage/lcov-report/front-end-utils/src/components/header-view.js.html +1 -1
  24. package/coverage/lcov-report/front-end-utils/src/components/index.html +1 -1
  25. package/coverage/lcov-report/front-end-utils/src/components/search.js.html +13 -13
  26. package/coverage/lcov-report/front-end-utils/src/constants/index.html +1 -1
  27. package/coverage/lcov-report/front-end-utils/src/constants/pageUrl.js.html +1 -1
  28. package/coverage/lcov-report/front-end-utils/src/constants/roleType.js.html +1 -1
  29. package/coverage/lcov-report/front-end-utils/src/constants/searchType.js.html +1 -1
  30. package/coverage/lcov-report/front-end-utils/src/utils/debounce.js.html +1 -1
  31. package/coverage/lcov-report/front-end-utils/src/utils/index.html +1 -1
  32. package/coverage/lcov-report/index.html +20 -20
  33. package/coverage/lcov-report/middlewares/config.js.html +1 -1
  34. package/coverage/lcov-report/middlewares/index.html +1 -1
  35. package/coverage/lcov.info +341 -330
  36. package/npm-shrinkwrap.json +86 -180
  37. package/package.json +6 -7
  38. package/readme.md +6 -0
  39. package/src/api/cors.js +29 -20
  40. package/src/controllers/index.js +58 -46
  41. package/src/tools/prompt-questions.js +78 -68
  42. package/src/tools/toolkit-common-vars.js +1 -1
@@ -1,9 +1,11 @@
1
+ /* eslint-disable */
2
+
1
3
  const yaml = require("js-yaml")
2
- const axios = require("axios")
3
4
  const fs = require("fs")
4
5
  const objectAssignDeep = require("object-assign-deep")
5
6
  const storefrontUtils = require("@appdirect/storefront-utils")
6
7
  const URI = require("urijs")
8
+ const fetch = require("node-fetch");
7
9
  const { merge } = require("lodash")
8
10
 
9
11
  const { callToActionsFilter } = require("./data-filters/call-to-actions-filter")
@@ -135,7 +137,7 @@ class Pages {
135
137
  this.config.marketplacePath,
136
138
  this.envData
137
139
  ),
138
- currentPage: page
140
+ currentPage: this.getPage(this.page),
139
141
  }),
140
142
  storefrontUtils.getQueryData(
141
143
  {
@@ -152,49 +154,55 @@ class Pages {
152
154
  }
153
155
  )
154
156
  )
155
- axios
156
- .get(apiURL, {
157
- baseURL: this.config.pageObjectsPath,
158
- headers: this.getDataHeaders()
159
- })
160
- .then(response => {
161
- const data = Pages.filterData(response.data)
162
- if (this.mockRole === "USER") {
163
- data.config.user = userMock
164
- }
165
- this.defaultLocale = data.config.defaultLocale || "en-US"
166
- resolve({
167
- config: this.config,
168
- ...data,
169
- i18n: Object.assign({}, data.i18n, {
170
- custom: this.getLocalization()
171
- })
157
+
158
+ fetch(this.config.pageObjectsPath + apiURL, {
159
+ method: 'GET',
160
+ redirect: 'follow',
161
+ follow: 20,
162
+ headers: this.getDataHeaders(),
163
+ })
164
+ .then(response => response.json())
165
+ .then(data => {
166
+ data = Pages.filterData(data)
167
+ if (this.mockRole === "USER") {
168
+ data.config.user = userMock;
169
+ }
170
+ if (this.isCustomPage(page)) {
171
+ data.config.pageId = this.getPage(page);
172
+ }
173
+ this.defaultLocale = data.config.defaultLocale || "en-US";
174
+ resolve({
175
+ config: this.config,
176
+ ...data,
177
+ i18n: Object.assign({}, data.i18n, {
178
+ custom: this.getLocalization()
172
179
  })
173
- })
174
- .catch(error => {
175
- console.log(error)
176
- if (error.response) {
177
- const statusCode = error.response.status
178
- if (
179
- statusCode &&
180
- Pages._isRecoverableBadLinkError(error.response)
181
- ) {
182
- const uri = URI(error.response.data.link)
183
- uri.addSearch(this.query)
184
- this.res.redirect(uri.valueOf())
185
- }
186
- console.error(
187
- `Unable to fetch page data with http status ${statusCode}`
188
- )
189
- this.renderErrorPage(statusCode)
190
- } else {
191
- const errorCode = error.code
192
- console.error(
193
- `Unable to fetch page data with error code ${errorCode}`
194
- )
195
- this.renderErrorPage(errorCode)
180
+ });
181
+ })
182
+ .catch(error => {
183
+ console.log(error)
184
+ if (error.response) {
185
+ const statusCode = error.response.status;
186
+ if (
187
+ statusCode &&
188
+ Pages._isRecoverableBadLinkError(error.response)
189
+ ) {
190
+ const uri = URI(error.response.data.link);
191
+ uri.addSearch(this.query);
192
+ this.res.redirect(uri.valueOf());
196
193
  }
197
- })
194
+ console.error(
195
+ `Unable to fetch page data with http status ${statusCode}`
196
+ );
197
+ this.renderErrorPage(statusCode);
198
+ } else {
199
+ const errorCode = error.code;
200
+ console.error(
201
+ `Unable to fetch page data with error code ${errorCode}`
202
+ );
203
+ this.renderErrorPage(errorCode);
204
+ }
205
+ });
198
206
  })
199
207
  }
200
208
 
@@ -227,7 +235,11 @@ class Pages {
227
235
  )
228
236
  )
229
237
  } catch (e) {
230
- console.log(`localization file ${locale} not found`)
238
+ if (e instanceof yaml.YAMLException) {
239
+ console.log('YAML Error:', e.message);
240
+ } else {
241
+ console.log(`localization file ${locale} not found`)
242
+ }
231
243
  }
232
244
  return {}
233
245
  }
@@ -303,9 +315,9 @@ class Pages {
303
315
  ).then(html => {
304
316
  if (html) {
305
317
  staticPage = new storefrontUtils.StaticContent(html, data)
306
- .addGlobalString()
307
318
  .addUnavDefaultContent(headerTpl)
308
319
  .addDataStore()
320
+ .addGlobalString()
309
321
  .addToolbar()
310
322
  .addPageReload401()
311
323
  }
@@ -400,7 +412,7 @@ class Pages {
400
412
  staticPage = new storefrontUtils.StaticContent(
401
413
  html,
402
414
  data,
403
- this.page
415
+ this.getPage(this.page)
404
416
  )
405
417
  .overrideDefaultStrings()
406
418
  .addDataStore()
@@ -1,73 +1,81 @@
1
- const fs = require("fs")
2
- const inquirer = require("inquirer")
3
- const axios = require("axios")
4
- const chalk = require("chalk")
5
- const { TOOLKIT_GLOBAL_CONFIG, THEME_TEMPLATES, WHO_ARE_YOU_PROMPT, EXTENSION_PROMPT } = require("./toolkit-common-vars")
1
+ const fs = require("fs");
2
+ const fetch = require("node-fetch");
3
+ const inquirer = require("inquirer");
4
+ const chalk = require("chalk");
5
+ const {
6
+ TOOLKIT_GLOBAL_CONFIG,
7
+ THEME_TEMPLATES,
8
+ WHO_ARE_YOU_PROMPT,
9
+ EXTENSION_PROMPT,
10
+ } = require("./toolkit-common-vars");
6
11
 
7
12
  // small function to check if item has been defined
8
- const isDefined = answer => !!answer
13
+ const isDefined = (answer) => !!answer;
9
14
 
10
15
  // checks if the string provided is valid folder name
11
- const isValidFolderName = toTest => {
12
- const pattern = new RegExp(/^[a-z0-9_-]+$/, "i")
13
- const result = pattern.test(toTest)
16
+ const isValidFolderName = (toTest) => {
17
+ const pattern = new RegExp(/^[a-z0-9_-]+$/, "i");
18
+ const result = pattern.test(toTest);
14
19
  if (!result) {
15
- console.error(chalk.red(`\n${toTest} does not seem as valid folder name.`))
20
+ console.error(chalk.red(`\n${toTest} does not seem as valid folder name.`));
16
21
  }
17
- return toTest !== "undefined" && result
18
- }
22
+ return toTest !== "undefined" && result;
23
+ };
19
24
 
20
25
  // gets only origin from the url
21
- const parseToUrl = toParse => {
26
+ const parseToUrl = (toParse) => {
22
27
  try {
23
- const myUrl = new URL(toParse)
24
- return Promise.resolve(myUrl.origin)
28
+ const myUrl = new URL(toParse);
29
+ return Promise.resolve(myUrl.origin);
25
30
  } catch (err) {
26
- return toParse
31
+ return toParse;
27
32
  }
28
- }
33
+ };
29
34
 
30
35
  // checks if the string provided is valid URL
31
- const isValidURL = toTest => {
36
+ const isValidURL = (toTest) => {
32
37
  const pattern = new RegExp(
33
38
  /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/,
34
39
  "i"
35
- )
36
- const result = pattern.test(toTest)
40
+ );
41
+ const result = pattern.test(toTest);
37
42
  if (!result) {
38
- console.error(chalk.red(`\n"${toTest}" does not seem as valid URL.`))
43
+ console.error(chalk.red(`\n"${toTest}" does not seem as valid URL.`));
39
44
  }
40
- return result
41
- }
42
- const isValidMarketplaceURL = async toTest => {
43
- if (!toTest || !isValidURL(toTest)) return false
44
- console.log("\n\n Verifiying Marketplace URL...")
45
+ return result;
46
+ };
47
+ const isValidMarketplaceURL = async (toTest) => {
48
+ if (!toTest || !isValidURL(toTest)) return false;
49
+ console.log("\n\n Verifiying Marketplace URL...");
45
50
  try {
46
- const response = await axios.get(
47
- `${toTest}/api/session/v1/frontend-context`
48
- )
49
- if (!response.data.bootstrap.marketPlaceName)
50
- throw Error("This is not a marketplace")
51
+ const response = await fetch(`${toTest}/api/session/v1/frontend-context`);
52
+ const data = await response.json();
53
+ if (!data.bootstrap.marketPlaceName)
54
+ throw Error("This is not a marketplace");
51
55
  } catch (err) {
52
56
  switch (err.code) {
53
57
  case "ETIMEDOUT":
54
- console.log(chalk.red(
55
- ` Unable to reach ${toTest}. Please make sure to provide valid marketplace URL and that if you are running a proxy, is it configured correctly with node https://jjasonclark.com/how-to-setup-node-behind-web-proxy/ \n`
56
- ))
57
- break
58
+ console.log(
59
+ chalk.red(
60
+ ` Unable to reach ${toTest}. Please make sure to provide valid marketplace URL and that if you are running a proxy, is it configured correctly with node https://jjasonclark.com/how-to-setup-node-behind-web-proxy/ \n`
61
+ )
62
+ );
63
+ break;
58
64
  default:
59
- console.log(chalk.red(
60
- ` ${toTest} does not seem to be a valid marketplace URL.\n`
61
- ))
62
- break
65
+ console.log(
66
+ chalk.red(
67
+ ` ${toTest} does not seem to be a valid marketplace URL.\n`
68
+ )
69
+ );
70
+ break;
63
71
  }
64
- return false
72
+ return false;
65
73
  }
66
- console.log(chalk.green(" Marketplace URL successfully verified.\n"))
67
- return true
68
- }
74
+ console.log(chalk.green(" Marketplace URL successfully verified.\n"));
75
+ return true;
76
+ };
69
77
 
70
- const licenseText = ` In order to use this software, please type 'agree' to accept the license agreement that can be found at https://help.appdirect.com/sfb-eula.pdf`
78
+ const licenseText = ` In order to use this software, please type 'agree' to accept the license agreement that can be found at https://help.appdirect.com/sfb-eula.pdf`;
71
79
 
72
80
  // list of default questions that could be prompt to user
73
81
  const QUESTIONS = [
@@ -76,14 +84,14 @@ const QUESTIONS = [
76
84
  name: "ProjectName",
77
85
  message: "Name of the project:",
78
86
  default: TOOLKIT_GLOBAL_CONFIG.defaultValues.projectName,
79
- validate: isValidFolderName
87
+ validate: isValidFolderName,
80
88
  },
81
89
  {
82
90
  type: "input",
83
91
  name: "ThemeName",
84
92
  message: "Customize the theme name:",
85
93
  default: TOOLKIT_GLOBAL_CONFIG.defaultValues.themeName,
86
- validate: isValidFolderName
94
+ validate: isValidFolderName,
87
95
  },
88
96
  {
89
97
  type: "input",
@@ -91,37 +99,39 @@ const QUESTIONS = [
91
99
  message: "Path to the Marketplace:",
92
100
  default: TOOLKIT_GLOBAL_CONFIG.defaultValues.marketplacePath,
93
101
  validate: isValidMarketplaceURL,
94
- filter: parseToUrl
102
+ filter: parseToUrl,
95
103
  },
96
104
  {
97
105
  type: "confirm",
98
106
  name: "PackTranslationsChoice",
99
107
  message: "Do you want to include translations in this package?",
100
- default: false
108
+ default: false,
101
109
  },
102
110
  {
103
111
  type: "input",
104
112
  name: "LicenseAgreement",
105
113
  message: licenseText,
106
- validate: isDefined
114
+ validate: isDefined,
107
115
  },
108
116
  {
109
117
  type: "list",
110
118
  name: "ThemeTemplates",
111
119
  message: "Choose a marketplace theme as a starting point:",
112
- choices: THEME_TEMPLATES
120
+ choices: THEME_TEMPLATES,
113
121
  },
114
122
  {
115
123
  type: "list",
116
124
  name: "WhoAreYou",
117
- message: "Please indicate which option most closely represents who you are:",
118
- choices: WHO_ARE_YOU_PROMPT
125
+ message:
126
+ "Please indicate which option most closely represents who you are:",
127
+ choices: WHO_ARE_YOU_PROMPT,
119
128
  },
120
129
  {
121
130
  type: "confirm",
122
131
  name: "PackSettingsChoice",
123
- message: "Do you want to include the Storefront Builder layout editor settings in this package? (This will override existing settings in the editor)",
124
- default: false
132
+ message:
133
+ "Do you want to include the Storefront Builder layout editor settings in this package? (This will override existing settings in the editor)",
134
+ default: false,
125
135
  },
126
136
  {
127
137
  type: "list",
@@ -143,35 +153,35 @@ const QUESTIONS = [
143
153
  "Path to the extension you want to build on the marketplace /app/:mypath (letter & dash, only) (This can be changed later):",
144
154
  validate: isValidFolderName,
145
155
  },
146
- ]
156
+ ];
147
157
 
148
158
  // use only selected question
149
159
  // list: Array<String>
150
- const chooseQuestions = list =>
151
- QUESTIONS.filter(question => list.includes(question.name))
160
+ const chooseQuestions = (list) =>
161
+ QUESTIONS.filter((question) => list.includes(question.name));
152
162
 
153
163
  // parse question if necessary (eg. want to update default)
154
164
  const parseQuestions = (questions, custom) =>
155
- chooseQuestions(questions).map(question => {
156
- const newCustom = custom.find(q => q.name === question.name)
165
+ chooseQuestions(questions).map((question) => {
166
+ const newCustom = custom.find((q) => q.name === question.name);
157
167
  return {
158
168
  ...question,
159
- ...newCustom
160
- }
161
- })
169
+ ...newCustom,
170
+ };
171
+ });
162
172
 
163
173
  // prompt to user with provided qustions
164
174
  const ask = (questions = [], custom = []) => {
165
175
  const toAsk =
166
176
  custom.length > 0
167
177
  ? parseQuestions(questions, custom)
168
- : chooseQuestions(questions)
169
- return inquirer.prompt(toAsk)
170
- }
178
+ : chooseQuestions(questions);
179
+ return inquirer.prompt(toAsk);
180
+ };
171
181
  module.exports = {
172
182
  ask,
173
183
  validateFun: {
174
184
  isValidFolderName,
175
- isValidURL
176
- }
177
- }
185
+ isValidURL,
186
+ },
187
+ };
@@ -15,7 +15,7 @@ const THEME_TEMPLATES_CONFIG_PATH = `${TOOLKIT_PATH}/themes-config.json`;
15
15
  const THEME_TEMPLATES = JSON.parse(fs.readFileSync(THEME_TEMPLATES_CONFIG_PATH));
16
16
  const PAGE_OBJECTS_SUFFIX = "/api/internal/storefront/v1";
17
17
  const THEME_COMPONENT_MODULE = "@appdirect/sfb-theme-components";
18
- const THEME_COMPONENT_VERSION = "0.0.331";
18
+ const THEME_COMPONENT_VERSION = "0.0.338";
19
19
  const SASS_MODULE = "sass";
20
20
  const SASS_VERSION = "1.57.1";
21
21
  const SASS_LOADER_MODULE = "sass-loader";