@ui5/task-adaptation 1.2.0 → 1.3.1
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 +9 -1
- package/eslint.config.js +52 -0
- package/package.json +42 -52
- package/scripts/metadataDownloadHelper.ts +8 -7
- package/scripts/rollup/bundle.d.ts +25 -0
- package/scripts/rollup/bundleDefinition.js +11 -1
- package/scripts/{bundler.ts → rollup/bundler.ts} +6 -17
- package/scripts/rollup/overrides/sap/base/config.js +10 -0
- package/scripts/rollup/project/package.json +2 -1
- package/scripts/rollup/project/ui5.yaml +1 -1
- package/scripts/rollup/ui5Resolve.ts +14 -38
- package/scripts/rollup.ts +67 -23
- package/types/ui5.d.ts +44 -0
- package/dist/annotationManager.d.ts +0 -18
- package/dist/annotationManager.js +0 -80
- package/dist/annotations/comparator/comparator.d.ts +0 -47
- package/dist/annotations/comparator/comparator.js +0 -279
- package/dist/annotations/comparator/diffCase.d.ts +0 -4
- package/dist/annotations/comparator/diffCase.js +0 -3
- package/dist/annotations/comparator/interchangableCase.d.ts +0 -25
- package/dist/annotations/comparator/interchangableCase.js +0 -65
- package/dist/annotations/converter/metadataJsonReferenceUtil.d.ts +0 -12
- package/dist/annotations/converter/metadataJsonReferenceUtil.js +0 -50
- package/dist/annotations/converter/metadataJsonUtil.d.ts +0 -30
- package/dist/annotations/converter/metadataJsonUtil.js +0 -73
- package/dist/annotations/converter/ui5JsonConverter.d.ts +0 -21
- package/dist/annotations/converter/ui5JsonConverter.js +0 -253
- package/dist/annotations/converter/ui5MetadataJsonUtil.d.ts +0 -3
- package/dist/annotations/converter/ui5MetadataJsonUtil.js +0 -13
- package/dist/annotations/converter/ui5XmlConverter.d.ts +0 -5
- package/dist/annotations/converter/ui5XmlConverter.js +0 -17
- package/dist/annotations/dataSource/dataSource.d.ts +0 -34
- package/dist/annotations/dataSource/dataSource.js +0 -62
- package/dist/annotations/dataSource/dataSourceManager.d.ts +0 -12
- package/dist/annotations/dataSource/dataSourceManager.js +0 -50
- package/dist/annotations/dataSource/dataSourceOData.d.ts +0 -17
- package/dist/annotations/dataSource/dataSourceOData.js +0 -47
- package/dist/annotations/dataSource/dataSourceODataAnnotation.d.ts +0 -6
- package/dist/annotations/dataSource/dataSourceODataAnnotation.js +0 -18
- package/dist/annotations/serviceRequestor.d.ts +0 -9
- package/dist/annotations/serviceRequestor.js +0 -71
- package/dist/annotations/transformers/convertV2ToV4.d.ts +0 -4
- package/dist/annotations/transformers/convertV2ToV4.js +0 -16
- package/dist/annotations/transformers/makeAnnotationNamespaceUnique.d.ts +0 -6
- package/dist/annotations/transformers/makeAnnotationNamespaceUnique.js +0 -44
- package/dist/annotations/transformers/removeAllSchemaNodesExceptAnnotations.d.ts +0 -4
- package/dist/annotations/transformers/removeAllSchemaNodesExceptAnnotations.js +0 -17
- package/dist/annotations/transformers/transformer.d.ts +0 -12
- package/dist/annotations/transformers/transformer.js +0 -3
- package/dist/annotations/transformers/traverseReferences.d.ts +0 -9
- package/dist/annotations/transformers/traverseReferences.js +0 -67
- package/dist/appVariantManager.d.ts +0 -12
- package/dist/appVariantManager.js +0 -105
- package/dist/baseAppManager.d.ts +0 -29
- package/dist/baseAppManager.js +0 -141
- package/dist/buildStrategy.d.ts +0 -7
- package/dist/buildStrategy.js +0 -21
- package/dist/bundle-odata.js +0 -5498
- package/dist/bundle.js +0 -3475
- package/dist/cache/annotationsCacheManager.d.ts +0 -8
- package/dist/cache/annotationsCacheManager.js +0 -18
- package/dist/cache/baseAppFilesCacheManager.d.ts +0 -6
- package/dist/cache/baseAppFilesCacheManager.js +0 -15
- package/dist/cache/cacheManager.d.ts +0 -16
- package/dist/cache/cacheManager.js +0 -68
- package/dist/i18nManager.d.ts +0 -43
- package/dist/i18nManager.js +0 -203
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -27
- package/dist/model/annotationDiffStructureError.d.ts +0 -3
- package/dist/model/annotationDiffStructureError.js +0 -11
- package/dist/model/language.d.ts +0 -13
- package/dist/model/language.js +0 -37
- package/dist/model/noAuthorizationProvidedError.d.ts +0 -3
- package/dist/model/noAuthorizationProvidedError.js +0 -9
- package/dist/model/serverError.d.ts +0 -3
- package/dist/model/serverError.js +0 -9
- package/dist/model/types.d.ts +0 -119
- package/dist/model/types.js +0 -3
- package/dist/processors/abapProcessor.d.ts +0 -21
- package/dist/processors/abapProcessor.js +0 -36
- package/dist/processors/cfProcessor.d.ts +0 -17
- package/dist/processors/cfProcessor.js +0 -46
- package/dist/processors/processor.d.ts +0 -7
- package/dist/processors/processor.js +0 -36
- package/dist/repositories/abapRepoManager.d.ts +0 -13
- package/dist/repositories/abapRepoManager.js +0 -82
- package/dist/repositories/html5RepoManager.d.ts +0 -11
- package/dist/repositories/html5RepoManager.js +0 -89
- package/dist/util/cfUtil.d.ts +0 -30
- package/dist/util/cfUtil.js +0 -173
- package/dist/util/commonUtil.d.ts +0 -13
- package/dist/util/commonUtil.js +0 -129
- package/dist/util/i18nMerger.d.ts +0 -28
- package/dist/util/i18nMerger.js +0 -103
- package/dist/util/requestUtil.d.ts +0 -8
- package/dist/util/requestUtil.js +0 -57
- package/dist/util/resourceUtil.d.ts +0 -11
- package/dist/util/resourceUtil.js +0 -65
- package/dist/util/urlUtil.d.ts +0 -4
- package/dist/util/urlUtil.js +0 -21
- package/dist/util/xmlUtil.d.ts +0 -4
- package/dist/util/xmlUtil.js +0 -24
- package/dist/util/zipUtil.d.ts +0 -2
- package/dist/util/zipUtil.js +0 -20
- package/scripts/rollup/bundleDefinition-odata.js +0 -9
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const commonUtil_1 = require("../util/commonUtil");
|
|
4
|
-
const language_1 = require("../model/language");
|
|
5
|
-
class AbapProcessor {
|
|
6
|
-
constructor(configuration, cacheManager, abapRepoManager, annotationManager) {
|
|
7
|
-
this.configuration = configuration;
|
|
8
|
-
this.abapRepoManager = abapRepoManager;
|
|
9
|
-
this.cacheManager = cacheManager;
|
|
10
|
-
this.annotationManager = annotationManager;
|
|
11
|
-
}
|
|
12
|
-
getBaseAppFiles(baseAppId) {
|
|
13
|
-
return this.cacheManager.getFiles(() => this.abapRepoManager.getMetadata(baseAppId), () => this.abapRepoManager.downloadBaseAppFiles());
|
|
14
|
-
}
|
|
15
|
-
validateConfiguration() {
|
|
16
|
-
(0, commonUtil_1.validateObject)(this.configuration, ["destination", "appName"], "should be specified in ui5.yaml configuration");
|
|
17
|
-
}
|
|
18
|
-
async updateLandscapeSpecificContent(renamedBaseAppManifest, baseAppFiles) {
|
|
19
|
-
const files = await this.annotationManager.process(renamedBaseAppManifest, (language_1.default.create(this.configuration.languages)));
|
|
20
|
-
if (baseAppFiles) {
|
|
21
|
-
files.forEach((value, key) => baseAppFiles.set(key, value));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
getConfigurationType() {
|
|
25
|
-
return "abap";
|
|
26
|
-
}
|
|
27
|
-
createAppVariantHierarchyItem(appVariantId, version) {
|
|
28
|
-
return {
|
|
29
|
-
appVariantId,
|
|
30
|
-
version,
|
|
31
|
-
layer: "VENDOR"
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.default = AbapProcessor;
|
|
36
|
-
//# sourceMappingURL=abapProcessor.js.map
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import BaseAppFilesCacheManager from "../cache/baseAppFilesCacheManager";
|
|
2
|
-
import { IConfiguration } from "../model/types";
|
|
3
|
-
import IProcessor from "./processor";
|
|
4
|
-
export default class CFProcessor implements IProcessor {
|
|
5
|
-
private configuration;
|
|
6
|
-
private cacheManager;
|
|
7
|
-
constructor(configuration: IConfiguration, cacheManager: BaseAppFilesCacheManager);
|
|
8
|
-
getBaseAppFiles(): Promise<Map<string, string>>;
|
|
9
|
-
validateConfiguration(): void;
|
|
10
|
-
updateLandscapeSpecificContent(renamedBaseAppManifest: any): Promise<void>;
|
|
11
|
-
private updateCloudPlatform;
|
|
12
|
-
getConfigurationType(): string;
|
|
13
|
-
createAppVariantHierarchyItem(appVariantId: string, version: string): {
|
|
14
|
-
appVariantId: string;
|
|
15
|
-
version: string;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const html5RepoManager_1 = require("../repositories/html5RepoManager");
|
|
4
|
-
const commonUtil_1 = require("../util/commonUtil");
|
|
5
|
-
class CFProcessor {
|
|
6
|
-
constructor(configuration, cacheManager) {
|
|
7
|
-
this.configuration = configuration;
|
|
8
|
-
this.cacheManager = cacheManager;
|
|
9
|
-
}
|
|
10
|
-
async getBaseAppFiles() {
|
|
11
|
-
return this.cacheManager.getFiles(() => html5RepoManager_1.default.getMetadata(this.configuration), () => html5RepoManager_1.default.getBaseAppFiles(this.configuration));
|
|
12
|
-
}
|
|
13
|
-
validateConfiguration() {
|
|
14
|
-
(0, commonUtil_1.validateObject)(this.configuration, ["appHostId", "appName", "appVersion"], "should be specified in ui5.yaml configuration");
|
|
15
|
-
}
|
|
16
|
-
async updateLandscapeSpecificContent(renamedBaseAppManifest) {
|
|
17
|
-
this.updateCloudPlatform(renamedBaseAppManifest);
|
|
18
|
-
}
|
|
19
|
-
updateCloudPlatform(renamedBaseAppManifest) {
|
|
20
|
-
const sapCloudService = renamedBaseAppManifest["sap.cloud"]?.service;
|
|
21
|
-
const sapPlatformCf = renamedBaseAppManifest["sap.platform.cf"];
|
|
22
|
-
if (sapPlatformCf && sapCloudService) {
|
|
23
|
-
sapPlatformCf.oAuthScopes = sapPlatformCf.oAuthScopes.map((scope) => scope.replace(`$XSAPPNAME.`, `$XSAPPNAME('${sapCloudService}').`));
|
|
24
|
-
}
|
|
25
|
-
if (this.configuration.sapCloudService) {
|
|
26
|
-
if (renamedBaseAppManifest["sap.cloud"] == null) {
|
|
27
|
-
renamedBaseAppManifest["sap.cloud"] = {};
|
|
28
|
-
}
|
|
29
|
-
renamedBaseAppManifest["sap.cloud"].service = this.configuration.sapCloudService;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
delete renamedBaseAppManifest["sap.cloud"];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
getConfigurationType() {
|
|
36
|
-
return "cf";
|
|
37
|
-
}
|
|
38
|
-
createAppVariantHierarchyItem(appVariantId, version) {
|
|
39
|
-
return {
|
|
40
|
-
appVariantId,
|
|
41
|
-
version
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.default = CFProcessor;
|
|
46
|
-
//# sourceMappingURL=cfProcessor.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { IConfiguration } from "../model/types";
|
|
2
|
-
export default interface IProcessor {
|
|
3
|
-
createAppVariantHierarchyItem(appVariantId: string, version: string): void;
|
|
4
|
-
getBaseAppFiles(baseAppId: string): Promise<Map<string, string>>;
|
|
5
|
-
updateLandscapeSpecificContent(renamedBaseAppManifest: any, baseAppFiles?: Map<string, string>): Promise<void>;
|
|
6
|
-
}
|
|
7
|
-
export declare function determineProcessor(configuration: IConfiguration): IProcessor;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.determineProcessor = void 0;
|
|
4
|
-
const abapProcessor_1 = require("./abapProcessor");
|
|
5
|
-
const abapRepoManager_1 = require("../repositories/abapRepoManager");
|
|
6
|
-
const annotationManager_1 = require("../annotationManager");
|
|
7
|
-
const baseAppFilesCacheManager_1 = require("../cache/baseAppFilesCacheManager");
|
|
8
|
-
const cfProcessor_1 = require("./cfProcessor");
|
|
9
|
-
function determineProcessor(configuration) {
|
|
10
|
-
const cacheManager = new baseAppFilesCacheManager_1.default(configuration);
|
|
11
|
-
const abapRepoManager = new abapRepoManager_1.default(configuration);
|
|
12
|
-
const annotationManager = new annotationManager_1.default(configuration, abapRepoManager);
|
|
13
|
-
const processors = [
|
|
14
|
-
new cfProcessor_1.default(configuration, cacheManager),
|
|
15
|
-
new abapProcessor_1.default(configuration, cacheManager, abapRepoManager, annotationManager)
|
|
16
|
-
];
|
|
17
|
-
let processor = processors.find(processor => processor.getConfigurationType() === configuration.type);
|
|
18
|
-
if (processor) {
|
|
19
|
-
processor.validateConfiguration();
|
|
20
|
-
return processor;
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
for (const processor of processors) {
|
|
24
|
-
try {
|
|
25
|
-
processor.validateConfiguration();
|
|
26
|
-
return processor;
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
throw new Error("ui5.yaml configuration should correspond either ABAP or SAP BTP landscape");
|
|
34
|
-
}
|
|
35
|
-
exports.determineProcessor = determineProcessor;
|
|
36
|
-
//# sourceMappingURL=processor.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { IConfiguration, IMetadata } from "../model/types";
|
|
2
|
-
export default class AbapRepoManager {
|
|
3
|
-
private auth?;
|
|
4
|
-
private configuration;
|
|
5
|
-
constructor(configuration: IConfiguration);
|
|
6
|
-
getAnnotationMetadata(uri: string): Promise<IMetadata>;
|
|
7
|
-
downloadAnnotationFile(uri: string): Promise<Map<string, string>>;
|
|
8
|
-
getMetadata(baseAppId: string): Promise<IMetadata>;
|
|
9
|
-
downloadBaseAppFiles(): Promise<Map<string, string>>;
|
|
10
|
-
private getMetadataRequest;
|
|
11
|
-
private downloadBaseAppFilesRequest;
|
|
12
|
-
private getAuth;
|
|
13
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const requestUtil_1 = require("../util/requestUtil");
|
|
4
|
-
const zipUtil_1 = require("../util/zipUtil");
|
|
5
|
-
const log = require("@ui5/logger").getLogger("@ui5/task-adaptation::AbapRepoManager");
|
|
6
|
-
const REQUEST_OPTIONS_XML = {
|
|
7
|
-
responseType: "text",
|
|
8
|
-
headers: {
|
|
9
|
-
"Accept": "text/html,application/xhtml+xml,application/xml"
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
const REQUEST_OPTIONS_JSON = {
|
|
13
|
-
headers: {
|
|
14
|
-
"Accept": "application/json"
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
class AbapRepoManager {
|
|
18
|
-
constructor(configuration) {
|
|
19
|
-
this.configuration = configuration;
|
|
20
|
-
}
|
|
21
|
-
async getAnnotationMetadata(uri) {
|
|
22
|
-
const header = await requestUtil_1.default.retryWithAuth(() => requestUtil_1.default.head(uri), () => requestUtil_1.default.head(uri, this.getAuth()));
|
|
23
|
-
return { changedOn: header.modified };
|
|
24
|
-
}
|
|
25
|
-
async downloadAnnotationFile(uri) {
|
|
26
|
-
const annotationUri = `https://${this.configuration.destination}.dest${uri}`;
|
|
27
|
-
const annotation = await requestUtil_1.default.retryWithAuth(() => requestUtil_1.default.get(annotationUri, REQUEST_OPTIONS_XML), () => requestUtil_1.default.get(annotationUri, REQUEST_OPTIONS_XML, this.getAuth()));
|
|
28
|
-
return new Map([["annotation.xml", annotation]]);
|
|
29
|
-
}
|
|
30
|
-
getMetadata(baseAppId) {
|
|
31
|
-
return requestUtil_1.default.retryWithAuth(() => this.getMetadataRequest(baseAppId), () => this.getMetadataRequest(baseAppId, this.getAuth()));
|
|
32
|
-
}
|
|
33
|
-
downloadBaseAppFiles() {
|
|
34
|
-
return requestUtil_1.default.retryWithAuth(() => this.downloadBaseAppFilesRequest(), () => this.downloadBaseAppFilesRequest(this.getAuth()));
|
|
35
|
-
}
|
|
36
|
-
async getMetadataRequest(id, auth) {
|
|
37
|
-
let uri = `https://${this.configuration.destination}.dest/sap/bc/ui2/app_index/ui5_app_info_json?id=${id}`;
|
|
38
|
-
const data = await requestUtil_1.default.get(uri, REQUEST_OPTIONS_JSON, auth);
|
|
39
|
-
if (data && data[id]) {
|
|
40
|
-
return {
|
|
41
|
-
changedOn: data[id].url,
|
|
42
|
-
id
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
log.warn(`UI5AppInfoJson request doesn't contain cache buster token for sap.app/id '${id}'. Fallback to download.`);
|
|
46
|
-
}
|
|
47
|
-
async downloadBaseAppFilesRequest(auth) {
|
|
48
|
-
const { destination, appName } = this.configuration;
|
|
49
|
-
const encodedAppName = encodeURIComponent(appName);
|
|
50
|
-
const uri = `https://${destination}.dest/sap/opu/odata/UI5/ABAP_REPOSITORY_SRV/Repositories('${encodedAppName}')?DownloadFiles=RUNTIME&CodePage=UTF8`;
|
|
51
|
-
const data = await requestUtil_1.default.get(uri, {}, auth);
|
|
52
|
-
if (data?.d?.ZipArchive.length > 0) {
|
|
53
|
-
const buffer = Buffer.from(data.d.ZipArchive, "base64");
|
|
54
|
-
return (0, zipUtil_1.unzipZipEntries)(buffer);
|
|
55
|
-
}
|
|
56
|
-
throw new Error(`App '${appName}' from destination '${destination}' doesn't contain files`);
|
|
57
|
-
}
|
|
58
|
-
getAuth() {
|
|
59
|
-
if (!this.auth) {
|
|
60
|
-
if (this.configuration?.credentials) {
|
|
61
|
-
let { username, password } = this.configuration?.credentials;
|
|
62
|
-
if (username && password) {
|
|
63
|
-
const ENV_PREFIX = "env:";
|
|
64
|
-
username = username.substring(ENV_PREFIX.length);
|
|
65
|
-
password = password.substring(ENV_PREFIX.length);
|
|
66
|
-
if (process.env[username] && process.env[password]) {
|
|
67
|
-
this.auth = {
|
|
68
|
-
username: process.env[username],
|
|
69
|
-
password: process.env[password]
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (!this.auth) {
|
|
76
|
-
throw new Error("Please provide ABAP System credentials in .env file of the project: https://help.sap.com/docs/SAP_FIORI_tools/17d50220bcd848aa854c9c182d65b699/1c859274b511435ab6bd45f70e7f9af2.html.");
|
|
77
|
-
}
|
|
78
|
-
return this.auth;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.default = AbapRepoManager;
|
|
82
|
-
//# sourceMappingURL=abapRepoManager.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { IConfiguration } from "./../model/types";
|
|
2
|
-
export default class HTML5RepoManager {
|
|
3
|
-
static getBaseAppFiles(configuration: IConfiguration): Promise<Map<string, string>>;
|
|
4
|
-
static getMetadata(configuration: IConfiguration): Promise<any>;
|
|
5
|
-
private static getHtml5RepoInfo;
|
|
6
|
-
private static getHTML5Credentials;
|
|
7
|
-
private static getToken;
|
|
8
|
-
private static requestMetadata;
|
|
9
|
-
private static getBaseAppZipEntries;
|
|
10
|
-
private static download;
|
|
11
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const cfUtil_1 = require("./../util/cfUtil");
|
|
4
|
-
const requestUtil_1 = require("./../util/requestUtil");
|
|
5
|
-
const zipUtil_1 = require("./../util/zipUtil");
|
|
6
|
-
const log = require("@ui5/logger").getLogger("@ui5/task-adaptation::HTML5RepoManager");
|
|
7
|
-
class HTML5RepoManager {
|
|
8
|
-
static async getBaseAppFiles(configuration) {
|
|
9
|
-
const { token, baseUri } = await this.getHtml5RepoInfo(configuration);
|
|
10
|
-
return this.getBaseAppZipEntries(configuration, baseUri, token);
|
|
11
|
-
}
|
|
12
|
-
static async getMetadata(configuration) {
|
|
13
|
-
const { token, baseUri } = await this.getHtml5RepoInfo(configuration);
|
|
14
|
-
return this.requestMetadata(configuration, baseUri, token);
|
|
15
|
-
}
|
|
16
|
-
static async getHtml5RepoInfo(configuration) {
|
|
17
|
-
const spaceGuid = await cfUtil_1.default.getSpaceGuid(configuration?.spaceGuid);
|
|
18
|
-
const credentials = await this.getHTML5Credentials(spaceGuid);
|
|
19
|
-
const token = await this.getToken(credentials);
|
|
20
|
-
return {
|
|
21
|
-
token,
|
|
22
|
-
baseUri: credentials.uri
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
static async getHTML5Credentials(spaceGuid) {
|
|
26
|
-
log.verbose("Getting HTML5 Repo Runtime credentials from space " + spaceGuid);
|
|
27
|
-
const PLAN_NAME = "app-runtime";
|
|
28
|
-
const SERVIСE_INSTANCE_NAME = "html5-apps-repo-runtime";
|
|
29
|
-
const getParams = {
|
|
30
|
-
spaceGuids: [spaceGuid],
|
|
31
|
-
planNames: [PLAN_NAME],
|
|
32
|
-
names: [SERVIСE_INSTANCE_NAME]
|
|
33
|
-
};
|
|
34
|
-
const createParams = {
|
|
35
|
-
spaceGuid,
|
|
36
|
-
planName: PLAN_NAME,
|
|
37
|
-
serviceName: SERVIСE_INSTANCE_NAME,
|
|
38
|
-
tags: ["html5-apps-repo-rt"]
|
|
39
|
-
};
|
|
40
|
-
const serviceKeys = await cfUtil_1.default.getServiceInstanceKeys(getParams, createParams);
|
|
41
|
-
return serviceKeys.credentials;
|
|
42
|
-
}
|
|
43
|
-
static async getToken({ uaa }) {
|
|
44
|
-
log.verbose("Getting HTML5 Repo token");
|
|
45
|
-
const auth = Buffer.from(uaa.clientid + ":" + uaa.clientsecret);
|
|
46
|
-
const options = {
|
|
47
|
-
headers: {
|
|
48
|
-
"Content-Type": "application/json",
|
|
49
|
-
"Authorization": "Basic " + auth.toString("base64")
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const uri = `${uaa.url}/oauth/token?grant_type=client_credentials`;
|
|
53
|
-
return requestUtil_1.default.get(uri, options).then((json) => json["access_token"]);
|
|
54
|
-
}
|
|
55
|
-
static async requestMetadata(options, html5RepoBaseUri, token) {
|
|
56
|
-
const { appHostId, appName, appVersion } = options;
|
|
57
|
-
const uri = `${html5RepoBaseUri}/applications/metadata/`;
|
|
58
|
-
const requestOptions = {
|
|
59
|
-
headers: {
|
|
60
|
-
"Content-Type": "application/json",
|
|
61
|
-
"Authorization": "Bearer " + token,
|
|
62
|
-
"x-app-host-id": appHostId
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
const metadata = await requestUtil_1.default.get(uri, requestOptions);
|
|
66
|
-
return metadata.find((item) => item.appHostId === appHostId && item.applicationName === appName && item.applicationVersion === appVersion);
|
|
67
|
-
}
|
|
68
|
-
static async getBaseAppZipEntries(options, html5RepoBaseUri, token) {
|
|
69
|
-
const { appHostId, appName, appVersion } = options;
|
|
70
|
-
const uri = `${html5RepoBaseUri}/applications/content/${appName}-${appVersion}/`;
|
|
71
|
-
const zip = await this.download(token, appHostId, uri);
|
|
72
|
-
return (0, zipUtil_1.unzipZipEntries)(zip);
|
|
73
|
-
}
|
|
74
|
-
static async download(token, appHostId, uri) {
|
|
75
|
-
if (!token) {
|
|
76
|
-
throw new Error("HTML5 token is undefined");
|
|
77
|
-
}
|
|
78
|
-
return requestUtil_1.default.get(uri, {
|
|
79
|
-
responseType: "arraybuffer",
|
|
80
|
-
headers: {
|
|
81
|
-
"Content-Type": "application/json",
|
|
82
|
-
"Authorization": "Bearer " + token,
|
|
83
|
-
"x-app-host-id": appHostId
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.default = HTML5RepoManager;
|
|
89
|
-
//# sourceMappingURL=html5RepoManager.js.map
|
package/dist/util/cfUtil.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ICreateServiceInstanceParams, IGetServiceInstanceParams, IResource, IServiceKeys } from "../model/types";
|
|
2
|
-
export default class CFUtil {
|
|
3
|
-
/**
|
|
4
|
-
* Get or create service keys for service instance found by query
|
|
5
|
-
* @static
|
|
6
|
-
* @param {IGetServiceInstanceParams} getServiceInstanceParams query parameters to find a service instance by
|
|
7
|
-
* @param {ICreateServiceInstanceParams} [createServiceInstanceParams] parameters to create a service instance
|
|
8
|
-
* @return {Promise<IServiceKeys>} promise with service keys
|
|
9
|
-
* @memberof CFUtil
|
|
10
|
-
*/
|
|
11
|
-
static getServiceInstanceKeys(getServiceInstanceParams: IGetServiceInstanceParams, createServiceInstanceParams?: ICreateServiceInstanceParams): Promise<IServiceKeys>;
|
|
12
|
-
static createService(params: ICreateServiceInstanceParams): Promise<void>;
|
|
13
|
-
private static getOrCreateServiceKeys;
|
|
14
|
-
private static getServiceKeys;
|
|
15
|
-
private static createServiceKey;
|
|
16
|
-
private static getServiceInstance;
|
|
17
|
-
static requestCfApi(url: string): Promise<IResource[]>;
|
|
18
|
-
static getOAuthToken(): Promise<string>;
|
|
19
|
-
private static cfExecute;
|
|
20
|
-
private static errorsToString;
|
|
21
|
-
private static parseJson;
|
|
22
|
-
/**
|
|
23
|
-
* Get space guid from configuration or local CF fodler
|
|
24
|
-
* @static
|
|
25
|
-
* @param {string} spaceGuid ui5.yaml options
|
|
26
|
-
* @return {Promise<string>} promise with space guid
|
|
27
|
-
* @memberof CFUtil
|
|
28
|
-
*/
|
|
29
|
-
static getSpaceGuid(spaceGuid?: string): Promise<string>;
|
|
30
|
-
}
|
package/dist/util/cfUtil.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const CFLocal = require("@sap/cf-tools/out/src/cf-local");
|
|
4
|
-
const CFToolsCli = require("@sap/cf-tools/out/src/cli");
|
|
5
|
-
const types_1 = require("@sap/cf-tools/out/src/types");
|
|
6
|
-
const log = require("@ui5/logger").getLogger("@ui5/task-adaptation::CFUtil");
|
|
7
|
-
class CFUtil {
|
|
8
|
-
/**
|
|
9
|
-
* Get or create service keys for service instance found by query
|
|
10
|
-
* @static
|
|
11
|
-
* @param {IGetServiceInstanceParams} getServiceInstanceParams query parameters to find a service instance by
|
|
12
|
-
* @param {ICreateServiceInstanceParams} [createServiceInstanceParams] parameters to create a service instance
|
|
13
|
-
* @return {Promise<IServiceKeys>} promise with service keys
|
|
14
|
-
* @memberof CFUtil
|
|
15
|
-
*/
|
|
16
|
-
static async getServiceInstanceKeys(getServiceInstanceParams, createServiceInstanceParams) {
|
|
17
|
-
let serviceInstances = await this.getServiceInstance(getServiceInstanceParams);
|
|
18
|
-
if (!(serviceInstances?.length > 0) && createServiceInstanceParams) {
|
|
19
|
-
await this.createService(createServiceInstanceParams);
|
|
20
|
-
serviceInstances = await this.getServiceInstance(getServiceInstanceParams);
|
|
21
|
-
}
|
|
22
|
-
if (!(serviceInstances?.length > 0)) {
|
|
23
|
-
throw new Error(`Cannot find '${getServiceInstanceParams.names?.join(", ")}' service in current space: ${getServiceInstanceParams.spaceGuids?.join(", ")}`);
|
|
24
|
-
}
|
|
25
|
-
// we can use any instance in the list to connect to HTML5 Repo
|
|
26
|
-
log.verbose(`Use '${serviceInstances[0].name}' HTML5 Repo Runtime service instance`);
|
|
27
|
-
const serviceKeys = await this.getOrCreateServiceKeys(serviceInstances[0]);
|
|
28
|
-
if (!(serviceKeys?.length > 0)) {
|
|
29
|
-
throw new Error(`Cannot get service keys for '${getServiceInstanceParams.names?.join(", ")}' service in current space: ${getServiceInstanceParams.spaceGuids?.join(", ")}`);
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
credentials: serviceKeys[0].credentials,
|
|
33
|
-
serviceInstance: serviceInstances[0]
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
static async createService(params) {
|
|
37
|
-
log.verbose(`Creating a service instance with parameters: ${JSON.stringify(params)}`);
|
|
38
|
-
const resources = await this.requestCfApi(`/v3/service_plans?names=${params.planName}&space_guids=${params.spaceGuid}`);
|
|
39
|
-
const publicPlan = resources.find(resource => resource.visibility_type === "public");
|
|
40
|
-
if (!publicPlan) {
|
|
41
|
-
throw new Error(`Cannot find a public plan by name '${params.serviceName}' in space '${params.spaceGuid}'`);
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
await CFLocal.cfCreateService(publicPlan.guid, params.serviceName, params.parameters, params.tags);
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
throw new Error(`Cannot create a service instance '${params.serviceName}' in space '${params.spaceGuid}': ${error.message}`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
static async getOrCreateServiceKeys(serviceInstance) {
|
|
51
|
-
const credentials = await this.getServiceKeys(serviceInstance.guid);
|
|
52
|
-
if (credentials.length === 0) {
|
|
53
|
-
const serviceKeyName = serviceInstance.name + "_key";
|
|
54
|
-
log.info(`Creating service key '${serviceKeyName}' for service instance '${serviceInstance.name}'`);
|
|
55
|
-
await this.createServiceKey(serviceInstance.name, serviceKeyName);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
return credentials;
|
|
59
|
-
}
|
|
60
|
-
return this.getServiceKeys(serviceInstance.guid);
|
|
61
|
-
}
|
|
62
|
-
static getServiceKeys(serviceInstanceGuid) {
|
|
63
|
-
return CFLocal.cfGetInstanceCredentials({
|
|
64
|
-
filters: [{
|
|
65
|
-
value: serviceInstanceGuid,
|
|
66
|
-
key: types_1.eFilters.service_instance_guids
|
|
67
|
-
}]
|
|
68
|
-
}).catch((error) => {
|
|
69
|
-
throw new Error("Failed to get service credentials: " + error.message);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
static async createServiceKey(serviceInstanceName, serviceKeyName) {
|
|
73
|
-
try {
|
|
74
|
-
return this.cfExecute(["create-service-key", serviceInstanceName, serviceKeyName]);
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
throw new Error(`Couldn't create a service key for instance: ${serviceInstanceName}`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
static async getServiceInstance(params) {
|
|
81
|
-
const PARAM_MAP = {
|
|
82
|
-
spaceGuids: "space_guids",
|
|
83
|
-
planNames: "service_plan_names",
|
|
84
|
-
names: "names"
|
|
85
|
-
};
|
|
86
|
-
const parameters = Object.entries(params)
|
|
87
|
-
.filter(([_, value]) => value?.length && value?.length > 0)
|
|
88
|
-
.map(([key, value]) => `${PARAM_MAP[key]}=${value?.join(",")}`);
|
|
89
|
-
const uri = `/v3/service_instances` + (parameters.length > 0 ? `?${parameters.join("&")}` : "");
|
|
90
|
-
const resources = await this.requestCfApi(uri);
|
|
91
|
-
return resources.map((service) => ({
|
|
92
|
-
name: service.name,
|
|
93
|
-
guid: service.guid
|
|
94
|
-
}));
|
|
95
|
-
}
|
|
96
|
-
static async requestCfApi(url) {
|
|
97
|
-
const response = await this.cfExecute(["curl", url]);
|
|
98
|
-
const json = this.parseJson(response);
|
|
99
|
-
const resources = json?.resources;
|
|
100
|
-
const totalPages = json?.pagination?.total_pages;
|
|
101
|
-
if (totalPages > 1) {
|
|
102
|
-
const pages = Array.from({ length: totalPages - 1 }, (_, i) => i + 2);
|
|
103
|
-
return resources.concat(await Promise.all(pages.map(async (page) => {
|
|
104
|
-
const uri = `${url}${url.includes("?") ? "&" : "?"}page=${page}`;
|
|
105
|
-
const response = await this.cfExecute(["curl", uri]);
|
|
106
|
-
return this.parseJson(response)?.resources || [];
|
|
107
|
-
})).then(resources => [].concat(...resources)));
|
|
108
|
-
}
|
|
109
|
-
return resources;
|
|
110
|
-
}
|
|
111
|
-
static getOAuthToken() {
|
|
112
|
-
return this.cfExecute(["oauth-token"]);
|
|
113
|
-
}
|
|
114
|
-
static async cfExecute(params) {
|
|
115
|
-
const MAX_ATTEMPTS = 3;
|
|
116
|
-
const errors = new Set();
|
|
117
|
-
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
|
|
118
|
-
try {
|
|
119
|
-
const response = await CFToolsCli.Cli.execute(params, { env: { "CF_COLOR": "false" } });
|
|
120
|
-
if (response.exitCode === 0) {
|
|
121
|
-
const errorValues = [...errors.values()];
|
|
122
|
-
if (errorValues?.length > 0) {
|
|
123
|
-
log.verbose(this.errorsToString(errorValues));
|
|
124
|
-
}
|
|
125
|
-
return response.stdout;
|
|
126
|
-
}
|
|
127
|
-
errors.add(response.error || response.stderr);
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
errors.add(error.message);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
throw new Error(`Failed to send request with parameters '${JSON.stringify(params)}': ${this.errorsToString([...errors.values()])}`);
|
|
134
|
-
}
|
|
135
|
-
static errorsToString(errors) {
|
|
136
|
-
return errors.length > 1
|
|
137
|
-
? errors.map((error, attempt) => `${attempt + 1} attempt: ${error}`).join("; ")
|
|
138
|
-
: errors.map(error => error);
|
|
139
|
-
}
|
|
140
|
-
static parseJson(jsonString) {
|
|
141
|
-
try {
|
|
142
|
-
return JSON.parse(jsonString);
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
throw new Error(`Failed parse response from request CF API: ${error.message}`);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Get space guid from configuration or local CF fodler
|
|
150
|
-
* @static
|
|
151
|
-
* @param {string} spaceGuid ui5.yaml options
|
|
152
|
-
* @return {Promise<string>} promise with space guid
|
|
153
|
-
* @memberof CFUtil
|
|
154
|
-
*/
|
|
155
|
-
static async getSpaceGuid(spaceGuid) {
|
|
156
|
-
if (spaceGuid == null) {
|
|
157
|
-
const spaceName = (await CFLocal.cfGetTarget())?.space;
|
|
158
|
-
if (spaceName) {
|
|
159
|
-
const resources = await this.requestCfApi(`/v3/spaces?names=${spaceName}`);
|
|
160
|
-
for (const resource of resources) {
|
|
161
|
-
spaceGuid = resource.guid;
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
if (spaceGuid == null) {
|
|
167
|
-
throw new Error("Please login to Cloud Foundry with 'cf login' and try again");
|
|
168
|
-
}
|
|
169
|
-
return spaceGuid;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
exports.default = CFUtil;
|
|
173
|
-
//# sourceMappingURL=cfUtil.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { IConfiguration } from "../model/types";
|
|
2
|
-
import Language from "../model/language";
|
|
3
|
-
export declare function dotToUnderscore(value: string): string;
|
|
4
|
-
export declare function validateObject<T extends Object>(options: T, properties: Array<keyof T>, message: string): void;
|
|
5
|
-
export declare function escapeRegex(update: string): string;
|
|
6
|
-
export declare function renameResources(files: Map<string, string>, search: string, replacement: string): Map<string, string>;
|
|
7
|
-
export declare function insertInArray<T>(array: T[], index: number, insert: T): void;
|
|
8
|
-
export declare function writeTempAnnotations({ writeTempFiles }: IConfiguration, name: string, language: Language, content: string): void;
|
|
9
|
-
export declare function removePropertiesExtension(filePath: string): string;
|
|
10
|
-
export declare function traverse(json: any, paths: string[], callback: (json: any, key: string | number, paths: string[]) => void): void;
|
|
11
|
-
export declare function logBuilderVersion(): Promise<void>;
|
|
12
|
-
export declare function logBetaUsage(): Promise<void>;
|
|
13
|
-
export declare function getUniqueName(existingNames: string[], template: string): string;
|