@speedkit/cli 2.4.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -74,7 +74,7 @@ $ npm install -g @speedkit/cli
74
74
  $ sk COMMAND
75
75
  running command...
76
76
  $ sk (--version)
77
- @speedkit/cli/2.4.1 linux-x64 node-v20.11.1
77
+ @speedkit/cli/2.5.0 linux-x64 node-v20.11.1
78
78
  $ sk --help [COMMAND]
79
79
  USAGE
80
80
  $ sk COMMAND
@@ -26,6 +26,7 @@ export declare class DocumentHandlerServer {
26
26
  private createDataBaseMock;
27
27
  private createNodeVmContext;
28
28
  private createRequireMock;
29
+ private createFetchMock;
29
30
  private createProcessPartial;
30
31
  /**
31
32
  * Fetches and returns the latest dynamic fetcher from the code repository. If a new version is available online it is
@@ -7,14 +7,9 @@ const required_file_not_found_error_1 = tslib_1.__importDefault(require("./error
7
7
  const database_mock_1 = tslib_1.__importDefault(require("./templates/database-mock"));
8
8
  const vm = tslib_1.__importStar(require("vm"));
9
9
  const vm_error_1 = require("../onboarding/error/vm-error");
10
+ const path_1 = tslib_1.__importDefault(require("path"));
11
+ const files_1 = require("../../models/files");
10
12
  // documentHandlerDependencies
11
- var parse5 = require('parse5');
12
- var parse5Htmlparser2TreeAdapter = require('parse5-htmlparser2-tree-adapter');
13
- var domSerializer = require('dom-serializer');
14
- var domhandler = require('domhandler');
15
- var domelementtype = require('domelementtype');
16
- var domutils = require('domutils');
17
- var cssSelect = require('css-select');
18
13
  var fetch = require('node-fetch');
19
14
  class DocumentHandlerServer {
20
15
  customerConfig;
@@ -84,11 +79,6 @@ class DocumentHandlerServer {
84
79
  return `${this.getContextVars()} ${docHandler} ${docHandlerConfig}`;
85
80
  }
86
81
  async getDocumentHandler() {
87
- // todo use fetchRemoteFile from integration api
88
- if (!this.files.hasFile(document_handler_runtime_context_1.LOCAL_DOCUMENT_HANDLER)) {
89
- const response = await fetch(document_handler_runtime_context_1.LATEST_DOCUMENT_HANDLER_URL);
90
- return await response.text();
91
- }
92
82
  return this.files.getByName(document_handler_runtime_context_1.LOCAL_DOCUMENT_HANDLER).getContent();
93
83
  }
94
84
  async getDynamicFetcher() {
@@ -97,7 +87,7 @@ class DocumentHandlerServer {
97
87
  const response = await fetch(document_handler_runtime_context_1.LATEST_DYNAMIC_FETCHER_URL);
98
88
  return await this.bundleDynamicFetcher({ 'dynamic-fetcher': 'https://www.baqend.com/speed-kit/latest/' }, await response.text());
99
89
  }
100
- return this.files.getByName(document_handler_runtime_context_1.LOCAL_DYNAMIC_FETCHER).getContent();
90
+ return this.files.getByName(files_1.INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER).getContent();
101
91
  }
102
92
  async getDynamicFetcherConfig() {
103
93
  return this.files.getByName(document_handler_runtime_context_1.LOCAL_DYNAMIC_FETCHER_CONFIG).getContent();
@@ -145,7 +135,7 @@ class DocumentHandlerServer {
145
135
  process: this.createProcessPartial(),
146
136
  require: this.createRequireMock(),
147
137
  'URL': URL,
148
- 'fetch': fetch,
138
+ 'fetch': this.createFetchMock(),
149
139
  'Buffer': Buffer,
150
140
  };
151
141
  if (this.verboseLevel) {
@@ -159,40 +149,31 @@ class DocumentHandlerServer {
159
149
  return { baqend: { message: { RevalidateAssets: () => true } } };
160
150
  }
161
151
  if (module.includes('fetch')) {
162
- return async (url, options) => {
163
- if (this.verboseLevel) {
164
- this.cli.writeWarning(`[documentHandler.fetch]: ${url}`);
165
- }
166
- return fetch(url, options);
167
- };
168
- }
169
- if (module.includes('css-select')) {
170
- return cssSelect;
171
- }
172
- if (module.includes('domutils')) {
173
- return domutils;
174
- }
175
- if (module.includes('domelementtype')) {
176
- return domelementtype;
177
- }
178
- if (module.includes('domhandler')) {
179
- return domhandler;
180
- }
181
- if (module.includes('dom-serializer')) {
182
- return domSerializer;
183
- }
184
- if (module.includes('parse5-htmlparser2-tree-adapter')) {
185
- return parse5Htmlparser2TreeAdapter;
152
+ return this.createFetchMock();
186
153
  }
187
- if (module.includes('parse5')) {
188
- return parse5;
189
- }
190
- const moduleFileName = module.split('/')?.pop();
154
+ const fileExtension = path_1.default.extname(module);
155
+ const moduleFileName = path_1.default.basename(module, fileExtension);
191
156
  if (this.files.hasFile(moduleFileName)) {
192
157
  const vmContext = { module: { exports: {} }, exports: {}, ...this.createNodeVmContext() };
193
158
  vm.runInNewContext(this.files.getByName(moduleFileName).getContent(), vmContext);
194
159
  return { ...vmContext.module.exports, ...vmContext.exports };
195
160
  }
161
+ try {
162
+ const outerModule = require(module);
163
+ return outerModule;
164
+ }
165
+ catch (error) {
166
+ this.cli.writeError(`[documentHandler] could not load module: ${module}`);
167
+ this.cli.writeError(error.message);
168
+ }
169
+ };
170
+ }
171
+ createFetchMock() {
172
+ return async (url, options) => {
173
+ if (this.verboseLevel) {
174
+ this.cli.writeWarning(`[documentHandler.fetch]: ${url}`);
175
+ }
176
+ return fetch(url, options);
196
177
  };
197
178
  }
198
179
  createProcessPartial() {
@@ -210,9 +191,6 @@ class DocumentHandlerServer {
210
191
  * @returns {Promise<string>} a Promise which resolves to the latest dynamic fetcher
211
192
  */
212
193
  async bundleDynamicFetcher(basePaths, dynamicFetcher) {
213
- const IMPORT_PATHS = {
214
- 'dynamicFetcher': 'https://www.baqend.com/speed-kit/latest/',
215
- };
216
194
  return this.bundler.bundle({
217
195
  basePaths: basePaths,
218
196
  entryPoints: { "dynamicFetcher.js": dynamicFetcher },
@@ -21,6 +21,7 @@ export declare class OnboardingContext {
21
21
  readonly DEFAULT_SW_PATH = "https://www.baqend.com/speed-kit/latest/sw.js";
22
22
  readonly DEFAULT_SNIPPET_PATH = "https://www.baqend.com/speed-kit/latest/snippet.js";
23
23
  readonly DEFAULT_DF_PATH = "https://www.baqend.com/speed-kit/latest/dynamic-fetcher.js";
24
+ readonly DEFAULT_DOCUMENT_HANDLER_PATH = "https://www.baqend.com/speed-kit-handler/latest/DocumentHandler.js";
24
25
  constructor(customerPath: string, configName: string, local: boolean, verboseLevel?: boolean);
25
26
  }
26
27
  export type awsCredentials = {
@@ -43,6 +43,7 @@ class OnboardingContext {
43
43
  DEFAULT_SW_PATH = 'https://www.baqend.com/speed-kit/latest/sw.js';
44
44
  DEFAULT_SNIPPET_PATH = 'https://www.baqend.com/speed-kit/latest/snippet.js';
45
45
  DEFAULT_DF_PATH = 'https://www.baqend.com/speed-kit/latest/dynamic-fetcher.js';
46
+ DEFAULT_DOCUMENT_HANDLER_PATH = 'https://www.baqend.com/speed-kit-handler/latest/DocumentHandler.js';
46
47
  constructor(customerPath, configName, local, verboseLevel) {
47
48
  this.customerPath = customerPath;
48
49
  this.configName = configName;
@@ -128,6 +128,10 @@ class OnboardingServiceFactory {
128
128
  name: files_1.INTEGRATION_FILES.CUSTOM.LOADER,
129
129
  recipe: new external_recipe_1.ExternalRecipe(this.context.DEFAULT_SNIPPET_PATH, externalFileReader)
130
130
  },
131
+ {
132
+ name: files_1.INTEGRATION_FILES.CUSTOM.DOCUMENT_HANDLER,
133
+ recipe: new external_recipe_1.ExternalRecipe(this.context.DEFAULT_DOCUMENT_HANDLER_PATH, externalFileReader)
134
+ },
131
135
  ]);
132
136
  }
133
137
  getConfigApi(app) {
@@ -696,5 +696,5 @@
696
696
  ]
697
697
  }
698
698
  },
699
- "version": "2.4.1"
699
+ "version": "2.5.0"
700
700
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "2.4.1",
4
+ "version": "2.5.0",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"