@speedkit/cli 2.21.0 → 2.23.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/CHANGELOG.md +20 -0
- package/README.md +12 -34
- package/dist/commands/prewarm.d.ts +5 -26
- package/dist/commands/prewarm.js +23 -103
- package/dist/models/cli-parameters.d.ts +4 -1
- package/dist/models/cli-parameters.js +3 -0
- package/dist/services/cli/cli-service-factory.d.ts +3 -0
- package/dist/services/cli/cli-service-factory.js +9 -1
- package/dist/services/cli/cli-service-model.d.ts +19 -11
- package/dist/services/cli/cli-service-model.js +8 -1
- package/dist/services/cli/cli-service.d.ts +20 -13
- package/dist/services/cli/cli-service.js +102 -66
- package/dist/services/config-api/client.d.ts +7 -9
- package/dist/services/config-api/client.js +26 -30
- package/dist/services/customer-config/customer-config-service-model.d.ts +1 -0
- package/dist/services/customer-config/customer-config-service.js +5 -1
- package/dist/services/customer-config/templates/config_SpeedKit.js.hbs +35 -1
- package/dist/services/customer-config/templates/config_customer.js.hbs +6 -2
- package/dist/services/customer-config/templates/config_documentHandler.js.hbs +5 -0
- package/dist/services/prewarm/assets/asset-api-client.d.ts +13 -0
- package/dist/services/prewarm/assets/asset-api-client.js +58 -0
- package/dist/services/prewarm/assets/asset-item.d.ts +14 -0
- package/dist/services/prewarm/assets/asset-item.js +29 -0
- package/dist/services/prewarm/assets/asset-list.d.ts +14 -0
- package/dist/services/prewarm/assets/asset-list.js +43 -0
- package/dist/services/prewarm/csv-reader.d.ts +5 -0
- package/dist/services/prewarm/csv-reader.js +34 -0
- package/dist/services/prewarm/error/invalid-origin-error.d.ts +2 -0
- package/dist/services/prewarm/error/invalid-origin-error.js +6 -0
- package/dist/services/prewarm/error/read-csv-error.d.ts +8 -0
- package/dist/services/prewarm/error/read-csv-error.js +18 -0
- package/dist/services/prewarm/index.d.ts +3 -0
- package/dist/services/prewarm/index.js +6 -0
- package/dist/services/prewarm/pre-warm-factory.d.ts +8 -0
- package/dist/services/prewarm/pre-warm-factory.js +40 -0
- package/dist/services/prewarm/pre-warm-model.d.ts +38 -0
- package/dist/services/prewarm/pre-warm-model.js +38 -0
- package/dist/services/prewarm/pre-warm-service.d.ts +21 -0
- package/dist/services/prewarm/pre-warm-service.js +154 -0
- package/oclif.manifest.json +24 -63
- package/package.json +1 -1
- package/dist/commands/pop-prewarm.d.ts +0 -17
- package/dist/commands/pop-prewarm.js +0 -90
- package/dist/services/cli/hooks.d.ts +0 -11
- package/dist/services/cli/hooks.js +0 -33
|
@@ -2,68 +2,79 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CliService = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
6
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk")); // interactive prompts
|
|
7
7
|
const core_1 = require("@oclif/core");
|
|
8
8
|
const cli_service_model_1 = require("./cli-service-model");
|
|
9
9
|
class CliService {
|
|
10
|
-
|
|
10
|
+
quiet;
|
|
11
11
|
style = chalk_1.default;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
buffer = [];
|
|
13
|
+
progressBar;
|
|
14
|
+
constructor(quiet = false) {
|
|
15
|
+
this.quiet = quiet;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
code(code, buffered = false) {
|
|
18
|
+
code = ` ${code} `;
|
|
17
19
|
if (buffered) {
|
|
18
|
-
this.buffer.push(this.style.white(
|
|
20
|
+
this.buffer.push(this.style.bgBlack.white(code));
|
|
19
21
|
return;
|
|
20
22
|
}
|
|
21
|
-
core_1.ux.
|
|
23
|
+
core_1.ux.log(this.style.bgBlack.white(code));
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
codeStyle(code) {
|
|
26
|
+
const padding = " ";
|
|
27
|
+
return this.style.bgGray.rgb(230, 126, 0)(`${padding}${code}${padding}`);
|
|
25
28
|
}
|
|
26
|
-
|
|
29
|
+
comment(message, buffered = false) {
|
|
27
30
|
if (buffered) {
|
|
28
|
-
this.buffer.push(this.style.
|
|
31
|
+
this.buffer.push(this.style.grey.italic(message));
|
|
29
32
|
return;
|
|
30
33
|
}
|
|
31
|
-
this.write(this.style.
|
|
34
|
+
this.write(this.style.grey.italic(message));
|
|
32
35
|
}
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
return;
|
|
36
|
+
async confirm(message, defaultAnswer = true) {
|
|
37
|
+
if (this.quiet) {
|
|
38
|
+
return defaultAnswer;
|
|
37
39
|
}
|
|
38
|
-
|
|
40
|
+
return (0, prompts_1.confirm)({
|
|
41
|
+
default: defaultAnswer,
|
|
42
|
+
message: this.getFormattedMessage(message),
|
|
43
|
+
});
|
|
39
44
|
}
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
this.buffer.push(this.style.red(message));
|
|
45
|
+
endAction(status) {
|
|
46
|
+
if (this.quiet) {
|
|
43
47
|
return;
|
|
44
48
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
switch (status) {
|
|
50
|
+
case cli_service_model_1.CliActionStatus.COMPLETED: {
|
|
51
|
+
core_1.ux.action.stop(this.style.green(cli_service_model_1.CliActionStatus.COMPLETED));
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case cli_service_model_1.CliActionStatus.FAILED: {
|
|
55
|
+
core_1.ux.action.stop(this.style.red(cli_service_model_1.CliActionStatus.FAILED));
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case cli_service_model_1.CliActionStatus.SKIPPED: {
|
|
59
|
+
core_1.ux.action.stop(this.style.yellow(cli_service_model_1.CliActionStatus.SKIPPED));
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
default: {
|
|
63
|
+
core_1.ux.action.stop();
|
|
64
|
+
}
|
|
51
65
|
}
|
|
52
|
-
this.write(this.style.grey.italic(message));
|
|
53
66
|
}
|
|
54
|
-
|
|
55
|
-
code
|
|
56
|
-
if (buffered) {
|
|
57
|
-
this.buffer.push(this.style.bgBlack.white(code));
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
core_1.ux.log(this.style.bgBlack.white(code));
|
|
67
|
+
exit(code = 0) {
|
|
68
|
+
core_1.ux.exit(code);
|
|
61
69
|
}
|
|
62
70
|
async prompt(message, options) {
|
|
63
|
-
|
|
71
|
+
if (this.quiet) {
|
|
72
|
+
return options?.defaultAnswer || "";
|
|
73
|
+
}
|
|
74
|
+
const { defaultAnswer, validator } = options;
|
|
64
75
|
return (0, prompts_1.input)({
|
|
65
|
-
message: this.getFormattedMessage(message),
|
|
66
76
|
default: defaultAnswer,
|
|
77
|
+
message: this.getFormattedMessage(message),
|
|
67
78
|
validate: (input) => {
|
|
68
79
|
if (typeof validator !== "function")
|
|
69
80
|
return true;
|
|
@@ -75,50 +86,75 @@ class CliService {
|
|
|
75
86
|
},
|
|
76
87
|
});
|
|
77
88
|
}
|
|
78
|
-
async confirm(message, defaultAnswer = true) {
|
|
79
|
-
return (0, prompts_1.confirm)({
|
|
80
|
-
message: this.getFormattedMessage(message),
|
|
81
|
-
default: defaultAnswer,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
89
|
async select(message, choices) {
|
|
85
90
|
return (0, prompts_1.select)({
|
|
86
|
-
message: this.getFormattedMessage(message),
|
|
87
91
|
choices,
|
|
92
|
+
message: this.getFormattedMessage(message),
|
|
88
93
|
});
|
|
89
94
|
}
|
|
95
|
+
spacer() {
|
|
96
|
+
core_1.ux.info("");
|
|
97
|
+
}
|
|
90
98
|
startAction(message) {
|
|
99
|
+
if (this.quiet) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
91
102
|
core_1.ux.action.start(message);
|
|
92
103
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
core_1.ux.action.stop(this.style.green(cli_service_model_1.CliActionStatus.COMPLETED));
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
case cli_service_model_1.CliActionStatus.FAILED: {
|
|
100
|
-
core_1.ux.action.stop(this.style.red(cli_service_model_1.CliActionStatus.FAILED));
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
case cli_service_model_1.CliActionStatus.SKIPPED: {
|
|
104
|
-
core_1.ux.action.stop(this.style.yellow(cli_service_model_1.CliActionStatus.SKIPPED));
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
default: {
|
|
108
|
-
core_1.ux.action.stop();
|
|
109
|
-
}
|
|
104
|
+
startProgress(total, start = 0, payload, config) {
|
|
105
|
+
if (this.quiet) {
|
|
106
|
+
return;
|
|
110
107
|
}
|
|
108
|
+
this.progressBar = core_1.ux.progress(config);
|
|
109
|
+
this.progressBar.start(total, start, payload);
|
|
110
|
+
}
|
|
111
|
+
stopProgress() {
|
|
112
|
+
if (this.quiet) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.progressBar.stop();
|
|
116
|
+
}
|
|
117
|
+
table(data, columns, options) {
|
|
118
|
+
core_1.ux.table(data, columns, options);
|
|
119
|
+
}
|
|
120
|
+
updateProgress(current, payload) {
|
|
121
|
+
if (this.quiet) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
this.progressBar.update(current, payload);
|
|
125
|
+
}
|
|
126
|
+
write(message, buffered = false) {
|
|
127
|
+
if (buffered) {
|
|
128
|
+
this.buffer.push(this.style.white(message));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
core_1.ux.info(message);
|
|
111
132
|
}
|
|
112
133
|
writeBuffer() {
|
|
113
134
|
core_1.ux.log(this.buffer.join(`\n`));
|
|
114
135
|
core_1.ux.log();
|
|
115
136
|
this.buffer = [];
|
|
116
137
|
}
|
|
117
|
-
|
|
118
|
-
|
|
138
|
+
writeError(message, buffered = false) {
|
|
139
|
+
if (buffered) {
|
|
140
|
+
this.buffer.push(this.style.red(message));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
this.write(this.style.red(message));
|
|
119
144
|
}
|
|
120
|
-
|
|
121
|
-
|
|
145
|
+
writeSuccess(message, buffered = false) {
|
|
146
|
+
if (buffered) {
|
|
147
|
+
this.buffer.push(this.style.green(message));
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
this.write(this.style.green(message));
|
|
151
|
+
}
|
|
152
|
+
writeWarning(message, buffered = false) {
|
|
153
|
+
if (buffered) {
|
|
154
|
+
this.buffer.push(this.style.yellow(message));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.write(this.style.yellow(message));
|
|
122
158
|
}
|
|
123
159
|
getFormattedMessage(questionText) {
|
|
124
160
|
return `${this.style.bold(questionText)}`;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EntityManager } from "baqend";
|
|
2
2
|
import EntityManagerFactory from "./factory/entity-manager-factory";
|
|
3
|
+
import RequestExtensionInterface from "./interface/request-extension-interface";
|
|
3
4
|
export default class Client {
|
|
4
|
-
private readonly entityManagerFactory;
|
|
5
|
-
private readonly app;
|
|
6
5
|
private readonly agent;
|
|
6
|
+
private readonly app;
|
|
7
|
+
private readonly entityManagerFactory;
|
|
7
8
|
constructor(app: string, entityManagerFactory: EntityManagerFactory);
|
|
8
|
-
|
|
9
|
+
createRequest(requestExtension: RequestExtensionInterface): Promise<RequestInit>;
|
|
10
|
+
getEntityManager(): Promise<EntityManager>;
|
|
9
11
|
getModule(moduleName: string): Promise<string>;
|
|
12
|
+
send(url: string, requestExtension?: RequestExtensionInterface): Promise<any>;
|
|
10
13
|
setModule(moduleName: string, moduleCode: string): Promise<string>;
|
|
11
|
-
/**
|
|
12
|
-
* @param requestExtension
|
|
13
|
-
*/
|
|
14
|
-
createRequest(requestExtension: RequestExtensionInterface): Promise<NonNullable<unknown>>;
|
|
15
|
-
private getEntityManager;
|
|
16
14
|
}
|
|
@@ -1,57 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const node_https_1 = require("node:https");
|
|
5
|
-
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
6
4
|
const deepmerge_1 = tslib_1.__importDefault(require("deepmerge"));
|
|
5
|
+
const node_https_1 = require("node:https");
|
|
7
6
|
const race_1 = require("../../helpers/race");
|
|
8
7
|
const REQUEST_TIMEOUT = 10_000;
|
|
9
8
|
const CONTENT_TYPE = "application/json;charset=UTF-8";
|
|
10
9
|
class Client {
|
|
11
|
-
entityManagerFactory;
|
|
12
|
-
app;
|
|
13
10
|
agent;
|
|
11
|
+
app;
|
|
12
|
+
entityManagerFactory;
|
|
14
13
|
constructor(app, entityManagerFactory) {
|
|
15
14
|
this.app = app;
|
|
16
15
|
this.entityManagerFactory = entityManagerFactory;
|
|
17
|
-
this.agent = new node_https_1.Agent({
|
|
18
|
-
}
|
|
19
|
-
async send(url, requestExtension = {}) {
|
|
20
|
-
const response = await (0, node_fetch_1.default)(url, await this.createRequest(requestExtension));
|
|
21
|
-
if (response.status !== 200) {
|
|
22
|
-
const json = await response.json();
|
|
23
|
-
throw new Error(json.message);
|
|
24
|
-
}
|
|
25
|
-
return await response.json();
|
|
26
|
-
}
|
|
27
|
-
async getModule(moduleName) {
|
|
28
|
-
const entityManager = await this.getEntityManager();
|
|
29
|
-
return await entityManager.code.loadCode(moduleName, "module");
|
|
30
|
-
}
|
|
31
|
-
async setModule(moduleName, moduleCode) {
|
|
32
|
-
const entityManager = await this.getEntityManager();
|
|
33
|
-
return await entityManager.code.saveCode(moduleName, "module", moduleCode);
|
|
16
|
+
this.agent = new node_https_1.Agent({ keepAlive: true, rejectUnauthorized: false });
|
|
34
17
|
}
|
|
35
|
-
/**
|
|
36
|
-
* @param requestExtension
|
|
37
|
-
*/
|
|
38
18
|
async createRequest(requestExtension) {
|
|
39
19
|
const entityManager = await this.getEntityManager();
|
|
40
20
|
const baseRequest = {
|
|
41
|
-
method: "GET",
|
|
42
21
|
headers: {
|
|
22
|
+
"Content-Type": CONTENT_TYPE,
|
|
43
23
|
Host: `${this.app}.app.baqend.com`,
|
|
44
24
|
authorization: `BAT ${entityManager.token}`,
|
|
45
|
-
"Content-Type": CONTENT_TYPE,
|
|
46
25
|
},
|
|
26
|
+
method: "GET",
|
|
47
27
|
timeout: REQUEST_TIMEOUT,
|
|
48
28
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
29
|
+
// @ts-expect-error agent seems not to be part of type RequestInit
|
|
30
|
+
return { ...(0, deepmerge_1.default)(baseRequest, requestExtension), agent: this.agent };
|
|
52
31
|
}
|
|
53
32
|
async getEntityManager() {
|
|
54
|
-
return
|
|
33
|
+
return (0, race_1.race)(this.entityManagerFactory.getEntityManager(this.app));
|
|
34
|
+
}
|
|
35
|
+
async getModule(moduleName) {
|
|
36
|
+
const entityManager = await this.getEntityManager();
|
|
37
|
+
return entityManager.code.loadCode(moduleName, "module");
|
|
38
|
+
}
|
|
39
|
+
async send(url, requestExtension = {}) {
|
|
40
|
+
const requestInit = await this.createRequest(requestExtension);
|
|
41
|
+
const response = await fetch(url, requestInit);
|
|
42
|
+
if (response.status !== 200) {
|
|
43
|
+
const message = await response.json();
|
|
44
|
+
throw new Error(message);
|
|
45
|
+
}
|
|
46
|
+
return response.json();
|
|
47
|
+
}
|
|
48
|
+
async setModule(moduleName, moduleCode) {
|
|
49
|
+
const entityManager = await this.getEntityManager();
|
|
50
|
+
return entityManager.code.saveCode(moduleName, "module", moduleCode);
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
53
|
exports.default = Client;
|
|
@@ -23,6 +23,7 @@ export interface CustomerConfigSettings {
|
|
|
23
23
|
appName?: string;
|
|
24
24
|
production?: EnvironmentConfig;
|
|
25
25
|
staging?: EnvironmentConfig;
|
|
26
|
+
subRouteScope?: string;
|
|
26
27
|
includeServiceWorker?: string;
|
|
27
28
|
activateImageOptimisation?: boolean;
|
|
28
29
|
removeLazyLoading?: boolean;
|
|
@@ -161,7 +161,7 @@ class CustomerConfigService {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
async getConfigSettings() {
|
|
164
|
-
let { production, staging, includeServiceWorker, activateImageOptimisation, removeLazyLoading, addPreRendering, activateRumTracking, useGATracking, withGoogleOptimize, activateCfRocketLoaderWorkaround, isShopify, isShopware, isSalesforce, isPlentymarkets, shopifyId, } = {};
|
|
164
|
+
let { production, staging, subRouteScope, includeServiceWorker, activateImageOptimisation, removeLazyLoading, addPreRendering, activateRumTracking, useGATracking, withGoogleOptimize, activateCfRocketLoaderWorkaround, isShopify, isShopware, isSalesforce, isPlentymarkets, shopifyId, } = {};
|
|
165
165
|
this.appName = await this.cli.prompt(`Enter SK App Name:`, {
|
|
166
166
|
validator: (input) => /^[\da-z]+(?:-[\da-z]+)*$/.test(input) ? "" : "No valid kebab-case",
|
|
167
167
|
defaultAnswer: this.appName,
|
|
@@ -199,6 +199,9 @@ class CustomerConfigService {
|
|
|
199
199
|
staging = await this.getEnvironmentConfig(customer_config_service_model_1.EnvironmentType.STAGING, production.host.replace("www", "stg"));
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
|
+
if (await this.cli.confirm("Should SK only be active on specific sub-routes? (e.g. /de-de)", false)) {
|
|
203
|
+
subRouteScope = await this.cli.prompt("Enter one exemplary sub-route to scope to (without leading/trailing slashes):", { defaultAnswer: "de-de" });
|
|
204
|
+
}
|
|
202
205
|
if (await this.cli.confirm("Is there a Service Worker which needs to be included?", false)) {
|
|
203
206
|
includeServiceWorker = await this.cli.prompt("Enter path of Service Worker to be included:", { defaultAnswer: "/sw.js" });
|
|
204
207
|
}
|
|
@@ -217,6 +220,7 @@ class CustomerConfigService {
|
|
|
217
220
|
appName: this.appName,
|
|
218
221
|
production,
|
|
219
222
|
staging,
|
|
223
|
+
subRouteScope,
|
|
220
224
|
includeServiceWorker,
|
|
221
225
|
activateImageOptimisation,
|
|
222
226
|
removeLazyLoading,
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
// Production:
|
|
4
4
|
{
|
|
5
5
|
hosts: ["{{production.host}}"],
|
|
6
|
+
{{#if subRouteScope}}
|
|
7
|
+
scopes: ["{{subRouteScope}}"],
|
|
8
|
+
{{/if}}
|
|
6
9
|
split: 0,
|
|
7
10
|
splitTestId: "0vs100_20xx-xx-xx",
|
|
8
11
|
},
|
|
@@ -11,6 +14,9 @@
|
|
|
11
14
|
// Staging:
|
|
12
15
|
{
|
|
13
16
|
hosts: ["{{staging.host}}"],
|
|
17
|
+
{{#if subRouteScope}}
|
|
18
|
+
scopes: ["{{subRouteScope}}"],
|
|
19
|
+
{{/if}}
|
|
14
20
|
},
|
|
15
21
|
{{else}}
|
|
16
22
|
// No Staging configured
|
|
@@ -100,7 +106,7 @@
|
|
|
100
106
|
// – unless this has been explicitly requested!
|
|
101
107
|
contentType: ["script", "style", "font"],
|
|
102
108
|
},
|
|
103
|
-
|
|
109
|
+
|
|
104
110
|
// Shopify specific:
|
|
105
111
|
{
|
|
106
112
|
url: [
|
|
@@ -323,7 +329,14 @@
|
|
|
323
329
|
|
|
324
330
|
// Lookup for matching enabled hosts config
|
|
325
331
|
for (var i = 0; i < enabledHostsConfigs.length; i++) {
|
|
332
|
+
{{#if subRouteScope}}
|
|
333
|
+
if (
|
|
334
|
+
enabledHostsConfigs[i].hosts.indexOf(currentHost) !== -1 &&
|
|
335
|
+
isCurrentScopeEnabled(enabledHostsConfigs[i].scopes)
|
|
336
|
+
) {
|
|
337
|
+
{{else}}
|
|
326
338
|
if (enabledHostsConfigs[i].hosts.indexOf(currentHost) !== -1) {
|
|
339
|
+
{{/if}}
|
|
327
340
|
foundHostConfig = enabledHostsConfigs[i];
|
|
328
341
|
break; // Break out of the loop once the config related to the host is found
|
|
329
342
|
}
|
|
@@ -348,4 +361,25 @@
|
|
|
348
361
|
};
|
|
349
362
|
}
|
|
350
363
|
}
|
|
364
|
+
{{#if subRouteScope}}
|
|
365
|
+
|
|
366
|
+
function isCurrentScopeEnabled(enabledScopes) {
|
|
367
|
+
// Check if enabled scopes are provided
|
|
368
|
+
if (!enabledScopes) {
|
|
369
|
+
// If not: consider current scope as enabled due to no scoping
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// Check if enabled scopes are provided as array
|
|
374
|
+
if (!Array.isArray(enabledScopes)) {
|
|
375
|
+
// If not: consider current scope as disabled due to faulty scoping
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// Test if current scope matches enabled scopes
|
|
380
|
+
var pattern = "^/(" + enabledScopes.join("|") + ")/";
|
|
381
|
+
var regex = new RegExp(pattern);
|
|
382
|
+
return regex.test(location.pathname);
|
|
383
|
+
}
|
|
384
|
+
{{/if}}
|
|
351
385
|
})();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shop
|
|
2
|
+
* Shop/Frontend system in use:
|
|
3
3
|
{{#if isShopify}}
|
|
4
4
|
* - Shopify
|
|
5
5
|
{{else if isShopware}}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
{{else if isPlentymarkets}}
|
|
10
10
|
* - Plentymarkets
|
|
11
11
|
{{else}}
|
|
12
|
-
* - TODO: enter name of
|
|
12
|
+
* - TODO: enter name of system in use
|
|
13
13
|
{{/if}}
|
|
14
14
|
*/
|
|
15
15
|
|
|
@@ -25,7 +25,11 @@ const shared = {
|
|
|
25
25
|
{{else}}
|
|
26
26
|
swPath: "/wrapper-sw.js",
|
|
27
27
|
{{/if}}
|
|
28
|
+
{{#if subRouteScope}}
|
|
29
|
+
scope: "/{{subRouteScope}}/",
|
|
30
|
+
{{else}}
|
|
28
31
|
scope: "/",
|
|
32
|
+
{{/if}}
|
|
29
33
|
};
|
|
30
34
|
|
|
31
35
|
const configs = {
|
|
@@ -45,6 +45,11 @@ const lazyLoadList = [
|
|
|
45
45
|
{{/unless}}
|
|
46
46
|
const config = {
|
|
47
47
|
rejectHTML({ db, {{#if addPreRendering}}document{{else}}html{{/if}}, variation, url, headers }) {
|
|
48
|
+
/* Use to configure guards to prevent e.g. error and captcha pages from being cached */
|
|
49
|
+
return false;
|
|
50
|
+
},
|
|
51
|
+
blacklistHTML({ db, {{#if addPreRendering}}document{{else}}html{{/if}}, variation, url, headers }) {
|
|
52
|
+
/* Use to configure guards to black-list e.g. specific page types */
|
|
48
53
|
return false;
|
|
49
54
|
},
|
|
50
55
|
shouldTransform({ db, {{#if addPreRendering}}document{{else}}html{{/if}}, variation, url, headers }) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class AssetApiClient {
|
|
2
|
+
private authenticationToken;
|
|
3
|
+
private app;
|
|
4
|
+
private sortParameters;
|
|
5
|
+
private agent;
|
|
6
|
+
private rateLimit;
|
|
7
|
+
constructor(authenticationToken: string, app: string, sortParameters: boolean);
|
|
8
|
+
fetchURL(url: string, variation: string): Promise<Response>;
|
|
9
|
+
getRateLimit(): number;
|
|
10
|
+
reduceMaxRequestsPerSecond(): void;
|
|
11
|
+
private isValidUrl;
|
|
12
|
+
private setRateLimit;
|
|
13
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssetApiClient = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_https_1 = require("node:https");
|
|
6
|
+
const node_url_1 = require("node:url");
|
|
7
|
+
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
8
|
+
const __1 = require("../");
|
|
9
|
+
const normalize_1 = require("../../../helpers/normalize");
|
|
10
|
+
const invalid_origin_error_1 = require("../error/invalid-origin-error");
|
|
11
|
+
class AssetApiClient {
|
|
12
|
+
authenticationToken;
|
|
13
|
+
app;
|
|
14
|
+
sortParameters;
|
|
15
|
+
agent = new node_https_1.Agent({
|
|
16
|
+
keepAlive: true,
|
|
17
|
+
rejectUnauthorized: false,
|
|
18
|
+
});
|
|
19
|
+
rateLimit = __1.DEFAULT_MAX_REQUESTS_PER_SECOND;
|
|
20
|
+
constructor(authenticationToken, app, sortParameters) {
|
|
21
|
+
this.authenticationToken = authenticationToken;
|
|
22
|
+
this.app = app;
|
|
23
|
+
this.sortParameters = sortParameters;
|
|
24
|
+
}
|
|
25
|
+
async fetchURL(url, variation) {
|
|
26
|
+
this.isValidUrl(url);
|
|
27
|
+
const assetUrl = new node_url_1.URL((0, normalize_1.normalize)(url, this.sortParameters));
|
|
28
|
+
if (variation !== "DEFAULT" && variation !== "DESKTOP") {
|
|
29
|
+
assetUrl.searchParams.set("bqvariation", variation.toLowerCase());
|
|
30
|
+
}
|
|
31
|
+
assetUrl.searchParams.set("bqpass", "1");
|
|
32
|
+
return (0, node_fetch_1.default)(`https://${this.app}.app.baqend.com/v1/asset/${assetUrl.toString()}`, {
|
|
33
|
+
agent: this.agent,
|
|
34
|
+
headers: {
|
|
35
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
36
|
+
Origin: assetUrl.origin,
|
|
37
|
+
authorization: `BAT ${this.authenticationToken}`,
|
|
38
|
+
},
|
|
39
|
+
method: "HEAD",
|
|
40
|
+
timeout: __1.FETCH_TIMEOUT,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
getRateLimit() {
|
|
44
|
+
return this.rateLimit;
|
|
45
|
+
}
|
|
46
|
+
reduceMaxRequestsPerSecond() {
|
|
47
|
+
this.setRateLimit(this.rateLimit * __1.RATE_LIMIT_MULTIPLICATOR);
|
|
48
|
+
}
|
|
49
|
+
isValidUrl(url) {
|
|
50
|
+
if (!node_url_1.URL.canParse(url)) {
|
|
51
|
+
throw new invalid_origin_error_1.InvalidOriginError(`Invalid url`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
setRateLimit(limit) {
|
|
55
|
+
this.rateLimit = limit > 1 ? Math.floor(limit) : 1;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.AssetApiClient = AssetApiClient;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AssetItemInterface, ItemStatus } from "../";
|
|
2
|
+
import { AssetApiClient } from "./asset-api-client";
|
|
3
|
+
export declare class AssetItem implements AssetItemInterface {
|
|
4
|
+
readonly url: string;
|
|
5
|
+
readonly variation: string;
|
|
6
|
+
readonly callback: (client: AssetApiClient, entry: AssetItemInterface) => Promise<void>;
|
|
7
|
+
error?: Error;
|
|
8
|
+
status: ItemStatus;
|
|
9
|
+
constructor(url: string, variation: string, callback: (client: AssetApiClient, entry: AssetItemInterface) => Promise<void>);
|
|
10
|
+
done(): void;
|
|
11
|
+
failed(): void;
|
|
12
|
+
retry(): void;
|
|
13
|
+
setError(error: Error): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssetItem = void 0;
|
|
4
|
+
const __1 = require("../");
|
|
5
|
+
class AssetItem {
|
|
6
|
+
url;
|
|
7
|
+
variation;
|
|
8
|
+
callback;
|
|
9
|
+
error = null;
|
|
10
|
+
status = __1.ItemStatus.NEW;
|
|
11
|
+
constructor(url, variation, callback) {
|
|
12
|
+
this.url = url;
|
|
13
|
+
this.variation = variation;
|
|
14
|
+
this.callback = callback;
|
|
15
|
+
}
|
|
16
|
+
done() {
|
|
17
|
+
this.status = __1.ItemStatus.DONE;
|
|
18
|
+
}
|
|
19
|
+
failed() {
|
|
20
|
+
this.status = __1.ItemStatus.ERROR;
|
|
21
|
+
}
|
|
22
|
+
retry() {
|
|
23
|
+
this.status = __1.ItemStatus.RETRY;
|
|
24
|
+
}
|
|
25
|
+
setError(error) {
|
|
26
|
+
this.error = error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.AssetItem = AssetItem;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AssetItemInterface, ItemStatus } from "../";
|
|
2
|
+
export declare class AssetList {
|
|
3
|
+
private variations;
|
|
4
|
+
private elements;
|
|
5
|
+
constructor(variations: string[]);
|
|
6
|
+
addItem(item: AssetItemInterface): void;
|
|
7
|
+
getBatch(offset: number, limit: number): AssetItemInterface[];
|
|
8
|
+
getByStatus(status: ItemStatus): AssetItemInterface[];
|
|
9
|
+
getErrorCount(): number;
|
|
10
|
+
getErrors(): Error[];
|
|
11
|
+
getLength(): number;
|
|
12
|
+
getRetryCount(): number;
|
|
13
|
+
getSuccessCount(): number;
|
|
14
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssetList = void 0;
|
|
4
|
+
const __1 = require("../");
|
|
5
|
+
class AssetList {
|
|
6
|
+
variations;
|
|
7
|
+
elements = [];
|
|
8
|
+
constructor(variations) {
|
|
9
|
+
this.variations = variations;
|
|
10
|
+
}
|
|
11
|
+
addItem(item) {
|
|
12
|
+
this.elements.push(item);
|
|
13
|
+
}
|
|
14
|
+
getBatch(offset, limit) {
|
|
15
|
+
let batchLimit = offset + limit;
|
|
16
|
+
if (offset >= this.elements.length) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
if (batchLimit >= this.elements.length) {
|
|
20
|
+
batchLimit = this.elements.length;
|
|
21
|
+
}
|
|
22
|
+
return this.elements.slice(offset, batchLimit);
|
|
23
|
+
}
|
|
24
|
+
getByStatus(status) {
|
|
25
|
+
return this.elements.filter((element) => element.status === status);
|
|
26
|
+
}
|
|
27
|
+
getErrorCount() {
|
|
28
|
+
return this.getByStatus(__1.ItemStatus.ERROR).length;
|
|
29
|
+
}
|
|
30
|
+
getErrors() {
|
|
31
|
+
return this.getByStatus(__1.ItemStatus.ERROR).map((element) => element.error);
|
|
32
|
+
}
|
|
33
|
+
getLength() {
|
|
34
|
+
return this.elements.length;
|
|
35
|
+
}
|
|
36
|
+
getRetryCount() {
|
|
37
|
+
return this.getByStatus(__1.ItemStatus.RETRY).length;
|
|
38
|
+
}
|
|
39
|
+
getSuccessCount() {
|
|
40
|
+
return this.getByStatus(__1.ItemStatus.DONE).length;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.AssetList = AssetList;
|