@sap-ux/adp-tooling 0.18.109 → 0.18.110

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.
@@ -1,5 +1,6 @@
1
1
  import type { Editor } from 'mem-fs-editor';
2
2
  import type { ReaderCollection } from '@ui5/fs';
3
+ import type { ToolsLogger } from '@sap-ux/logger';
3
4
  import type { UI5Config } from '@sap-ux/ui5-config';
4
5
  import { type Inbound, AdaptationProjectType } from '@sap-ux/axios-extension';
5
6
  import { type ManifestNamespace, type Manifest } from '@sap-ux/project-access';
@@ -60,6 +61,14 @@ export declare function extractAdpConfig(ui5Conf: UI5Config): AdpPreviewConfig |
60
61
  * @returns {UI5YamlCustomTaskConfiguration} The CF build task.
61
62
  */
62
63
  export declare function extractCfBuildTask(ui5Conf: UI5Config): UI5YamlCustomTaskConfiguration;
64
+ /**
65
+ * Read space GUID from ui5.yaml customTasks app-variant-bundler-build.space.
66
+ *
67
+ * @param {string} rootPath - Project root (where ui5.yaml lives).
68
+ * @param {ToolsLogger} logger - Optional logger.
69
+ * @returns {Promise<string | undefined>} Space GUID or undefined if not found.
70
+ */
71
+ export declare function getSpaceGuidFromUi5Yaml(rootPath: string, logger?: ToolsLogger): Promise<string | undefined>;
63
72
  /**
64
73
  * Read the manifest from the build output folder.
65
74
  *
@@ -7,6 +7,7 @@ exports.isTypescriptSupported = isTypescriptSupported;
7
7
  exports.readUi5Config = readUi5Config;
8
8
  exports.extractAdpConfig = extractAdpConfig;
9
9
  exports.extractCfBuildTask = extractCfBuildTask;
10
+ exports.getSpaceGuidFromUi5Yaml = getSpaceGuidFromUi5Yaml;
10
11
  exports.readManifestFromBuildPath = readManifestFromBuildPath;
11
12
  exports.loadAppVariant = loadAppVariant;
12
13
  exports.getAdpConfig = getAdpConfig;
@@ -101,6 +102,24 @@ function extractCfBuildTask(ui5Conf) {
101
102
  }
102
103
  return buildTask;
103
104
  }
105
+ /**
106
+ * Read space GUID from ui5.yaml customTasks app-variant-bundler-build.space.
107
+ *
108
+ * @param {string} rootPath - Project root (where ui5.yaml lives).
109
+ * @param {ToolsLogger} logger - Optional logger.
110
+ * @returns {Promise<string | undefined>} Space GUID or undefined if not found.
111
+ */
112
+ async function getSpaceGuidFromUi5Yaml(rootPath, logger) {
113
+ try {
114
+ const ui5Config = await readUi5Config(rootPath, 'ui5.yaml');
115
+ const buildTask = extractCfBuildTask(ui5Config);
116
+ return buildTask?.space;
117
+ }
118
+ catch {
119
+ logger?.warn('Could not read space from ui5.yaml (app-variant-bundler-build).');
120
+ return undefined;
121
+ }
122
+ }
104
123
  /**
105
124
  * Read the manifest from the build output folder.
106
125
  *
@@ -1,4 +1,4 @@
1
+ export * from './mta';
1
2
  export * from './yaml';
2
3
  export * from './yaml-loader';
3
- export * from './mta';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./mta"), exports);
17
18
  __exportStar(require("./yaml"), exports);
18
19
  __exportStar(require("./yaml-loader"), exports);
19
- __exportStar(require("./mta"), exports);
20
20
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,14 @@
1
1
  import type { ToolsLogger } from '@sap-ux/logger';
2
- import type { BusinessServiceResource, AppRouterType } from '../../types';
2
+ import type { BusinessServiceResource, AppRouterType, MtaYaml } from '../../types';
3
+ /**
4
+ * Builds VCAP_SERVICES by resolving MTA resources to service key credentials.
5
+ *
6
+ * @param {MtaYaml['resources']} resources - MTA YAML resources.
7
+ * @param {string} spaceGuid - The space GUID.
8
+ * @param {ToolsLogger} logger - Optional logger.
9
+ * @returns {Promise<Record<string, unknown>>} VCAP_SERVICES keyed by service name.
10
+ */
11
+ export declare function buildVcapServicesFromResources(resources: MtaYaml['resources'], spaceGuid: string, logger?: ToolsLogger): Promise<Record<string, unknown>>;
3
12
  /**
4
13
  * Get the approuter type.
5
14
  *
@@ -33,6 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.buildVcapServicesFromResources = buildVcapServicesFromResources;
36
37
  exports.getApprouterType = getApprouterType;
37
38
  exports.getModuleNames = getModuleNames;
38
39
  exports.getServicesForFile = getServicesForFile;
@@ -42,9 +43,36 @@ exports.getResources = getResources;
42
43
  exports.readMta = readMta;
43
44
  const path = __importStar(require("node:path"));
44
45
  const i18n_1 = require("../../i18n");
46
+ const api_1 = require("../services/api");
47
+ const cli_1 = require("../services/cli");
45
48
  const yaml_1 = require("./yaml");
46
49
  const yaml_loader_1 = require("./yaml-loader");
47
- const cli_1 = require("../services/cli");
50
+ const EXCLUDED_SERVICES_VCAP = new Set(['html5-apps-repo', 'portal']);
51
+ /**
52
+ * Builds VCAP_SERVICES by resolving MTA resources to service key credentials.
53
+ *
54
+ * @param {MtaYaml['resources']} resources - MTA YAML resources.
55
+ * @param {string} spaceGuid - The space GUID.
56
+ * @param {ToolsLogger} logger - Optional logger.
57
+ * @returns {Promise<Record<string, unknown>>} VCAP_SERVICES keyed by service name.
58
+ */
59
+ async function buildVcapServicesFromResources(resources, spaceGuid, logger) {
60
+ const vcapServices = {};
61
+ for (const resource of resources ?? []) {
62
+ const serviceName = resource.parameters?.service;
63
+ const serviceInstanceName = resource.parameters?.['service-name'];
64
+ const servicePlan = resource.parameters?.['service-plan'];
65
+ if (!serviceName || !serviceInstanceName || EXCLUDED_SERVICES_VCAP.has(serviceName)) {
66
+ continue;
67
+ }
68
+ const data = await (0, api_1.getServiceKeyCredentialsWithTags)(spaceGuid, serviceName, serviceInstanceName, servicePlan ?? '', logger);
69
+ if (!data?.credentials) {
70
+ throw new Error(`Credentials and tags for service '${serviceName}' ('${serviceInstanceName}') not found`);
71
+ }
72
+ vcapServices[serviceName] = [data];
73
+ }
74
+ return vcapServices;
75
+ }
48
76
  /**
49
77
  * Get the approuter type.
50
78
  *
@@ -1,6 +1,6 @@
1
1
  import type { ToolsLogger } from '@sap-ux/logger';
2
2
  import type { ManifestNamespace } from '@sap-ux/project-access';
3
- import type { CfConfig, CFApp, RequestArguments, ServiceKeys, GetServiceInstanceParams, ServiceInstance, MtaYaml, ServiceInfo, CfUi5AppInfo } from '../../types';
3
+ import type { CfConfig, CFApp, RequestArguments, ServiceKeys, GetServiceInstanceParams, ServiceInstance, MtaYaml, ServiceInfo, CfUi5AppInfo, ServiceKeyCredentialsWithTags } from '../../types';
4
4
  interface CreateServiceOptions {
5
5
  xsSecurityProjectName?: string;
6
6
  templatePathOverwrite?: string;
@@ -98,5 +98,24 @@ export declare function getOrCreateServiceInstanceKeys(serviceInstanceQuery: Get
98
98
  * @returns {Promise<ServiceKeys[]>} The service instance keys.
99
99
  */
100
100
  export declare function getOrCreateServiceKeys(serviceInstance: ServiceInstance, logger?: ToolsLogger): Promise<ServiceKeys[]>;
101
+ /**
102
+ * Gets service tags for a given service name.
103
+ *
104
+ * @param {string} spaceGuid - The space GUID.
105
+ * @param {string} serviceName - The service name (e.g., 'xsuaa', 'hana').
106
+ * @returns {Promise<string[]>} The service tags.
107
+ */
108
+ export declare function getServiceTags(spaceGuid: string, serviceName: string): Promise<string[]>;
109
+ /**
110
+ * Fetches service tags and credentials for a single app-router resource (xsuaa/destination).
111
+ *
112
+ * @param {string} spaceGuid - The space GUID.
113
+ * @param {string} serviceName - The service name (e.g. 'xsuaa', 'destination').
114
+ * @param {string} serviceInstanceName - The service instance name.
115
+ * @param {string} plan - The service plan.
116
+ * @param {ToolsLogger} logger - Optional logger.
117
+ * @returns {Promise<ServiceKeyCredentialsWithTags | null>} Service key credentials with tags returned by the CF API.
118
+ */
119
+ export declare function getServiceKeyCredentialsWithTags(spaceGuid: string, serviceName: string, serviceInstanceName: string, plan: string, logger?: ToolsLogger): Promise<ServiceKeyCredentialsWithTags | null>;
101
120
  export {};
102
121
  //# sourceMappingURL=api.d.ts.map
@@ -46,6 +46,8 @@ exports.getServiceNameByTags = getServiceNameByTags;
46
46
  exports.createServices = createServices;
47
47
  exports.getOrCreateServiceInstanceKeys = getOrCreateServiceInstanceKeys;
48
48
  exports.getOrCreateServiceKeys = getOrCreateServiceKeys;
49
+ exports.getServiceTags = getServiceTags;
50
+ exports.getServiceKeyCredentialsWithTags = getServiceKeyCredentialsWithTags;
49
51
  const fs = __importStar(require("node:fs"));
50
52
  const axios_1 = __importDefault(require("axios"));
51
53
  const path = __importStar(require("node:path"));
@@ -374,4 +376,51 @@ async function getOrCreateServiceKeys(serviceInstance, logger) {
374
376
  throw new Error((0, i18n_1.t)('error.failedToGetOrCreateServiceKeys', { serviceInstanceName, error: e.message }));
375
377
  }
376
378
  }
379
+ /**
380
+ * Gets service tags for a given service name.
381
+ *
382
+ * @param {string} spaceGuid - The space GUID.
383
+ * @param {string} serviceName - The service name (e.g., 'xsuaa', 'hana').
384
+ * @returns {Promise<string[]>} The service tags.
385
+ */
386
+ async function getServiceTags(spaceGuid, serviceName) {
387
+ const json = await (0, cli_1.requestCfApi)(`/v3/service_offerings?per_page=1000&space_guids=${spaceGuid}&names=${serviceName}`);
388
+ const serviceOffering = json?.resources?.find((resource) => resource.name === serviceName);
389
+ return serviceOffering?.tags ?? [];
390
+ }
391
+ /**
392
+ * Fetches service tags and credentials for a single app-router resource (xsuaa/destination).
393
+ *
394
+ * @param {string} spaceGuid - The space GUID.
395
+ * @param {string} serviceName - The service name (e.g. 'xsuaa', 'destination').
396
+ * @param {string} serviceInstanceName - The service instance name.
397
+ * @param {string} plan - The service plan.
398
+ * @param {ToolsLogger} logger - Optional logger.
399
+ * @returns {Promise<ServiceKeyCredentialsWithTags | null>} Service key credentials with tags returned by the CF API.
400
+ */
401
+ async function getServiceKeyCredentialsWithTags(spaceGuid, serviceName, serviceInstanceName, plan, logger) {
402
+ try {
403
+ const tags = await getServiceTags(spaceGuid, serviceName);
404
+ const serviceInstances = await getServiceInstance({
405
+ names: [serviceInstanceName],
406
+ spaceGuids: [spaceGuid]
407
+ });
408
+ if (serviceInstances.length === 0) {
409
+ logger?.error(`Service instance '${serviceInstanceName}' not found, skipping`);
410
+ return null;
411
+ }
412
+ const credentials = await getOrCreateServiceKeys(serviceInstances[0], logger);
413
+ return {
414
+ label: serviceName,
415
+ name: serviceInstanceName,
416
+ tags,
417
+ plan,
418
+ credentials: credentials?.[0].credentials
419
+ };
420
+ }
421
+ catch (e) {
422
+ logger?.error(`Failed to get credentials and tags for service '${serviceName}' (instance: '${serviceInstanceName}'): ${e.message}`);
423
+ return null;
424
+ }
425
+ }
377
426
  //# sourceMappingURL=api.js.map
@@ -23,6 +23,13 @@ export declare function getServiceKeys(serviceInstanceGuid: string, sortBy?: Ser
23
23
  * @param {string} serviceKeyName - The service key name.
24
24
  */
25
25
  export declare function createServiceKey(serviceInstanceName: string, serviceKeyName: string): Promise<void>;
26
+ /**
27
+ * Updates a Cloud Foundry service instance with the given parameters.
28
+ *
29
+ * @param {string} serviceInstanceName - The service instance name.
30
+ * @param {object} parameters - The configuration parameters to update.
31
+ */
32
+ export declare function updateServiceInstance(serviceInstanceName: string, parameters: object): Promise<void>;
26
33
  /**
27
34
  * Request CF API.
28
35
  *
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isCfInstalled = isCfInstalled;
4
4
  exports.getServiceKeys = getServiceKeys;
5
5
  exports.createServiceKey = createServiceKey;
6
+ exports.updateServiceInstance = updateServiceInstance;
6
7
  exports.requestCfApi = requestCfApi;
7
8
  const cf_tools_1 = require("@sap/cf-tools");
8
9
  const i18n_1 = require("../../i18n");
@@ -96,6 +97,23 @@ async function createServiceKey(serviceInstanceName, serviceKeyName) {
96
97
  throw new Error((0, i18n_1.t)('error.createServiceKeyFailed', { serviceInstanceName, error: e.message }));
97
98
  }
98
99
  }
100
+ /**
101
+ * Updates a Cloud Foundry service instance with the given parameters.
102
+ *
103
+ * @param {string} serviceInstanceName - The service instance name.
104
+ * @param {object} parameters - The configuration parameters to update.
105
+ */
106
+ async function updateServiceInstance(serviceInstanceName, parameters) {
107
+ try {
108
+ const cliResult = await cf_tools_1.Cli.execute(['update-service', serviceInstanceName, '-c', JSON.stringify(parameters), '--wait'], ENV);
109
+ if (cliResult.exitCode !== 0) {
110
+ throw new Error(cliResult.stderr);
111
+ }
112
+ }
113
+ catch (e) {
114
+ throw new Error((0, i18n_1.t)('error.failedToUpdateServiceInstance', { serviceInstanceName, error: e.message }));
115
+ }
116
+ }
99
117
  /**
100
118
  * Request CF API.
101
119
  *
@@ -103,6 +103,7 @@
103
103
  "emptyCFAPIResponse": "Empty response from CF API. Please verify your CF login status with 'cf target' and re-authenticate if needed with 'cf login'.",
104
104
  "xsSecurityJsonCouldNotBeParsed": "The xs-security.json file could not be parsed. Ensure the xs-security.json file exists and try again.",
105
105
  "failedToCreateServiceInstance": "Failed to create the service instance: '{{serviceInstanceName}}'. Error: {{error}}",
106
+ "failedToUpdateServiceInstance": "Failed to update the service instance: '{{serviceInstanceName}}'. Error: {{error}}",
106
107
  "failedToGetFDCApps": "Retrieving FDC apps failed: {{error}}",
107
108
  "failedToGetFDCInbounds": "Retrieving inbounds from the UI5 Flexibility Design and Configuration service failed: {{error}}",
108
109
  "failedToConnectToFDCService": "Failed to connect to the FDC service: '{{status}}'",
package/dist/types.d.ts CHANGED
@@ -824,6 +824,23 @@ export interface ServiceInstance {
824
824
  name: string;
825
825
  guid: string;
826
826
  }
827
+ /**
828
+ * Service key credentials with tags returned by the CF API.
829
+ */
830
+ export interface ServiceKeyCredentialsWithTags {
831
+ label: string;
832
+ name: string;
833
+ tags: string[];
834
+ plan: string;
835
+ credentials: ServiceKeys['credentials'] | undefined;
836
+ }
837
+ export interface AppRouterEnvOptions {
838
+ 'VCAP_SERVICES'?: Record<string, unknown>;
839
+ destinations?: {
840
+ name: string;
841
+ url: string;
842
+ }[];
843
+ }
827
844
  export interface GetServiceInstanceParams {
828
845
  spaceGuids?: string[];
829
846
  planNames?: string[];
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aadp-tooling"
11
11
  },
12
- "version": "0.18.109",
12
+ "version": "0.18.110",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",