@speedkit/cli 2.6.0 → 2.8.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 +1 -1
- package/dist/services/onboarding/fetch-events/speed-kit-asset-request.d.ts +4 -2
- package/dist/services/onboarding/fetch-events/speed-kit-asset-request.js +16 -2
- package/dist/services/onboarding/onboarding-model.d.ts +38 -0
- package/dist/services/onboarding/onboarding-service-factory.js +3 -1
- package/dist/services/onboarding/server-config/index.d.ts +10 -0
- package/dist/services/onboarding/server-config/index.js +32 -0
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Protocol from "devtools-protocol";
|
|
2
|
-
import { FetchRequestPausedEventHandler } from "../onboarding-model";
|
|
2
|
+
import { FetchRequestPausedEventHandler, SpeedKitServerConfig } from "../onboarding-model";
|
|
3
3
|
import CustomerConfig from "../../integration-api/struct/customer-config";
|
|
4
4
|
import { DocumentHandlerServer } from "../../document-handler-runtime/document-handler-server";
|
|
5
5
|
import { AbortResponse } from "../browser/abort-response";
|
|
@@ -13,8 +13,9 @@ export declare class SpeedKitAssetRequest implements FetchRequestPausedEventHand
|
|
|
13
13
|
private documentHandler;
|
|
14
14
|
private cache;
|
|
15
15
|
private cli;
|
|
16
|
+
private speedKitServerConfig?;
|
|
16
17
|
get patterns(): Protocol.Fetch.RequestPattern[];
|
|
17
|
-
constructor(customerConfig: CustomerConfig, documentHandler: DocumentHandlerServer, cache: Cache, cli: CliService);
|
|
18
|
+
constructor(customerConfig: CustomerConfig, documentHandler: DocumentHandlerServer, cache: Cache, cli: CliService, speedKitServerConfig?: SpeedKitServerConfig);
|
|
18
19
|
handle(event: Protocol.Fetch.RequestPausedEvent): Promise<Partial<Protocol.Fetch.FulfillRequestRequest> | AbortResponse>;
|
|
19
20
|
private getCachedResponse;
|
|
20
21
|
private buildCustomHeaders;
|
|
@@ -23,4 +24,5 @@ export declare class SpeedKitAssetRequest implements FetchRequestPausedEventHand
|
|
|
23
24
|
private isHtmlContentHeader;
|
|
24
25
|
private isValidHtmlContent;
|
|
25
26
|
private rewriteInstallResource;
|
|
27
|
+
private prepareOriginRequest;
|
|
26
28
|
}
|
|
@@ -10,6 +10,7 @@ class SpeedKitAssetRequest {
|
|
|
10
10
|
documentHandler;
|
|
11
11
|
cache;
|
|
12
12
|
cli;
|
|
13
|
+
speedKitServerConfig;
|
|
13
14
|
get patterns() {
|
|
14
15
|
let result = [];
|
|
15
16
|
for (const origin of this.customerConfig.origins) {
|
|
@@ -29,11 +30,12 @@ class SpeedKitAssetRequest {
|
|
|
29
30
|
}
|
|
30
31
|
return result;
|
|
31
32
|
}
|
|
32
|
-
constructor(customerConfig, documentHandler, cache, cli) {
|
|
33
|
+
constructor(customerConfig, documentHandler, cache, cli, speedKitServerConfig) {
|
|
33
34
|
this.customerConfig = customerConfig;
|
|
34
35
|
this.documentHandler = documentHandler;
|
|
35
36
|
this.cache = cache;
|
|
36
37
|
this.cli = cli;
|
|
38
|
+
this.speedKitServerConfig = speedKitServerConfig;
|
|
37
39
|
}
|
|
38
40
|
async handle(event) {
|
|
39
41
|
const originUrl = this.getAssetUrl(event.request.url);
|
|
@@ -43,7 +45,7 @@ class SpeedKitAssetRequest {
|
|
|
43
45
|
if (cachedResponse instanceof baqend_response_1.BaqendResponse) {
|
|
44
46
|
return cachedResponse;
|
|
45
47
|
}
|
|
46
|
-
const response = await fetch(originUrl, { headers: (event.request.headers) });
|
|
48
|
+
const response = await fetch(originUrl, this.prepareOriginRequest(variation, { headers: (event.request.headers) }));
|
|
47
49
|
const customHeaders = this.buildCustomHeaders(originUrl);
|
|
48
50
|
if (response.headers.get('Content-Type').includes('image') || response.headers.get('Content-Type').includes('font')) {
|
|
49
51
|
return;
|
|
@@ -134,5 +136,17 @@ class SpeedKitAssetRequest {
|
|
|
134
136
|
return `${head}\n<script src="${this.customerConfig.installPath}" ${this.customerConfig.installParams}></script>`;
|
|
135
137
|
});
|
|
136
138
|
}
|
|
139
|
+
prepareOriginRequest(variationParam, init) {
|
|
140
|
+
if (!this.speedKitServerConfig || !variationParam) {
|
|
141
|
+
return init;
|
|
142
|
+
}
|
|
143
|
+
const variation = variationParam.toUpperCase();
|
|
144
|
+
if (!(variation in this.speedKitServerConfig.speedKit.variations)) {
|
|
145
|
+
return init;
|
|
146
|
+
}
|
|
147
|
+
const variationConfig = this.speedKitServerConfig.speedKit.variations[variation];
|
|
148
|
+
init.headers = { ...init.headers, ...variationConfig.headers };
|
|
149
|
+
return init;
|
|
150
|
+
}
|
|
137
151
|
}
|
|
138
152
|
exports.SpeedKitAssetRequest = SpeedKitAssetRequest;
|
|
@@ -29,3 +29,41 @@ export type awsCredentials = {
|
|
|
29
29
|
accessKeyId: string;
|
|
30
30
|
secretAccessKey: string;
|
|
31
31
|
};
|
|
32
|
+
export type SpeedKitServerConfigAuthentication = {
|
|
33
|
+
"user": string;
|
|
34
|
+
"password": string;
|
|
35
|
+
"uri": string;
|
|
36
|
+
"type": "basic";
|
|
37
|
+
};
|
|
38
|
+
export type SpeedKitServerConfigVariation = {
|
|
39
|
+
[key: string]: {
|
|
40
|
+
"headers"?: {
|
|
41
|
+
"cookie"?: string;
|
|
42
|
+
};
|
|
43
|
+
"urlPrefix"?: string;
|
|
44
|
+
"encodePrefixedUrl"?: boolean;
|
|
45
|
+
"queryParams"?: [];
|
|
46
|
+
"regex"?: null | string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export type SpeedKitServerConfig = {
|
|
50
|
+
"speedKit": {
|
|
51
|
+
"httpAuthUser": null | string;
|
|
52
|
+
"httpAuthPass": null | string;
|
|
53
|
+
"httpAuthURI": null | string;
|
|
54
|
+
"httpAuthType": "basic";
|
|
55
|
+
"defaultAssetRequestsPerSecond": number;
|
|
56
|
+
"globalMinAssetRequestsPerSecond": number;
|
|
57
|
+
"globalMaxAssetRequestsPerSecond": number;
|
|
58
|
+
"assetRequestRateScaleUpStep": number;
|
|
59
|
+
"assetRequestRateScaleDownFactor": number;
|
|
60
|
+
"assetRequestRateLimitUpperTTFBLimit": number;
|
|
61
|
+
"assetRequestRateLimitLowerTTFBLimit": number;
|
|
62
|
+
"maxRevalidationWindowSize": number;
|
|
63
|
+
"minMaxAge": number;
|
|
64
|
+
"assetStreamingRateLimitTimeoutMs": 2000;
|
|
65
|
+
"streamRateLimit": number;
|
|
66
|
+
"authentications": SpeedKitServerConfigAuthentication[];
|
|
67
|
+
"variations": SpeedKitServerConfigVariation;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
@@ -39,6 +39,7 @@ const virtual_file_1 = require("../integration-api/struct/virtual-file");
|
|
|
39
39
|
const install_file_recipe_1 = require("./config-renderer/install-file-recipe");
|
|
40
40
|
const files_1 = require("../../models/files");
|
|
41
41
|
const speed_kit_rum_pi_request_1 = require("./fetch-events/speed-kit-rum-pi-request");
|
|
42
|
+
const server_config_1 = require("./server-config");
|
|
42
43
|
class OnboardingServiceFactory {
|
|
43
44
|
context;
|
|
44
45
|
cliConfig;
|
|
@@ -104,7 +105,8 @@ class OnboardingServiceFactory {
|
|
|
104
105
|
new speed_kit_service_worker_js_1.SpeedKitServiceWorkerJs(customerConfig, files.getByName(files_1.INTEGRATION_FILES.CUSTOM.SW)),
|
|
105
106
|
];
|
|
106
107
|
if (this.context.local) {
|
|
107
|
-
|
|
108
|
+
const speedKitConfigLoader = new server_config_1.ServerConfig(cli, configApi);
|
|
109
|
+
handlers.push(new speed_kit_asset_request_1.SpeedKitAssetRequest(customerConfig, documentHandler, cache, cli, await speedKitConfigLoader.getServerSpeedKitConfig()));
|
|
108
110
|
handlers.push(new speed_kit_rum_pi_request_1.SpeedKitRumPiRequest(customerConfig, cache, cli));
|
|
109
111
|
}
|
|
110
112
|
const athenaClient = await this.getAthenaClient(cli);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CliService } from "../../cli";
|
|
2
|
+
import ConfigApiService from "../../config-api/config-api-service";
|
|
3
|
+
import { SpeedKitServerConfig } from "../onboarding-model";
|
|
4
|
+
export declare class ServerConfig {
|
|
5
|
+
private cli;
|
|
6
|
+
private client?;
|
|
7
|
+
constructor(cli: CliService, client?: ConfigApiService);
|
|
8
|
+
getServerSpeedKitConfig(): Promise<SpeedKitServerConfig | null>;
|
|
9
|
+
private getServerConfig;
|
|
10
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerConfig = void 0;
|
|
4
|
+
const cli_1 = require("../../cli");
|
|
5
|
+
const safe_1 = require("../../../helpers/safe");
|
|
6
|
+
class ServerConfig {
|
|
7
|
+
cli;
|
|
8
|
+
client;
|
|
9
|
+
constructor(cli, client) {
|
|
10
|
+
this.cli = cli;
|
|
11
|
+
this.client = client;
|
|
12
|
+
}
|
|
13
|
+
async getServerSpeedKitConfig() {
|
|
14
|
+
const serverConfig = await this.getServerConfig();
|
|
15
|
+
if (!serverConfig) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
return JSON.parse(serverConfig);
|
|
19
|
+
}
|
|
20
|
+
async getServerConfig() {
|
|
21
|
+
this.cli.startAction('wait for credentials from server-config');
|
|
22
|
+
const serverConfigResponse = await (0, safe_1.safe)(this.client.getServerConfig());
|
|
23
|
+
if (serverConfigResponse.success === false) {
|
|
24
|
+
this.cli.endAction(cli_1.CliActionStatus.FAILED);
|
|
25
|
+
this.cli.writeError(`unable to load serverConfig: ${serverConfigResponse.error}`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.cli.endAction(cli_1.CliActionStatus.COMPLETED);
|
|
29
|
+
return serverConfigResponse.data;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.ServerConfig = ServerConfig;
|
package/oclif.manifest.json
CHANGED
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
|
+
"version": "2.8.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Baqend.com",
|
|
7
7
|
"email": "info@baqend.com"
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
|
-
"
|
|
17
|
+
"prepare": "husky install",
|
|
18
18
|
"lint": "eslint --ext .ts,.vue --ignore-path .gitignore src",
|
|
19
19
|
"lint-fix": "eslint --fix --ext .ts,.vue --ignore-path .gitignore src",
|
|
20
20
|
"prebuild": "shx rm -rf dist",
|
|
21
21
|
"build": "tsc -b && copyfiles -u 1 src/**/*hbs ./dist && copyfiles -u 1 src/**/*js ./dist && npm run build-dashboard",
|
|
22
22
|
"build-dashboard": "copyfiles -u 1 src/services/onboarding/dashboard/frontend-dist/**/*.html dist && copyfiles -u 1 src/services/onboarding/dashboard/frontend-dist/**/*.js dist && copyfiles -u 1 src/services/onboarding/dashboard/frontend-dist/**/*.css dist",
|
|
23
23
|
"postbuild": "oclif manifest && oclif readme",
|
|
24
|
-
"prepack": "npm run build
|
|
24
|
+
"prepack": "npm run build",
|
|
25
25
|
"postpack": "rimraf rm -f oclif.manifest.json",
|
|
26
26
|
"test": "mocha \"test/**/*.test.ts\"",
|
|
27
27
|
"coverage": "nyc --extension .ts mocha \"test/**/*.test.ts\""
|