@etm-professional-control/winccoa-mcp-server 1.5.0 → 1.5.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.
Files changed (47) hide show
  1. package/.env.example +6 -2
  2. package/OSS.md +8 -8
  3. package/README.md +4 -4
  4. package/build/helpers/icons/IX_ICONS_LIST.txt +1407 -0
  5. package/build/helpers/icons/IconGenerator.d.ts +54 -3
  6. package/build/helpers/icons/IconGenerator.d.ts.map +1 -1
  7. package/build/helpers/icons/IconGenerator.js +104 -22
  8. package/build/helpers/icons/IconGenerator.js.map +1 -1
  9. package/build/helpers/icons/IconList.d.ts +17 -2
  10. package/build/helpers/icons/IconList.d.ts.map +1 -1
  11. package/build/helpers/icons/IconList.js +41 -19
  12. package/build/helpers/icons/IconList.js.map +1 -1
  13. package/build/tool_loader.d.ts +21 -1
  14. package/build/tool_loader.d.ts.map +1 -1
  15. package/build/tool_loader.js +49 -8
  16. package/build/tool_loader.js.map +1 -1
  17. package/build/tools/archive/archive_query.d.ts.map +1 -1
  18. package/build/tools/archive/archive_query.js +2 -5
  19. package/build/tools/archive/archive_query.js.map +1 -1
  20. package/build/tools/common/common_query.d.ts.map +1 -1
  21. package/build/tools/common/common_query.js +2 -5
  22. package/build/tools/common/common_query.js.map +1 -1
  23. package/build/tools/datapoints/dp_basic.d.ts.map +1 -1
  24. package/build/tools/datapoints/dp_basic.js +62 -38
  25. package/build/tools/datapoints/dp_basic.js.map +1 -1
  26. package/build/tools/datapoints/dp_types.d.ts.map +1 -1
  27. package/build/tools/datapoints/dp_types.js +15 -9
  28. package/build/tools/datapoints/dp_types.js.map +1 -1
  29. package/build/tools/icons/icon.d.ts.map +1 -1
  30. package/build/tools/icons/icon.js +52 -7
  31. package/build/tools/icons/icon.js.map +1 -1
  32. package/build/tools/pv_range/pv_range_query.d.ts +12 -0
  33. package/build/tools/pv_range/pv_range_query.d.ts.map +1 -1
  34. package/build/tools/pv_range/pv_range_query.js +63 -31
  35. package/build/tools/pv_range/pv_range_query.js.map +1 -1
  36. package/build/utils/helpers.d.ts +56 -4
  37. package/build/utils/helpers.d.ts.map +1 -1
  38. package/build/utils/helpers.js +144 -14
  39. package/build/utils/helpers.js.map +1 -1
  40. package/build/utils/projectPath.d.ts +52 -0
  41. package/build/utils/projectPath.d.ts.map +1 -0
  42. package/build/utils/projectPath.js +102 -0
  43. package/build/utils/projectPath.js.map +1 -0
  44. package/manifest.cjs +50 -0
  45. package/package.json +5 -4
  46. package/postinstall.cjs +10 -4
  47. package/sbom.json +582 -623
@@ -4,38 +4,68 @@
4
4
  * MCP tool for querying existing pv_range configurations from datapoint elements.
5
5
  */
6
6
  import { z } from 'zod';
7
- import { createSuccessResponse, createErrorResponse } from '../../utils/helpers.js';
7
+ import { createSuccessResponse, createErrorResponse, describeWinccoaError, logWinccoaError } from '../../utils/helpers.js';
8
+ import * as log from '../../utils/logger.js';
8
9
  import { DpConfigType } from '../../types/winccoa/constants.js';
10
+ /** WinCC OA error 19: "attribute does not exist in this config" - i.e. not configured. */
11
+ const ERR_ATTRIBUTE_NOT_IN_CONFIG = 19;
9
12
  /**
10
- * Query range configuration for a datapoint element
13
+ * True if the error only says the attribute does not exist in the config
14
+ * (code 19, directly or in every nested detail). That is the normal answer
15
+ * for a datapoint element without a pv_range config, not a failure.
11
16
  */
12
- async function queryRangeConfig(winccoa, dpe) {
17
+ export function isNotConfiguredError(error) {
18
+ const described = describeWinccoaError(error);
19
+ if (described.details.length > 0) {
20
+ return described.details.every(d => d.code === ERR_ATTRIBUTE_NOT_IN_CONFIG);
21
+ }
22
+ return described.code === ERR_ATTRIBUTE_NOT_IN_CONFIG;
23
+ }
24
+ /**
25
+ * Read one _pv_range attribute.
26
+ * @returns The value, or undefined if the attribute does not exist in this config
27
+ * @throws Any other WinCC OA error
28
+ */
29
+ async function readRangeAttribute(winccoa, dpe, attribute) {
13
30
  try {
14
- // Read all range configuration parameters
15
- const [configType, minValue, maxValue, includeMin, includeMax] = await Promise.all([
16
- winccoa.dpGet(`${dpe}:_pv_range.._type`),
17
- winccoa.dpGet(`${dpe}:_pv_range.._min`),
18
- winccoa.dpGet(`${dpe}:_pv_range.._max`),
19
- winccoa.dpGet(`${dpe}:_pv_range.._incl_min`),
20
- winccoa.dpGet(`${dpe}:_pv_range.._incl_max`)
21
- ]);
22
- // Check if configuration exists
23
- if (configType === DpConfigType.DPCONFIG_NONE || configType === null || configType === undefined) {
24
- return null;
25
- }
26
- return {
27
- type: configType,
28
- min: minValue,
29
- max: maxValue,
30
- includeMin: includeMin,
31
- includeMax: includeMax,
32
- configured: true
33
- };
31
+ return await winccoa.dpGet(`${dpe}:_pv_range.._${attribute}`);
34
32
  }
35
33
  catch (error) {
36
- console.error(`Error querying range config for ${dpe}:`, error);
34
+ if (isNotConfiguredError(error)) {
35
+ log.debug(`${dpe}:_pv_range.._${attribute} does not exist in this config`);
36
+ return undefined;
37
+ }
38
+ throw error;
39
+ }
40
+ }
41
+ /**
42
+ * Query range configuration for a datapoint element
43
+ * @returns The configuration, or null if no pv_range config exists
44
+ * @throws On real WinCC OA errors (not on "not configured")
45
+ */
46
+ export async function queryRangeConfig(winccoa, dpe) {
47
+ // Read the config type first: without a config, the other attributes do not
48
+ // exist and reading them only produces errors.
49
+ const configType = await readRangeAttribute(winccoa, dpe, 'type');
50
+ if (configType === DpConfigType.DPCONFIG_NONE || configType === null || configType === undefined) {
37
51
  return null;
38
52
  }
53
+ // Not every range type has every attribute (e.g. a set range check has no
54
+ // min/max); those come back as undefined.
55
+ const [minValue, maxValue, includeMin, includeMax] = await Promise.all([
56
+ readRangeAttribute(winccoa, dpe, 'min'),
57
+ readRangeAttribute(winccoa, dpe, 'max'),
58
+ readRangeAttribute(winccoa, dpe, 'incl_min'),
59
+ readRangeAttribute(winccoa, dpe, 'incl_max')
60
+ ]);
61
+ return {
62
+ type: configType,
63
+ min: minValue,
64
+ max: maxValue,
65
+ includeMin: includeMin,
66
+ includeMax: includeMax,
67
+ configured: true
68
+ };
39
69
  }
40
70
  /**
41
71
  * Register pv_range query tools
@@ -62,7 +92,9 @@ export function registerTools(server, context) {
62
92
  - includeMax: Whether maximum is included in valid range
63
93
  - configured: true if a configuration exists
64
94
 
65
- Returns null if no pv_range configuration exists.
95
+ If no pv_range configuration exists, returns
96
+ {"dpe": "...", "configured": false, "message": "No pv_range configuration exists for this datapoint element"}.
97
+ Attributes that do not exist for the configured range type are omitted.
66
98
  `, {
67
99
  dpe: z.string().describe('Datapoint element name (e.g., System1:MyTag.)')
68
100
  }, async ({ dpe }) => {
@@ -98,12 +130,12 @@ export function registerTools(server, context) {
98
130
  });
99
131
  }
100
132
  catch (error) {
101
- const errorMessage = error instanceof Error ? error.message : String(error);
102
- console.error('========================================');
103
- console.error('✗ PV Range Query Failed');
104
- console.error('========================================');
105
- console.error(`Error: ${errorMessage}`);
106
- return createErrorResponse(`Failed to query pv_range configuration: ${errorMessage}`);
133
+ logWinccoaError('PV Range Query Failed', error);
134
+ const described = describeWinccoaError(error);
135
+ return createErrorResponse(`Failed to query pv_range configuration: ${described.message}`, {
136
+ ...(described.code !== undefined ? { errorCode: described.code } : {}),
137
+ ...(described.details.length > 0 ? { details: described.details } : {})
138
+ });
107
139
  }
108
140
  });
109
141
  return 1; // Number of tools registered
@@ -1 +1 @@
1
- {"version":3,"file":"pv_range_query.js","sourceRoot":"","sources":["../../../src/tools/pv_range/pv_range_query.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAGhE;;GAEG;AACH,KAAK,UAAU,gBAAgB,CAAC,OAAY,EAAE,GAAW;IACvD,IAAI,CAAC;QACH,0CAA0C;QAC1C,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE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AC,CAAC,CAAC,6BAA6B;AACzC,CAAC"}
@@ -2,14 +2,66 @@
2
2
  * Utility helper functions for MCP tool responses and datapoint operations
3
3
  */
4
4
  import type { WinccoaManager } from 'winccoa-manager';
5
- import type { McpContent, McpToolResponse, DatapointChild } from '../types/index.js';
5
+ import type { McpToolResponse, DatapointChild } from '../types/index.js';
6
6
  /**
7
- * Create content array for MCP responses, filtering internal types if needed
7
+ * Filter datapoint type names, dropping internal types (starting with _) unless requested
8
8
  * @param arr - Array of type names
9
9
  * @param withInternals - Whether to include internal types (starting with _)
10
- * @returns Content array for MCP response
10
+ * @returns Filtered type names
11
11
  */
12
- export declare function mkTypesContent(arr: string[], withInternals?: boolean): McpContent[];
12
+ export declare function filterTypeNames(arr: ReadonlyArray<string | undefined>, withInternals?: boolean): string[];
13
+ /** One flattened WinCC OA error (see describeWinccoaError). */
14
+ export interface WinccoaErrorDetail {
15
+ code?: number;
16
+ message: string;
17
+ dpe?: string;
18
+ }
19
+ /** Flattened view of a WinCC OA error, including its nested details. */
20
+ export interface WinccoaErrorDescription {
21
+ /** Effective code: the inner code if all inner errors agree, else the outer code */
22
+ code?: number;
23
+ /** Outer code as reported by the manager (e.g. 9399 "multiple errors") */
24
+ outerCode?: number;
25
+ /** Human-readable message: the inner messages if there are any, else the outer message */
26
+ message: string;
27
+ /** Inner errors, flattened */
28
+ details: WinccoaErrorDetail[];
29
+ }
30
+ /**
31
+ * Flatten a WinccoaError into code, message and inner details.
32
+ *
33
+ * A failing dpGet usually throws 9399 "multiple errors (N errors total)" with
34
+ * the real cause - e.g. 71 "DP does not exist" naming the element - only in
35
+ * `details`. Forwarding `error.message` alone hides that from the client.
36
+ * Nested details are flattened (their own details are pulled up one level).
37
+ *
38
+ * @param e - Caught error
39
+ * @param fallbackDpe - DPE the caller requested; used for inner details that carry no dpe themselves
40
+ * @returns Flattened description
41
+ */
42
+ export declare function describeWinccoaError(e: unknown, fallbackDpe?: string): WinccoaErrorDescription;
43
+ /**
44
+ * Log a caught WinCC OA error as a single line.
45
+ *
46
+ * Expected not-found codes (71 DP does not exist, 57 DP type does not exist,
47
+ * 19 attribute not in config) are client mistakes and go out at warn level.
48
+ * Everything else is logged at error level; the stack is added only at
49
+ * MCP_LOG_LEVEL=debug. The error object itself is never dumped.
50
+ *
51
+ * @param context - What was being attempted, e.g. "Error getting type name for X"
52
+ * @param e - Caught error
53
+ * @param fallbackDpe - DPE the caller requested
54
+ */
55
+ export declare function logWinccoaError(context: string, e: unknown, fallbackDpe?: string): void;
56
+ /**
57
+ * Build the uniform error envelope for a caught WinCC OA error:
58
+ * `{error, message, errorCode?, errorType?, details}`.
59
+ *
60
+ * @param prefix - Message prefix, e.g. "Failed to get type name for X"
61
+ * @param e - Caught error
62
+ * @param fallbackDpe - DPE the caller requested (fills empty details[].dpe)
63
+ */
64
+ export declare function winccoaErrorResponse(prefix: string, e: unknown, fallbackDpe?: string): McpToolResponse;
13
65
  /**
14
66
  * Recursively add description and unit information to datapoint children
15
67
  * @param children - Array of child datapoint elements
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EACV,UAAU,EAGV,eAAe,EACf,cAAc,EACf,MAAM,mBAAmB,CAAC;AAE3B;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,aAAa,CAAC,EAAE,OAAO,GAAG,UAAU,EAAE,CAanF;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,cAAc,EAAE,EAC1B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,GACtB,IAAI,CAeN;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CA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
+ import * as log from './logger.js';
4
5
  /**
5
- * Create content array for MCP responses, filtering internal types if needed
6
+ * Filter datapoint type names, dropping internal types (starting with _) unless requested
6
7
  * @param arr - Array of type names
7
8
  * @param withInternals - Whether to include internal types (starting with _)
8
- * @returns Content array for MCP response
9
+ * @returns Filtered type names
9
10
  */
10
- export function mkTypesContent(arr, withInternals) {
11
- const ret = [];
12
- for (let i = 0; i < arr.length; i++) {
13
- const item = arr[i];
14
- if (item !== undefined) {
15
- if (!item.startsWith('_')) {
16
- ret.push({ type: "text", text: item });
17
- }
18
- else if (withInternals) {
19
- ret.push({ type: "text", text: item });
20
- }
11
+ export function filterTypeNames(arr, withInternals) {
12
+ return arr.filter((item) => typeof item === 'string' && (withInternals === true || !item.startsWith('_')));
13
+ }
14
+ /** Read a numeric `code` from an error-like value. */
15
+ function errorCode(e) {
16
+ const code = e?.code;
17
+ if (typeof code === 'number')
18
+ return code;
19
+ if (typeof code === 'string' && code.trim() !== '' && !Number.isNaN(Number(code)))
20
+ return Number(code);
21
+ return undefined;
22
+ }
23
+ /** Read a message from an error-like value. */
24
+ function errorMessage(e) {
25
+ if (e instanceof Error)
26
+ return e.message;
27
+ if (typeof e === 'string')
28
+ return e;
29
+ const message = e?.message;
30
+ return typeof message === 'string' ? message : String(e);
31
+ }
32
+ /** Read the dpe an error refers to, if the manager attached one. */
33
+ function errorDpe(e) {
34
+ const err = e;
35
+ if (typeof err?.dpe === 'string')
36
+ return err.dpe;
37
+ if (typeof err?.dpName === 'string')
38
+ return err.dpName;
39
+ return undefined;
40
+ }
41
+ /** Nested WinCC OA errors, if any. */
42
+ function errorDetails(e) {
43
+ const details = e?.details;
44
+ if (Array.isArray(details))
45
+ return details;
46
+ // A single nested error instead of an array
47
+ if (details instanceof Error || (typeof details === 'object' && details !== null && 'message' in details)) {
48
+ return [details];
49
+ }
50
+ return [];
51
+ }
52
+ /**
53
+ * Flatten a WinccoaError into code, message and inner details.
54
+ *
55
+ * A failing dpGet usually throws 9399 "multiple errors (N errors total)" with
56
+ * the real cause - e.g. 71 "DP does not exist" naming the element - only in
57
+ * `details`. Forwarding `error.message` alone hides that from the client.
58
+ * Nested details are flattened (their own details are pulled up one level).
59
+ *
60
+ * @param e - Caught error
61
+ * @param fallbackDpe - DPE the caller requested; used for inner details that carry no dpe themselves
62
+ * @returns Flattened description
63
+ */
64
+ export function describeWinccoaError(e, fallbackDpe) {
65
+ const outerCode = errorCode(e);
66
+ const outerMessage = errorMessage(e);
67
+ const details = [];
68
+ const push = (inner) => {
69
+ const detail = { message: errorMessage(inner) };
70
+ const code = errorCode(inner);
71
+ if (code !== undefined)
72
+ detail.code = code;
73
+ const dpe = errorDpe(inner) || fallbackDpe;
74
+ if (dpe)
75
+ detail.dpe = dpe;
76
+ details.push(detail);
77
+ };
78
+ for (const inner of errorDetails(e)) {
79
+ const nested = errorDetails(inner);
80
+ if (nested.length > 0) {
81
+ nested.forEach(push);
82
+ }
83
+ else {
84
+ push(inner);
21
85
  }
22
86
  }
23
- return ret;
87
+ if (details.length === 0) {
88
+ return {
89
+ ...(outerCode !== undefined ? { code: outerCode, outerCode } : {}),
90
+ message: outerMessage,
91
+ details
92
+ };
93
+ }
94
+ const innerCodes = new Set(details.map(d => d.code));
95
+ const commonCode = innerCodes.size === 1 ? [...innerCodes][0] : undefined;
96
+ const code = commonCode !== undefined ? commonCode : outerCode;
97
+ const message = [...new Set(details.map(d => d.message))].join('; ');
98
+ return {
99
+ ...(code !== undefined ? { code } : {}),
100
+ ...(outerCode !== undefined ? { outerCode } : {}),
101
+ message,
102
+ details
103
+ };
104
+ }
105
+ /** Codes meaning "the client asked for something that does not exist": expected, not a server fault. */
106
+ const EXPECTED_NOT_FOUND_CODES = new Set([71, 57, 19]);
107
+ /**
108
+ * Log a caught WinCC OA error as a single line.
109
+ *
110
+ * Expected not-found codes (71 DP does not exist, 57 DP type does not exist,
111
+ * 19 attribute not in config) are client mistakes and go out at warn level.
112
+ * Everything else is logged at error level; the stack is added only at
113
+ * MCP_LOG_LEVEL=debug. The error object itself is never dumped.
114
+ *
115
+ * @param context - What was being attempted, e.g. "Error getting type name for X"
116
+ * @param e - Caught error
117
+ * @param fallbackDpe - DPE the caller requested
118
+ */
119
+ export function logWinccoaError(context, e, fallbackDpe) {
120
+ const described = describeWinccoaError(e, fallbackDpe);
121
+ // WinccoaError messages already start with "<code>, "; do not repeat the code.
122
+ const hasCodePrefix = described.code !== undefined && described.message.trimStart().startsWith(`${described.code},`);
123
+ const codePrefix = described.code !== undefined && !hasCodePrefix ? `[${described.code}] ` : '';
124
+ const line = `${context}: ${codePrefix}${described.message}`;
125
+ if (described.code !== undefined && EXPECTED_NOT_FOUND_CODES.has(described.code)) {
126
+ log.warn(line);
127
+ return;
128
+ }
129
+ log.error(line);
130
+ if (e instanceof Error && e.stack)
131
+ log.debug(e.stack);
132
+ }
133
+ /** errorType per WinCC OA error code, for winccoaErrorResponse. */
134
+ const WINCCOA_ERROR_TYPES = {
135
+ 71: 'DP_NOT_EXIST',
136
+ 57: 'DP_TYPE_NOT_EXIST'
137
+ };
138
+ /**
139
+ * Build the uniform error envelope for a caught WinCC OA error:
140
+ * `{error, message, errorCode?, errorType?, details}`.
141
+ *
142
+ * @param prefix - Message prefix, e.g. "Failed to get type name for X"
143
+ * @param e - Caught error
144
+ * @param fallbackDpe - DPE the caller requested (fills empty details[].dpe)
145
+ */
146
+ export function winccoaErrorResponse(prefix, e, fallbackDpe) {
147
+ const described = describeWinccoaError(e, fallbackDpe);
148
+ const errorType = described.code !== undefined ? WINCCOA_ERROR_TYPES[described.code] : undefined;
149
+ return createErrorResponse(`${prefix}: ${described.message}`, {
150
+ errorCode: described.code,
151
+ ...(errorType ? { errorType } : {}),
152
+ details: described.details
153
+ });
24
154
  }
25
155
  /**
26
156
  * Recursively add description and unit information to datapoint children
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH;;;;;GAKG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CAAC;IACf,CAAC;IAED,uDAAuD;IACvD,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,mBAAmB;IACnB,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACvE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAAC,IAAc;IAC5D,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,6BAA6B,CAAC,GAAG,CAAC,EAAE,CAAC;YACxC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC;QAC3B,OAAO;KACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * WinCC OA project path resolution.
3
+ *
4
+ * Tools that write into the project (custom dashboard icons under
5
+ * <proj>/data/WebUI/icons) need the project directory. It used to be derived by
6
+ * walking a fixed number of directories up from the compiled module, which is
7
+ * only right for one layout: a git clone inside <proj>/javascript/. It is wrong
8
+ * for the flat npm/zip layout (<proj>/javascript/mcpWinCCOA/...), for older zip
9
+ * layouts, and for symlinked development checkouts (Node resolves ESM modules
10
+ * through their real path), and it then pointed somewhere outside the project.
11
+ *
12
+ * The WinCC OA JavaScript manager knows the project path, so ask it first.
13
+ */
14
+ /** Where a resolved project path came from, for logging. */
15
+ export type ProjectPathSource = 'WINCCOA_PROJ_PATH' | 'winccoa.getPaths()' | 'PVSS_II' | 'directory search' | 'none';
16
+ export interface ProjectPathResolution {
17
+ /** Absolute project directory, or undefined if none could be determined. */
18
+ path: string | undefined;
19
+ /** Which strategy produced the path. */
20
+ source: ProjectPathSource;
21
+ }
22
+ /**
23
+ * Directory search fallback: a WinCC OA project is the directory that contains
24
+ * config/config. Walk upward from `startDir`.
25
+ *
26
+ * @param startDir - Directory to start in
27
+ * @returns The project directory, or undefined if no marker is found
28
+ */
29
+ export declare function findProjectDirUpward(startDir: string): string | undefined;
30
+ /**
31
+ * Resolve the WinCC OA project path and report where it came from.
32
+ *
33
+ * Order:
34
+ * 1. WINCCOA_PROJ_PATH environment variable (explicit override)
35
+ * 2. winccoa.getPaths()[0] - the manager API; the project path is always first
36
+ * 3. PVSS_II environment variable (<proj>/config/config), set in the manager process
37
+ * 4. Upward search from this module for a directory containing config/config
38
+ *
39
+ * Never throws.
40
+ *
41
+ * @param winccoa - WinCC OA manager instance (optional)
42
+ * @param startDir - Start directory for the upward search (defaults to this module's directory)
43
+ */
44
+ export declare function resolveProjectPathWithSource(winccoa?: unknown, startDir?: string): ProjectPathResolution;
45
+ /**
46
+ * Resolve the WinCC OA project path (see resolveProjectPathWithSource for the order).
47
+ *
48
+ * @param winccoa - WinCC OA manager instance (optional)
49
+ * @returns Absolute project directory, or undefined
50
+ */
51
+ export declare function resolveProjectPath(winccoa?: unknown): string | undefined;
52
+ //# sourceMappingURL=projectPath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projectPath.d.ts","sourceRoot":"","sources":["../../src/utils/projectPath.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,4DAA4D;AAC5D,MAAM,MAAM,iBAAiB,GACzB,mBAAmB,GACnB,oBAAoB,GACpB,SAAS,GACT,kBAAkB,GAClB,MAAM,CAAC;AAEX,MAAM,WAAW,qBAAqB;IACpC,4EAA4E;IAC5E,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,wCAAwC;IACxC,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAKD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAazE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,CAAC,EAAE,OAAO,EACjB,QAAQ,CAAC,EAAE,MAAM,GAChB,qBAAqB,CAwCvB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAExE"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * WinCC OA project path resolution.
3
+ *
4
+ * Tools that write into the project (custom dashboard icons under
5
+ * <proj>/data/WebUI/icons) need the project directory. It used to be derived by
6
+ * walking a fixed number of directories up from the compiled module, which is
7
+ * only right for one layout: a git clone inside <proj>/javascript/. It is wrong
8
+ * for the flat npm/zip layout (<proj>/javascript/mcpWinCCOA/...), for older zip
9
+ * layouts, and for symlinked development checkouts (Node resolves ESM modules
10
+ * through their real path), and it then pointed somewhere outside the project.
11
+ *
12
+ * The WinCC OA JavaScript manager knows the project path, so ask it first.
13
+ */
14
+ import { existsSync } from 'fs';
15
+ import { dirname, join, resolve } from 'path';
16
+ import { fileURLToPath } from 'url';
17
+ /** Upper bound for the upward directory search. */
18
+ const MAX_SEARCH_LEVELS = 10;
19
+ /**
20
+ * Directory search fallback: a WinCC OA project is the directory that contains
21
+ * config/config. Walk upward from `startDir`.
22
+ *
23
+ * @param startDir - Directory to start in
24
+ * @returns The project directory, or undefined if no marker is found
25
+ */
26
+ export function findProjectDirUpward(startDir) {
27
+ let current = resolve(startDir);
28
+ for (let i = 0; i <= MAX_SEARCH_LEVELS; i++) {
29
+ if (existsSync(join(current, 'config', 'config'))) {
30
+ return current;
31
+ }
32
+ const parent = dirname(current);
33
+ if (parent === current) {
34
+ break;
35
+ }
36
+ current = parent;
37
+ }
38
+ return undefined;
39
+ }
40
+ /**
41
+ * Resolve the WinCC OA project path and report where it came from.
42
+ *
43
+ * Order:
44
+ * 1. WINCCOA_PROJ_PATH environment variable (explicit override)
45
+ * 2. winccoa.getPaths()[0] - the manager API; the project path is always first
46
+ * 3. PVSS_II environment variable (<proj>/config/config), set in the manager process
47
+ * 4. Upward search from this module for a directory containing config/config
48
+ *
49
+ * Never throws.
50
+ *
51
+ * @param winccoa - WinCC OA manager instance (optional)
52
+ * @param startDir - Start directory for the upward search (defaults to this module's directory)
53
+ */
54
+ export function resolveProjectPathWithSource(winccoa, startDir) {
55
+ const fromEnv = process.env.WINCCOA_PROJ_PATH?.trim();
56
+ if (fromEnv) {
57
+ return { path: resolve(fromEnv), source: 'WINCCOA_PROJ_PATH' };
58
+ }
59
+ const getPaths = winccoa?.getPaths;
60
+ if (typeof getPaths === 'function') {
61
+ try {
62
+ const paths = getPaths.call(winccoa);
63
+ const first = paths?.[0];
64
+ if (typeof first === 'string' && first.trim().length > 0) {
65
+ return { path: first.trim(), source: 'winccoa.getPaths()' };
66
+ }
67
+ }
68
+ catch {
69
+ // Fall through to the next strategy.
70
+ }
71
+ }
72
+ const pvssII = process.env.PVSS_II?.trim();
73
+ if (pvssII) {
74
+ return { path: dirname(dirname(pvssII)), source: 'PVSS_II' };
75
+ }
76
+ let searchStart = startDir;
77
+ if (!searchStart) {
78
+ try {
79
+ searchStart = dirname(fileURLToPath(import.meta.url));
80
+ }
81
+ catch {
82
+ searchStart = undefined;
83
+ }
84
+ }
85
+ if (searchStart) {
86
+ const found = findProjectDirUpward(searchStart);
87
+ if (found) {
88
+ return { path: found, source: 'directory search' };
89
+ }
90
+ }
91
+ return { path: undefined, source: 'none' };
92
+ }
93
+ /**
94
+ * Resolve the WinCC OA project path (see resolveProjectPathWithSource for the order).
95
+ *
96
+ * @param winccoa - WinCC OA manager instance (optional)
97
+ * @returns Absolute project directory, or undefined
98
+ */
99
+ export function resolveProjectPath(winccoa) {
100
+ return resolveProjectPathWithSource(winccoa).path;
101
+ }
102
+ //# sourceMappingURL=projectPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projectPath.js","sourceRoot":"","sources":["../../src/utils/projectPath.ts"],"names":[],"mappings":"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,OAAO,CAAC,CAAC,IAAI,CAAC;AACpD,CAAC"}
package/manifest.cjs ADDED
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Builds the runtime manifest (package.json) that is written next to the flat
5
+ * server files, for both delivery paths:
6
+ *
7
+ * - npm install: postinstall.cjs writes it into the install directory
8
+ * - SIOS archive: zip.mjs writes it into the archive
9
+ *
10
+ * CommonJS so that postinstall.cjs can require() it and zip.mjs can load it via
11
+ * createRequire(). It is listed in the package.json "files" field because
12
+ * postinstall.cjs needs it inside the published npm package.
13
+ *
14
+ * The manifest exists only so that `npm install` in the flat directory pulls the
15
+ * runtime dependencies. Everything that refers to the repository/npm layout is
16
+ * removed:
17
+ *
18
+ * - scripts.postinstall: would run postinstall.cjs, which is not copied into
19
+ * the flat directory (and has nothing to do there).
20
+ * - build/test/release scripts: they need src/ and the dev toolchain.
21
+ * start / start:http are rewritten to the flat paths.
22
+ * - devDependencies: a finished build is shipped; keeps the installed set equal
23
+ * to what sbom.json (--omit dev) describes.
24
+ * - bin / files: describe the npm package layout (./build/...), not the flat one.
25
+ *
26
+ * "private": true guards against an accidental `npm publish` from the install
27
+ * directory. The published package.json itself is not affected.
28
+ *
29
+ * @param {Record<string, unknown>} source the package's own package.json
30
+ * @returns {Record<string, unknown>} the sanitized manifest
31
+ */
32
+ function buildRuntimeManifest(source) {
33
+ const {
34
+ scripts: _scripts,
35
+ devDependencies: _devDependencies,
36
+ bin: _bin,
37
+ files: _files,
38
+ ...rest
39
+ } = source;
40
+ return {
41
+ ...rest,
42
+ private: true,
43
+ scripts: {
44
+ start: 'node index_stdio.js',
45
+ 'start:http': 'node index_http.js'
46
+ }
47
+ };
48
+ }
49
+
50
+ module.exports = { buildRuntimeManifest };