@sap-ux/telemetry 0.7.5 → 1.0.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.
Files changed (46) hide show
  1. package/dist/base/client/azure-appinsight-client.d.ts +3 -3
  2. package/dist/base/client/azure-appinsight-client.js +22 -58
  3. package/dist/base/client/client.d.ts +1 -1
  4. package/dist/base/client/client.js +1 -4
  5. package/dist/base/client/index.d.ts +2 -2
  6. package/dist/base/client/index.js +5 -8
  7. package/dist/base/config-state.js +4 -10
  8. package/dist/base/decorator/index.d.ts +2 -2
  9. package/dist/base/decorator/index.js +4 -9
  10. package/dist/base/interceptor/config.js +4 -41
  11. package/dist/base/interceptor/index.d.ts +3 -3
  12. package/dist/base/interceptor/index.js +25 -34
  13. package/dist/base/performance/api.d.ts +2 -2
  14. package/dist/base/performance/api.js +14 -16
  15. package/dist/base/performance/entries.d.ts +2 -2
  16. package/dist/base/performance/entries.js +3 -7
  17. package/dist/base/performance/types.d.ts +2 -1
  18. package/dist/base/performance/types.js +2 -5
  19. package/dist/base/types/event-header.js +1 -4
  20. package/dist/base/types/event-name.js +2 -5
  21. package/dist/base/types/event.js +1 -2
  22. package/dist/base/types/index.d.ts +5 -5
  23. package/dist/base/types/index.js +5 -21
  24. package/dist/base/types/project-info.js +1 -2
  25. package/dist/base/types/sample-rate.js +2 -5
  26. package/dist/base/utils/azure-client-config.js +1 -4
  27. package/dist/base/utils/date.js +1 -5
  28. package/dist/base/utils/index.d.ts +5 -5
  29. package/dist/base/utils/index.js +5 -23
  30. package/dist/base/utils/logger.js +2 -6
  31. package/dist/base/utils/param-processing.js +10 -19
  32. package/dist/base/utils/reporting.js +10 -48
  33. package/dist/index.d.ts +14 -12
  34. package/dist/index.js +12 -32
  35. package/dist/tooling-telemetry/config-state.js +1 -4
  36. package/dist/tooling-telemetry/data-processor.d.ts +1 -1
  37. package/dist/tooling-telemetry/data-processor.js +73 -81
  38. package/dist/tooling-telemetry/index.d.ts +4 -4
  39. package/dist/tooling-telemetry/index.js +4 -23
  40. package/dist/tooling-telemetry/telemetry-client.d.ts +3 -3
  41. package/dist/tooling-telemetry/telemetry-client.js +9 -12
  42. package/dist/tooling-telemetry/telemetry-settings.d.ts +1 -1
  43. package/dist/tooling-telemetry/telemetry-settings.js +34 -43
  44. package/dist/tooling-telemetry/types.d.ts +1 -1
  45. package/dist/tooling-telemetry/types.js +8 -11
  46. package/package.json +11 -9
@@ -1,28 +1,20 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.processToolsSuiteTelemetry = processToolsSuiteTelemetry;
7
- exports.getCommonProperties = getCommonProperties;
8
- exports.getIdeType = getIdeType;
9
- const btp_utils_1 = require("@sap-ux/btp-utils");
10
- const nodejs_utils_1 = require("@sap-ux/nodejs-utils");
11
- const ui5_config_1 = require("@sap-ux/ui5-config");
12
- const axios_1 = __importDefault(require("axios"));
13
- const node_fs_1 = __importDefault(require("node:fs"));
14
- const node_path_1 = __importDefault(require("node:path"));
15
- const yaml_1 = __importDefault(require("yaml"));
16
- const project_access_1 = require("@sap-ux/project-access");
17
- const config_state_1 = require("./config-state");
18
- const types_1 = require("./types");
1
+ import { isAppStudio } from '@sap-ux/btp-utils';
2
+ import { CommandRunner } from '@sap-ux/nodejs-utils';
3
+ import { UI5Config } from '@sap-ux/ui5-config';
4
+ import axios from 'axios';
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import yaml from 'yaml';
8
+ import { findProjectRoot, getAppProgrammingLanguage, getAppType, getProjectType, getWebappPath, isCapJavaProject } from '@sap-ux/project-access';
9
+ import { ToolingTelemetrySettings } from './config-state.js';
10
+ import { CommonProperties, DeployTarget, ODataSource, ToolsId } from './types.js';
19
11
  /**
20
12
  * Collect commone properties that needs to be added to telemetry event.
21
13
  *
22
14
  * @param telemetryHelperProperties Pass to report ApplicationInsightClient.report()
23
15
  * @returns Common Fiori project properties
24
16
  */
25
- async function processToolsSuiteTelemetry(telemetryHelperProperties) {
17
+ export async function processToolsSuiteTelemetry(telemetryHelperProperties) {
26
18
  const commonProperties = await getCommonProperties();
27
19
  let appProperties = {};
28
20
  if (telemetryHelperProperties) {
@@ -35,16 +27,16 @@ async function processToolsSuiteTelemetry(telemetryHelperProperties) {
35
27
  *
36
28
  * @returns Common properties
37
29
  */
38
- async function getCommonProperties() {
30
+ export async function getCommonProperties() {
39
31
  const commonProperties = {};
40
- commonProperties[types_1.CommonProperties.DevSpace] = await getSbasDevspace();
41
- commonProperties[types_1.CommonProperties.AppStudio] = (0, btp_utils_1.isAppStudio)();
42
- commonProperties[types_1.CommonProperties.AppStudioBackwardCompatible] = commonProperties[types_1.CommonProperties.AppStudio];
43
- commonProperties[types_1.CommonProperties.InternlVsExternal] = getInternalVsExternal();
44
- commonProperties[types_1.CommonProperties.InternlVsExternalBackwardCompatible] =
45
- commonProperties[types_1.CommonProperties.InternlVsExternal];
46
- commonProperties[types_1.CommonProperties.NodeVersion] = await getOSNodeVersion();
47
- commonProperties[types_1.CommonProperties.IdeType] = getIdeType();
32
+ commonProperties[CommonProperties.DevSpace] = await getSbasDevspace();
33
+ commonProperties[CommonProperties.AppStudio] = isAppStudio();
34
+ commonProperties[CommonProperties.AppStudioBackwardCompatible] = commonProperties[CommonProperties.AppStudio];
35
+ commonProperties[CommonProperties.InternlVsExternal] = getInternalVsExternal();
36
+ commonProperties[CommonProperties.InternlVsExternalBackwardCompatible] =
37
+ commonProperties[CommonProperties.InternlVsExternal];
38
+ commonProperties[CommonProperties.NodeVersion] = await getOSNodeVersion();
39
+ commonProperties[CommonProperties.IdeType] = getIdeType();
48
40
  return commonProperties;
49
41
  }
50
42
  /**
@@ -53,7 +45,7 @@ async function getCommonProperties() {
53
45
  * @returns SBAS Dev Space Name. Empty string is returned if unable to fetch workspace type or the environment is not SBAS
54
46
  */
55
47
  async function getSbasDevspace() {
56
- if ((0, btp_utils_1.isAppStudio)()) {
48
+ if (isAppStudio()) {
57
49
  try {
58
50
  if (!process.env.H2O_URL || !process.env.WORKSPACE_ID) {
59
51
  return '';
@@ -61,7 +53,7 @@ async function getSbasDevspace() {
61
53
  const h20Url = process.env.H2O_URL;
62
54
  const workspaceId = process.env.WORKSPACE_ID.replace('workspaces-', '');
63
55
  const url = `${h20Url}/ws-manager/api/v1/workspace/${workspaceId}`;
64
- const response = await axios_1.default.get(url);
56
+ const response = await axios.get(url);
65
57
  if (response.data) {
66
58
  const workspaceConfig = response.data;
67
59
  // devspace stored in this path
@@ -86,23 +78,23 @@ async function getAppProperties(appPath) {
86
78
  }
87
79
  const templateType = await getTemplateType(appPath);
88
80
  const deployTarget = await getDeployTarget(appPath);
89
- const applicationType = await (0, project_access_1.getAppType)(appPath);
81
+ const applicationType = await getAppType(appPath);
90
82
  let odataSource = await getODataSource(appPath);
91
83
  // Correct logic in getAppType() implementation, if it's reuse lib type, odata source should be unknown
92
84
  if (applicationType === 'Fiori Reuse') {
93
- odataSource = types_1.ODataSource.UNKNOWN;
85
+ odataSource = ODataSource.UNKNOWN;
94
86
  }
95
87
  const sourceTemplate = await getSourceTemplate(appPath);
96
- const appProgrammingLanguage = await (0, project_access_1.getAppProgrammingLanguage)(appPath);
88
+ const appProgrammingLanguage = await getAppProgrammingLanguage(appPath);
97
89
  const output = {};
98
- output[types_1.CommonProperties.TemplateType] = templateType;
99
- output[types_1.CommonProperties.DeployTargetType] = deployTarget;
100
- output[types_1.CommonProperties.ODataSourceType] = odataSource;
101
- output[types_1.CommonProperties.AppToolsId] = sourceTemplate.toolsId ?? '';
102
- output[types_1.CommonProperties.AppProgrammingLanguage] = appProgrammingLanguage;
103
- output[types_1.CommonProperties.TemplateId] = sourceTemplate.id ?? '';
104
- output[types_1.CommonProperties.TemplateVersion] = sourceTemplate.version ?? '';
105
- output[types_1.CommonProperties.ApplicationType] = applicationType ?? '';
90
+ output[CommonProperties.TemplateType] = templateType;
91
+ output[CommonProperties.DeployTargetType] = deployTarget;
92
+ output[CommonProperties.ODataSourceType] = odataSource;
93
+ output[CommonProperties.AppToolsId] = sourceTemplate.toolsId ?? '';
94
+ output[CommonProperties.AppProgrammingLanguage] = appProgrammingLanguage;
95
+ output[CommonProperties.TemplateId] = sourceTemplate.id ?? '';
96
+ output[CommonProperties.TemplateVersion] = sourceTemplate.version ?? '';
97
+ output[CommonProperties.ApplicationType] = applicationType ?? '';
106
98
  return output;
107
99
  }
108
100
  /**
@@ -112,18 +104,18 @@ async function getAppProperties(appPath) {
112
104
  * @returns Template type used in the Fiori app
113
105
  */
114
106
  async function getTemplateType(appPath) {
115
- const readmeFilePath = node_path_1.default.join(appPath, 'README.md');
116
- const appGenInfoPath = node_path_1.default.join(appPath, '.appGenInfo.json');
107
+ const readmeFilePath = path.join(appPath, 'README.md');
108
+ const appGenInfoPath = path.join(appPath, '.appGenInfo.json');
117
109
  // N.B.: Keep this order i.e .appGenInfo.json file is read first, then README.md.
118
- if (node_fs_1.default.existsSync(appGenInfoPath)) {
119
- const appGenInfo = await node_fs_1.default.promises.readFile(appGenInfoPath, 'utf-8');
110
+ if (fs.existsSync(appGenInfoPath)) {
111
+ const appGenInfo = await fs.promises.readFile(appGenInfoPath, 'utf-8');
120
112
  const appGenInfoParsed = JSON.parse(appGenInfo);
121
113
  if (appGenInfoParsed?.generationParameters?.template) {
122
114
  return appGenInfoParsed.generationParameters.template.trim();
123
115
  }
124
116
  }
125
- if (node_fs_1.default.existsSync(readmeFilePath)) {
126
- const readmeContent = await node_fs_1.default.promises.readFile(readmeFilePath, 'utf-8');
117
+ if (fs.existsSync(readmeFilePath)) {
118
+ const readmeContent = await fs.promises.readFile(readmeFilePath, 'utf-8');
127
119
  if (readmeContent) {
128
120
  let templateType = '';
129
121
  const lines = readmeContent.split(/\r?\n/);
@@ -155,7 +147,7 @@ async function getODataSource(appPath) {
155
147
  // is ABAP.
156
148
  let projectRoot;
157
149
  try {
158
- projectRoot = await (0, project_access_1.findProjectRoot)(appPath);
150
+ projectRoot = await findProjectRoot(appPath);
159
151
  }
160
152
  catch {
161
153
  // No project root can be found
@@ -165,8 +157,8 @@ async function getODataSource(appPath) {
165
157
  // use appPath as project root.
166
158
  if (!projectRoot) {
167
159
  try {
168
- const appParentFolder = node_path_1.default.dirname(appPath);
169
- projectRoot = await (0, project_access_1.findProjectRoot)(appParentFolder, false);
160
+ const appParentFolder = path.dirname(appPath);
161
+ projectRoot = await findProjectRoot(appParentFolder, false);
170
162
  }
171
163
  catch (e) {
172
164
  // No project root can be found at parent folder.
@@ -178,19 +170,19 @@ async function getODataSource(appPath) {
178
170
  // a better solution
179
171
  let isCapJavaWithoutPackageJson = false;
180
172
  if (!projectRoot) {
181
- const directParentFolder = node_path_1.default.dirname(appPath);
182
- const twoLevelUpParentFolder = node_path_1.default.dirname(directParentFolder);
183
- isCapJavaWithoutPackageJson = await (0, project_access_1.isCapJavaProject)(twoLevelUpParentFolder);
173
+ const directParentFolder = path.dirname(appPath);
174
+ const twoLevelUpParentFolder = path.dirname(directParentFolder);
175
+ isCapJavaWithoutPackageJson = await isCapJavaProject(twoLevelUpParentFolder);
184
176
  projectRoot = isCapJavaWithoutPackageJson ? twoLevelUpParentFolder : appPath;
185
177
  }
186
178
  if (isCapJavaWithoutPackageJson) {
187
- return types_1.ODataSource.CAPJava;
179
+ return ODataSource.CAPJava;
188
180
  }
189
- const projectType = await (0, project_access_1.getProjectType)(projectRoot);
181
+ const projectType = await getProjectType(projectRoot);
190
182
  return getProjectTypeForTelemetry(projectType);
191
183
  }
192
184
  catch (e) {
193
- return types_1.ODataSource.UNKNOWN;
185
+ return ODataSource.UNKNOWN;
194
186
  }
195
187
  }
196
188
  /**
@@ -201,16 +193,16 @@ async function getODataSource(appPath) {
201
193
  */
202
194
  function getProjectTypeForTelemetry(projectType) {
203
195
  if (projectType === 'EDMXBackend') {
204
- return types_1.ODataSource.ABAP;
196
+ return ODataSource.ABAP;
205
197
  }
206
198
  else if (projectType === 'CAPNodejs') {
207
- return types_1.ODataSource.CAPNode;
199
+ return ODataSource.CAPNode;
208
200
  }
209
201
  else if (projectType === 'CAPJava') {
210
- return types_1.ODataSource.CAPJava;
202
+ return ODataSource.CAPJava;
211
203
  }
212
204
  else {
213
- return types_1.ODataSource.UNKNOWN;
205
+ return ODataSource.UNKNOWN;
214
206
  }
215
207
  }
216
208
  /**
@@ -220,19 +212,19 @@ function getProjectTypeForTelemetry(projectType) {
220
212
  * @returns CF | ABAP | NO_DEPLOY_CONFIG | UNKNOWN_DEPLOY_CONFIG
221
213
  */
222
214
  async function getDeployTarget(appPath) {
223
- let deployTarget = types_1.DeployTarget.NO_DEPLOY_CONFIG;
224
- const deployConfigPath = node_path_1.default.join(appPath, 'ui5-deploy.yaml');
215
+ let deployTarget = DeployTarget.NO_DEPLOY_CONFIG;
216
+ const deployConfigPath = path.join(appPath, 'ui5-deploy.yaml');
225
217
  try {
226
- await node_fs_1.default.promises.access(deployConfigPath);
227
- const deployConfigContent = await node_fs_1.default.promises.readFile(deployConfigPath, 'utf-8');
228
- const deployConfig = yaml_1.default.parse(deployConfigContent);
218
+ await fs.promises.access(deployConfigPath);
219
+ const deployConfigContent = await fs.promises.readFile(deployConfigPath, 'utf-8');
220
+ const deployConfig = yaml.parse(deployConfigContent);
229
221
  const customTasks = deployConfig?.builder?.customTasks;
230
222
  if (customTasks) {
231
223
  const isAbapDeployTarget = customTasks.some((task) => task.name === 'deploy-to-abap');
232
- deployTarget = isAbapDeployTarget ? types_1.DeployTarget.ABAP : types_1.DeployTarget.CF;
224
+ deployTarget = isAbapDeployTarget ? DeployTarget.ABAP : DeployTarget.CF;
233
225
  }
234
226
  else {
235
- deployTarget = types_1.DeployTarget.UNKNOWN_DEPLOY_CONFIG;
227
+ deployTarget = DeployTarget.UNKNOWN_DEPLOY_CONFIG;
236
228
  }
237
229
  }
238
230
  catch {
@@ -246,7 +238,7 @@ async function getDeployTarget(appPath) {
246
238
  * @returns String value 'internal' | 'external' to be backward compatible with existing telemetry data format.
247
239
  */
248
240
  function getInternalVsExternal() {
249
- return config_state_1.ToolingTelemetrySettings.internalFeature ? 'internal' : 'external';
241
+ return ToolingTelemetrySettings.internalFeature ? 'internal' : 'external';
250
242
  }
251
243
  /**
252
244
  * Retrieves the source template configuration from either the standard manifest.json or
@@ -256,21 +248,21 @@ function getInternalVsExternal() {
256
248
  * @returns {Promise<SourceTemplate>} A promise that resolves to the source template configuration object.
257
249
  */
258
250
  async function getSourceTemplate(appPath) {
259
- const webappPath = await (0, project_access_1.getWebappPath)(appPath);
251
+ const webappPath = await getWebappPath(appPath);
260
252
  const paths = {
261
- manifest: node_path_1.default.join(webappPath, 'manifest.json'),
262
- appdescr: node_path_1.default.join(webappPath, 'manifest.appdescr_variant'),
263
- ui5Yaml: node_path_1.default.join(appPath, 'ui5.yaml')
253
+ manifest: path.join(webappPath, 'manifest.json'),
254
+ appdescr: path.join(webappPath, 'manifest.appdescr_variant'),
255
+ ui5Yaml: path.join(appPath, 'ui5.yaml')
264
256
  };
265
257
  try {
266
- if (node_fs_1.default.existsSync(paths.manifest)) {
267
- const manifestStr = await node_fs_1.default.promises.readFile(paths.manifest, 'utf-8');
258
+ if (fs.existsSync(paths.manifest)) {
259
+ const manifestStr = await fs.promises.readFile(paths.manifest, 'utf-8');
268
260
  const manifest = JSON.parse(manifestStr);
269
261
  return populateSourceTemplate(manifest['sap.app']?.sourceTemplate ?? {});
270
262
  }
271
- if (node_fs_1.default.existsSync(paths.appdescr) && node_fs_1.default.existsSync(paths.ui5Yaml)) {
272
- const baseUi5ConfigContent = await node_fs_1.default.promises.readFile(paths.ui5Yaml, 'utf-8');
273
- const ui5Config = await ui5_config_1.UI5Config.newInstance(baseUi5ConfigContent);
263
+ if (fs.existsSync(paths.appdescr) && fs.existsSync(paths.ui5Yaml)) {
264
+ const baseUi5ConfigContent = await fs.promises.readFile(paths.ui5Yaml, 'utf-8');
265
+ const ui5Config = await UI5Config.newInstance(baseUi5ConfigContent);
274
266
  const adp = ui5Config.getCustomConfiguration('adp');
275
267
  return populateSourceTemplate(adp?.support ?? {});
276
268
  }
@@ -290,7 +282,7 @@ function populateSourceTemplate(sourceTemplate) {
290
282
  return {
291
283
  id: sourceTemplate.id ?? '',
292
284
  version: sourceTemplate.version ?? '',
293
- toolsId: sourceTemplate.toolsId ?? types_1.ToolsId.NO_TOOLS_ID
285
+ toolsId: sourceTemplate.toolsId ?? ToolsId.NO_TOOLS_ID
294
286
  };
295
287
  }
296
288
  /**
@@ -300,7 +292,7 @@ function populateSourceTemplate(sourceTemplate) {
300
292
  */
301
293
  async function getOSNodeVersion() {
302
294
  try {
303
- const nodeVer = (await new nodejs_utils_1.CommandRunner().run('node', ['-v'])) ?? 'unknown';
295
+ const nodeVer = (await new CommandRunner().run('node', ['-v'])) ?? 'unknown';
304
296
  return nodeVer.replaceAll(/(?:^v)|([\r\n]{1,100})/g, '');
305
297
  }
306
298
  catch {
@@ -323,9 +315,9 @@ async function getOSNodeVersion() {
323
315
  *
324
316
  * @returns The detected IDE type
325
317
  */
326
- function getIdeType() {
318
+ export function getIdeType() {
327
319
  // AppStudio is a VS Code fork that sets VSCODE_PID — check first to avoid misdetection as 'vscode'
328
- if ((0, btp_utils_1.isAppStudio)()) {
320
+ if (isAppStudio()) {
329
321
  return 'appstudio';
330
322
  }
331
323
  const vscodeCwd = process.env.VSCODE_CWD?.toLowerCase() ?? '';
@@ -1,5 +1,5 @@
1
- export * from './telemetry-client';
2
- export { processToolsSuiteTelemetry, getIdeType } from './data-processor';
3
- export * from './telemetry-settings';
4
- export * from './types';
1
+ export * from './telemetry-client.js';
2
+ export { processToolsSuiteTelemetry, getIdeType } from './data-processor.js';
3
+ export * from './telemetry-settings.js';
4
+ export * from './types.js';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1,24 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getIdeType = exports.processToolsSuiteTelemetry = void 0;
18
- __exportStar(require("./telemetry-client"), exports);
19
- var data_processor_1 = require("./data-processor");
20
- Object.defineProperty(exports, "processToolsSuiteTelemetry", { enumerable: true, get: function () { return data_processor_1.processToolsSuiteTelemetry; } });
21
- Object.defineProperty(exports, "getIdeType", { enumerable: true, get: function () { return data_processor_1.getIdeType; } });
22
- __exportStar(require("./telemetry-settings"), exports);
23
- __exportStar(require("./types"), exports);
1
+ export * from './telemetry-client.js';
2
+ export { processToolsSuiteTelemetry, getIdeType } from './data-processor.js';
3
+ export * from './telemetry-settings.js';
4
+ export * from './types.js';
24
5
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
- import { ApplicationInsightClient } from '../base/client/azure-appinsight-client';
2
- import type { SampleRate, TelemetryMeasurements, TelemetryProperties } from '../base/types';
3
- import type { TelemetryHelperProperties, TelemetryEvent } from './types';
1
+ import { ApplicationInsightClient } from '../base/client/azure-appinsight-client.js';
2
+ import type { SampleRate, TelemetryMeasurements, TelemetryProperties } from '../base/types/index.js';
3
+ import type { TelemetryHelperProperties, TelemetryEvent } from './types.js';
4
4
  /**
5
5
  *
6
6
  */
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ToolsSuiteTelemetryClient = void 0;
4
- const azure_appinsight_client_1 = require("../base/client/azure-appinsight-client");
5
- const _1 = require(".");
6
- const date_1 = require("../base/utils/date");
1
+ import { ApplicationInsightClient } from '../base/client/azure-appinsight-client.js';
2
+ import { processToolsSuiteTelemetry } from './index.js';
3
+ import { localDatetimeToUTC } from '../base/utils/date.js';
7
4
  /**
8
5
  *
9
6
  */
10
- class ToolsSuiteTelemetryClient extends azure_appinsight_client_1.ApplicationInsightClient {
7
+ class ToolsSuiteTelemetryClient extends ApplicationInsightClient {
11
8
  /**
12
9
  *
13
10
  * @param applicationKey Application key to identify the Azure Application Insight resource
@@ -30,10 +27,10 @@ class ToolsSuiteTelemetryClient extends azure_appinsight_client_1.ApplicationIns
30
27
  * @returns Promise<void>
31
28
  */
32
29
  async report(eventName, properties, measurements, sampleRate, telemetryHelperProperties, ignoreSettings) {
33
- const fioriProjectCommonProperties = await (0, _1.processToolsSuiteTelemetry)(telemetryHelperProperties);
30
+ const fioriProjectCommonProperties = await processToolsSuiteTelemetry(telemetryHelperProperties);
34
31
  const commonProperties = {
35
32
  v: this.extensionVersion,
36
- datetime: (0, date_1.localDatetimeToUTC)()
33
+ datetime: localDatetimeToUTC()
37
34
  };
38
35
  const finalProperties = {
39
36
  ...properties,
@@ -79,10 +76,10 @@ class ToolsSuiteTelemetryClient extends azure_appinsight_client_1.ApplicationIns
79
76
  * @returns Telemetry properties and measurements
80
77
  */
81
78
  async collectToolsSuiteTelemetry(event, telemetryHelperProperties) {
82
- const fioriProjectCommonProperties = await (0, _1.processToolsSuiteTelemetry)(telemetryHelperProperties);
79
+ const fioriProjectCommonProperties = await processToolsSuiteTelemetry(telemetryHelperProperties);
83
80
  const telemetryEventCommonProperties = {
84
81
  v: this.extensionVersion,
85
- datetime: (0, date_1.localDatetimeToUTC)()
82
+ datetime: localDatetimeToUTC()
86
83
  };
87
84
  const finalProperties = {
88
85
  ...event.properties,
@@ -98,5 +95,5 @@ class ToolsSuiteTelemetryClient extends azure_appinsight_client_1.ApplicationIns
98
95
  };
99
96
  }
100
97
  }
101
- exports.ToolsSuiteTelemetryClient = ToolsSuiteTelemetryClient;
98
+ export { ToolsSuiteTelemetryClient };
102
99
  //# sourceMappingURL=telemetry-client.js.map
@@ -1,4 +1,4 @@
1
- import type { ToolsSuiteTelemetryInitSettings } from './types';
1
+ import type { ToolsSuiteTelemetryInitSettings } from './types.js';
2
2
  import { TelemetrySetting } from '@sap-ux/store';
3
3
  /**
4
4
  * Telemetry API function to init settings.
@@ -1,20 +1,12 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.initTelemetrySettings = void 0;
7
- exports.setEnableTelemetry = setEnableTelemetry;
8
- exports.getTelemetrySetting = getTelemetrySetting;
9
- const reporting_1 = require("../base/utils/reporting");
10
- const store_1 = require("@sap-ux/store");
11
- const btp_utils_1 = require("@sap-ux/btp-utils");
12
- const node_os_1 = __importDefault(require("node:os"));
13
- const node_path_1 = __importDefault(require("node:path"));
14
- const node_fs_1 = __importDefault(require("node:fs"));
15
- const data_processor_1 = require("./data-processor");
16
- const config_state_1 = require("../base/config-state");
17
- const config_state_2 = require("./config-state");
1
+ import { reportRuntimeError, reportEnableTelemetryOnOff } from '../base/utils/reporting.js';
2
+ import { getService, Entity, TelemetrySetting, TelemetrySettingKey, getFilesystemWatcherFor } from '@sap-ux/store';
3
+ import { isAppStudio } from '@sap-ux/btp-utils';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import fs from 'node:fs';
7
+ import { getCommonProperties } from './data-processor.js';
8
+ import { TelemetrySettings } from '../base/config-state.js';
9
+ import { ToolingTelemetrySettings } from './config-state.js';
18
10
  const deprecatedSettingPaths = {
19
11
  win32: '\\AppData\\Roaming\\Code\\User\\settings.json',
20
12
  darwin: '/Library/Application Support/Code/User/settings.json',
@@ -30,15 +22,15 @@ const deprecatedExtensionPropKeys = [
30
22
  const definePath = (paths) => {
31
23
  const platform = process.platform;
32
24
  let settingsPath = paths[platform];
33
- if ((0, btp_utils_1.isAppStudio)()) {
25
+ if (isAppStudio()) {
34
26
  settingsPath = paths.theia;
35
27
  }
36
28
  if (!settingsPath) {
37
29
  // no path for unknown platform settings path
38
30
  return null;
39
31
  }
40
- const homedir = node_os_1.default.homedir();
41
- return node_path_1.default.join(homedir, settingsPath);
32
+ const homedir = os.homedir();
33
+ return path.join(homedir, settingsPath);
42
34
  };
43
35
  /**
44
36
  * Read telemetry settings from file store.
@@ -48,7 +40,7 @@ const definePath = (paths) => {
48
40
  async function readEnableTelemetry(storeService) {
49
41
  let setting;
50
42
  try {
51
- setting = await storeService.read(new store_1.TelemetrySettingKey());
43
+ setting = await storeService.read(new TelemetrySettingKey());
52
44
  }
53
45
  catch {
54
46
  // ignore read failure, assume file doens't exist and thus setting is undefined
@@ -65,7 +57,7 @@ async function readEnableTelemetry(storeService) {
65
57
  // If deprecated vscode setting exists, set central telemetry setting to false if any of vscode setting was false
66
58
  let content;
67
59
  try {
68
- content = await node_fs_1.default.promises.readFile(deprecatedSettingPath, 'utf-8');
60
+ content = await fs.promises.readFile(deprecatedSettingPath, 'utf-8');
69
61
  const deprecatedSetting = JSON.parse(content);
70
62
  const propValues = deprecatedExtensionPropKeys.map((propKey) => (deprecatedSetting[propKey] ?? true));
71
63
  const deprecatedEnableTelemetrySetting = propValues.reduce((prevValue, currentValue) => prevValue && currentValue, true);
@@ -78,7 +70,7 @@ async function readEnableTelemetry(storeService) {
78
70
  }
79
71
  }
80
72
  else {
81
- config_state_1.TelemetrySettings.telemetryEnabled = setting.enableTelemetry;
73
+ TelemetrySettings.telemetryEnabled = setting.enableTelemetry;
82
74
  }
83
75
  }
84
76
  /**
@@ -87,12 +79,12 @@ async function readEnableTelemetry(storeService) {
87
79
  * @param storeService Store service that is used for read/write telemetry settings
88
80
  */
89
81
  function watchTelemetrySettingStore(storeService) {
90
- (0, store_1.getFilesystemWatcherFor)(store_1.Entity.TelemetrySetting, () => {
82
+ getFilesystemWatcherFor(Entity.TelemetrySetting, () => {
91
83
  storeService
92
- .read(new store_1.TelemetrySettingKey())
84
+ .read(new TelemetrySettingKey())
93
85
  .then((watchedSetting) => {
94
86
  if (watchedSetting) {
95
- config_state_1.TelemetrySettings.telemetryEnabled = watchedSetting.enableTelemetry;
87
+ TelemetrySettings.telemetryEnabled = watchedSetting.enableTelemetry;
96
88
  }
97
89
  })
98
90
  .catch(() => {
@@ -105,15 +97,15 @@ function watchTelemetrySettingStore(storeService) {
105
97
  *
106
98
  * @param options Settings pass from the consumer module.
107
99
  */
108
- const initTelemetrySettings = async (options) => {
100
+ export const initTelemetrySettings = async (options) => {
109
101
  try {
110
- config_state_1.TelemetrySettings.consumerModuleName = options.consumerModule.name;
111
- config_state_1.TelemetrySettings.consumerModuleVersion = options.consumerModule.version;
112
- config_state_2.ToolingTelemetrySettings.internalFeature = options.internalFeature ?? false;
102
+ TelemetrySettings.consumerModuleName = options.consumerModule.name;
103
+ TelemetrySettings.consumerModuleVersion = options.consumerModule.version;
104
+ ToolingTelemetrySettings.internalFeature = options.internalFeature ?? false;
113
105
  if (options.resourceId) {
114
- config_state_1.TelemetrySettings.azureInstrumentationKey = options.resourceId;
106
+ TelemetrySettings.azureInstrumentationKey = options.resourceId;
115
107
  }
116
- const storeService = await (0, store_1.getService)({
108
+ const storeService = await getService({
117
109
  entityName: 'telemetrySetting'
118
110
  });
119
111
  await readEnableTelemetry(storeService);
@@ -122,43 +114,42 @@ const initTelemetrySettings = async (options) => {
122
114
  }
123
115
  }
124
116
  catch (err) {
125
- (0, reporting_1.reportRuntimeError)(err);
117
+ reportRuntimeError(err);
126
118
  }
127
119
  };
128
- exports.initTelemetrySettings = initTelemetrySettings;
129
120
  /**
130
121
  * Toggle on/off enable telemetry setting. This will update telemetry settings file
131
122
  * and the runtime setting.
132
123
  *
133
124
  * @param enableTelemetry Telemetry is enabled or not
134
125
  */
135
- async function setEnableTelemetry(enableTelemetry) {
126
+ export async function setEnableTelemetry(enableTelemetry) {
136
127
  try {
137
- const storeService = await (0, store_1.getService)({
128
+ const storeService = await getService({
138
129
  entityName: 'telemetrySetting'
139
130
  });
140
- const setting = new store_1.TelemetrySetting({ enableTelemetry });
131
+ const setting = new TelemetrySetting({ enableTelemetry });
141
132
  await storeService.write(setting);
142
- config_state_1.TelemetrySettings.telemetryEnabled = enableTelemetry;
133
+ TelemetrySettings.telemetryEnabled = enableTelemetry;
143
134
  }
144
135
  catch {
145
136
  // Telemetry settings could not be written
146
137
  }
147
- const commonProperties = await (0, data_processor_1.getCommonProperties)();
148
- (0, reporting_1.reportEnableTelemetryOnOff)(enableTelemetry, commonProperties);
138
+ const commonProperties = await getCommonProperties();
139
+ reportEnableTelemetryOnOff(enableTelemetry, commonProperties);
149
140
  }
150
141
  /**
151
142
  * Get telemetry settings.
152
143
  *
153
144
  * @returns Telemetry settings of context module that consumes telemetry library
154
145
  */
155
- async function getTelemetrySetting() {
146
+ export async function getTelemetrySetting() {
156
147
  let setting;
157
148
  try {
158
- const storeService = await (0, store_1.getService)({
149
+ const storeService = await getService({
159
150
  entityName: 'telemetrySetting'
160
151
  });
161
- setting = await storeService.read(new store_1.TelemetrySettingKey());
152
+ setting = await storeService.read(new TelemetrySettingKey());
162
153
  }
163
154
  catch {
164
155
  // ignore if settings could not be read, return undefined
@@ -1,4 +1,4 @@
1
- import type { ProjectInfo, TelemetryMeasurements, TelemetryProperties } from '../base/types';
1
+ import type { ProjectInfo, TelemetryMeasurements, TelemetryProperties } from '../base/types/index.js';
2
2
  import type { AppType } from '@sap-ux/project-access';
3
3
  export type TelemetryHelperProperties = {
4
4
  appPath: string;
@@ -1,26 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommonProperties = exports.DeployTarget = exports.ODataSource = exports.ToolsId = void 0;
4
- var ToolsId;
1
+ export var ToolsId;
5
2
  (function (ToolsId) {
6
3
  ToolsId["UNKNOWN"] = "UNKNOWN";
7
4
  ToolsId["NO_TOOLS_ID"] = "NO_TOOLS_ID";
8
- })(ToolsId || (exports.ToolsId = ToolsId = {}));
9
- var ODataSource;
5
+ })(ToolsId || (ToolsId = {}));
6
+ export var ODataSource;
10
7
  (function (ODataSource) {
11
8
  ODataSource["CAPJava"] = "CAPJava";
12
9
  ODataSource["CAPNode"] = "CAPNode";
13
10
  ODataSource["ABAP"] = "ABAP";
14
11
  ODataSource["UNKNOWN"] = "UNKNOWN";
15
- })(ODataSource || (exports.ODataSource = ODataSource = {}));
16
- var DeployTarget;
12
+ })(ODataSource || (ODataSource = {}));
13
+ export var DeployTarget;
17
14
  (function (DeployTarget) {
18
15
  DeployTarget["CF"] = "CF";
19
16
  DeployTarget["ABAP"] = "ABAP";
20
17
  DeployTarget["UNKNOWN_DEPLOY_CONFIG"] = "UNKNOWN_DEPLOY_CONFIG";
21
18
  DeployTarget["NO_DEPLOY_CONFIG"] = "NO_DEPLOY_CONFIG";
22
- })(DeployTarget || (exports.DeployTarget = DeployTarget = {}));
23
- var CommonProperties;
19
+ })(DeployTarget || (DeployTarget = {}));
20
+ export var CommonProperties;
24
21
  (function (CommonProperties) {
25
22
  CommonProperties["DevSpace"] = "cmn.devspace";
26
23
  CommonProperties["AppStudio"] = "cmn.appstudio";
@@ -37,5 +34,5 @@ var CommonProperties;
37
34
  CommonProperties["TemplateVersion"] = "cmn.templateVersion";
38
35
  CommonProperties["ApplicationType"] = "cmn.applicationType";
39
36
  CommonProperties["IdeType"] = "cmn.ideType";
40
- })(CommonProperties || (exports.CommonProperties = CommonProperties = {}));
37
+ })(CommonProperties || (CommonProperties = {}));
41
38
  //# sourceMappingURL=types.js.map