@synapticon/motion-master-client 2.3.0-beta.0 → 6.0.0-alpha.100

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 (72) hide show
  1. package/LICENSE +21 -0
  2. package/dist/api-error.d.ts +25 -0
  3. package/dist/api-error.js +52 -0
  4. package/dist/client.d.ts +20 -0
  5. package/dist/client.js +37 -0
  6. package/dist/constants.d.ts +2 -0
  7. package/dist/constants.js +8 -0
  8. package/dist/eni.d.ts +197 -0
  9. package/dist/eni.js +61 -0
  10. package/dist/generated/Api.d.ts +1886 -0
  11. package/dist/generated/Api.js +1293 -0
  12. package/dist/generated/data-contracts.d.ts +2282 -0
  13. package/dist/generated/data-contracts.js +12 -0
  14. package/dist/generated/http-client.d.ts +60 -0
  15. package/dist/generated/http-client.js +171 -0
  16. package/dist/hex.d.ts +2 -0
  17. package/dist/hex.js +20 -0
  18. package/dist/index.d.ts +13 -7
  19. package/dist/index.js +20 -22
  20. package/dist/lan.d.ts +4 -0
  21. package/dist/lan.js +59 -0
  22. package/dist/mmpd.d.ts +53 -0
  23. package/dist/mmpd.js +322 -0
  24. package/dist/sdo.d.ts +17 -0
  25. package/dist/sdo.js +219 -0
  26. package/dist/web-socket-connection.d.ts +70 -0
  27. package/dist/web-socket-connection.js +237 -0
  28. package/dist/wire-time.d.ts +2 -0
  29. package/dist/wire-time.js +18 -0
  30. package/package.json +29 -35
  31. package/.vscode/launch.json +0 -23
  32. package/README.md +0 -118
  33. package/box.config.json +0 -7
  34. package/dist/index.d.ts.map +0 -1
  35. package/dist/index.js.map +0 -1
  36. package/dist/motion-master-client-web-socket-connection.d.ts +0 -43
  37. package/dist/motion-master-client-web-socket-connection.d.ts.map +0 -1
  38. package/dist/motion-master-client-web-socket-connection.js +0 -91
  39. package/dist/motion-master-client-web-socket-connection.js.map +0 -1
  40. package/dist/motion-master-client.d.ts +0 -105
  41. package/dist/motion-master-client.d.ts.map +0 -1
  42. package/dist/motion-master-client.js +0 -348
  43. package/dist/motion-master-client.js.map +0 -1
  44. package/dist/motion-master-notification-subscribe-data.d.ts +0 -8
  45. package/dist/motion-master-notification-subscribe-data.d.ts.map +0 -1
  46. package/dist/motion-master-notification-subscribe-data.js +0 -3
  47. package/dist/motion-master-notification-subscribe-data.js.map +0 -1
  48. package/dist/motion-master-notification-web-socket-connection.d.ts +0 -56
  49. package/dist/motion-master-notification-web-socket-connection.d.ts.map +0 -1
  50. package/dist/motion-master-notification-web-socket-connection.js +0 -115
  51. package/dist/motion-master-notification-web-socket-connection.js.map +0 -1
  52. package/dist/motion-master-notification.d.ts +0 -31
  53. package/dist/motion-master-notification.d.ts.map +0 -1
  54. package/dist/motion-master-notification.js +0 -44
  55. package/dist/motion-master-notification.js.map +0 -1
  56. package/dist/util.d.ts +0 -16
  57. package/dist/util.d.ts.map +0 -1
  58. package/dist/util.js +0 -24
  59. package/dist/util.js.map +0 -1
  60. package/licenses.format.json +0 -4
  61. package/motion-master-client.config.json +0 -7
  62. package/smm_data_dic.json +0 -1213
  63. package/src/index.ts +0 -7
  64. package/src/motion-master-client-web-socket-connection.ts +0 -104
  65. package/src/motion-master-client.ts +0 -468
  66. package/src/motion-master-notification-subscribe-data.ts +0 -7
  67. package/src/motion-master-notification-web-socket-connection.ts +0 -143
  68. package/src/motion-master-notification.ts +0 -51
  69. package/src/util.ts +0 -22
  70. package/test.sh +0 -122
  71. package/tsconfig.json +0 -63
  72. package/tslint.json +0 -118
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Synapticon GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The one place that knows how a failed request from the generated client is shaped.
3
+ *
4
+ * `swagger-typescript-api`'s client does not throw an `Error`. On a non-2xx it throws its own
5
+ * `HttpResponse` object, having parsed the response body into that object's `error` property — and
6
+ * Motion Master's own error body is `{ "error": "<message>" }`. So the message a user should see
7
+ * sits at `err.error.error`, two levels down, and reading one level yields the string
8
+ * `"[object Object]"`.
9
+ *
10
+ * That is not a shape any caller should have to know, which is the whole reason this lives here: the
11
+ * wrapping belongs to the generated client, the generated client belongs to this package, so the
12
+ * unwrapping belongs here too rather than being rediscovered in every page that catches a request.
13
+ */
14
+ /**
15
+ * The human-readable reason a request failed.
16
+ *
17
+ * Tries, in order: the server's own message (`{ error }`, at either nesting level), the HTTP status,
18
+ * a thrown `Error`'s message, and finally `fallback`. The server message comes first because it is
19
+ * the only one that says anything specific — Motion Master's node layer writes these, and they name
20
+ * the object, the state, or the grammar that was wrong.
21
+ *
22
+ * @param err Whatever was caught.
23
+ * @param fallback Returned when nothing usable can be found.
24
+ */
25
+ export declare function apiErrorMessage(err: unknown, fallback?: string): string;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The one place that knows how a failed request from the generated client is shaped.
3
+ *
4
+ * `swagger-typescript-api`'s client does not throw an `Error`. On a non-2xx it throws its own
5
+ * `HttpResponse` object, having parsed the response body into that object's `error` property — and
6
+ * Motion Master's own error body is `{ "error": "<message>" }`. So the message a user should see
7
+ * sits at `err.error.error`, two levels down, and reading one level yields the string
8
+ * `"[object Object]"`.
9
+ *
10
+ * That is not a shape any caller should have to know, which is the whole reason this lives here: the
11
+ * wrapping belongs to the generated client, the generated client belongs to this package, so the
12
+ * unwrapping belongs here too rather than being rediscovered in every page that catches a request.
13
+ */
14
+ /**
15
+ * The human-readable reason a request failed.
16
+ *
17
+ * Tries, in order: the server's own message (`{ error }`, at either nesting level), the HTTP status,
18
+ * a thrown `Error`'s message, and finally `fallback`. The server message comes first because it is
19
+ * the only one that says anything specific — Motion Master's node layer writes these, and they name
20
+ * the object, the state, or the grammar that was wrong.
21
+ *
22
+ * @param err Whatever was caught.
23
+ * @param fallback Returned when nothing usable can be found.
24
+ */
25
+ export function apiErrorMessage(err, fallback = 'Unknown error') {
26
+ if (typeof err === 'object' && err !== null) {
27
+ const candidate = err;
28
+ // The generated client's HttpResponse: the parsed body sits in `error`.
29
+ if (typeof candidate.error === 'object' && candidate.error !== null) {
30
+ const body = candidate.error;
31
+ if (typeof body.error === 'string' && body.error !== '') {
32
+ return body.error;
33
+ }
34
+ }
35
+ // A body handed over directly, or an already-unwrapped one.
36
+ if (typeof candidate.error === 'string' && candidate.error !== '') {
37
+ return candidate.error;
38
+ }
39
+ // No body to read — a network failure, or a response with no JSON. The status is what is left,
40
+ // and it is still more use than a generic sentence.
41
+ if (typeof candidate.status === 'number') {
42
+ const statusText = typeof candidate.statusText === 'string' && candidate.statusText !== ''
43
+ ? ` ${candidate.statusText}`
44
+ : '';
45
+ return `HTTP ${candidate.status}${statusText}`;
46
+ }
47
+ }
48
+ if (err instanceof Error && err.message !== '') {
49
+ return err.message;
50
+ }
51
+ return fallback;
52
+ }
@@ -0,0 +1,20 @@
1
+ import { Api } from './generated/Api.js';
2
+ import type { ApiConfig } from './generated/http-client.js';
3
+ import { type MmpdFile } from './mmpd.js';
4
+ import { WebSocketConnection, type WebSocketConstructor } from './web-socket-connection.js';
5
+ export interface MotionMasterClientOptions {
6
+ baseUrl?: string;
7
+ wsUrl?: string;
8
+ WebSocket?: WebSocketConstructor;
9
+ webSocketOptions?: unknown;
10
+ customFetch?: ApiConfig['customFetch'];
11
+ }
12
+ export declare class MotionMasterClient {
13
+ readonly api: Api;
14
+ readonly ws: WebSocketConnection;
15
+ private readonly httpBaseUrl;
16
+ private readonly customFetch?;
17
+ constructor(options?: MotionMasterClientOptions);
18
+ fetchProcessDataDump(signal?: AbortSignal): Promise<MmpdFile>;
19
+ close(): void;
20
+ }
package/dist/client.js ADDED
@@ -0,0 +1,37 @@
1
+ // The MotionMasterClient facade: a single connection object that composes the generated HTTP API
2
+ // (`client.api.*`, flat — e.g. `client.api.getVersion()`) with the WebSocket connection
3
+ // (`client.ws`). It is a *connection, not a model*: it holds no mutable device/parameter/AL state
4
+ // — the HTTP API and the monitoring stream are the source of truth. Isomorphic: pass `WebSocket`
5
+ // (and `customFetch`) to run under Node; both default to the platform globals in the browser.
6
+ import { Api } from './generated/Api.js';
7
+ import { API_BASE_URL, WS_URL } from './constants.js';
8
+ import { fetchProcessDataDump } from './mmpd.js';
9
+ import { WebSocketConnection } from './web-socket-connection.js';
10
+ export class MotionMasterClient {
11
+ /// The generated HTTP API client. Flat method surface: `client.api.getVersion()`,
12
+ /// `client.api.scan()`, `client.api.sdoUpload(...)`, ...
13
+ api;
14
+ /// The WebSocket connection: `client.ws.subscribe(topic, cb)`,
15
+ /// `client.ws.onNotification(cb)`, `client.ws.onProgress(cb)`. Connects lazily.
16
+ ws;
17
+ httpBaseUrl;
18
+ customFetch;
19
+ constructor(options = {}) {
20
+ this.httpBaseUrl = options.baseUrl ?? API_BASE_URL;
21
+ this.customFetch = options.customFetch;
22
+ this.api = new Api({ baseUrl: this.httpBaseUrl, customFetch: options.customFetch });
23
+ this.ws = new WebSocketConnection({
24
+ url: options.wsUrl ?? WS_URL,
25
+ WebSocket: options.WebSocket,
26
+ protocolsOrOptions: options.webSocketOptions,
27
+ });
28
+ }
29
+ /// Fetches and parses the live recorder dump (`GET /api/process-data/dump`) as an `MmpdFile`.
30
+ fetchProcessDataDump(signal) {
31
+ return fetchProcessDataDump(this.httpBaseUrl, { fetch: this.customFetch, signal });
32
+ }
33
+ /// Closes the WebSocket connection (and cancels reconnection). The HTTP API needs no teardown.
34
+ close() {
35
+ this.ws.close();
36
+ }
37
+ }
@@ -0,0 +1,2 @@
1
+ export declare const API_BASE_URL = "https://local.motion-master.synapticon.com:61447";
2
+ export declare const WS_URL = "wss://local.motion-master.synapticon.com:62281";
@@ -0,0 +1,8 @@
1
+ // Default endpoints for a Motion Master instance running on the same machine as the client. The
2
+ // bundled Let's Encrypt cert is for `local.motion-master.synapticon.com`, which resolves to
3
+ // 127.0.0.1, so these work out of the box for a localhost install. Override both via
4
+ // `MotionMasterClient` options for a remote/LAN deployment.
5
+ export const API_BASE_URL = 'https://local.motion-master.synapticon.com:61447';
6
+ // The WebSocket connection runs on its own port/loop (separate from the HTTP API) so a slow HTTP
7
+ // request can never stall the monitoring/notification stream.
8
+ export const WS_URL = 'wss://local.motion-master.synapticon.com:62281';
package/dist/eni.d.ts ADDED
@@ -0,0 +1,197 @@
1
+ export interface EniExport {
2
+ xml: string;
3
+ warnings: number;
4
+ }
5
+ export declare function fetchEni(baseUrl: string, options?: {
6
+ fetch?: typeof fetch;
7
+ signal?: AbortSignal;
8
+ }): Promise<EniExport>;
9
+ export interface EniBytes {
10
+ hex: string;
11
+ bytes: number;
12
+ }
13
+ export interface EniRegisterAnnotation {
14
+ name: string;
15
+ description: string;
16
+ instance?: number;
17
+ decoded?: Record<string, number | boolean | string>;
18
+ requestsState?: string;
19
+ waitsForState?: string;
20
+ }
21
+ export interface EniInitCmd {
22
+ transitions?: string[];
23
+ states?: string[];
24
+ inputOffs?: number;
25
+ outputOffs?: number;
26
+ cmd: number;
27
+ cmdName: string;
28
+ beforeSlave?: boolean;
29
+ comment?: string;
30
+ requires?: string;
31
+ adp?: number;
32
+ ado?: number;
33
+ addr?: number;
34
+ data?: EniBytes;
35
+ dataLength?: number;
36
+ cnt?: number;
37
+ retries?: number;
38
+ timeoutMs?: number;
39
+ validate?: {
40
+ data: EniBytes;
41
+ dataMask?: EniBytes;
42
+ timeoutMs: number;
43
+ };
44
+ register?: EniRegisterAnnotation;
45
+ }
46
+ export interface EniCoeCmd {
47
+ transitions: string[];
48
+ timeoutMs: number;
49
+ ccs: number;
50
+ ccsName: 'download' | 'upload';
51
+ index: number;
52
+ subindex: number;
53
+ comment?: string;
54
+ data?: EniBytes;
55
+ disabled?: boolean;
56
+ }
57
+ export interface EniPdoEntry {
58
+ index: number;
59
+ subindex: number;
60
+ bitLen: number;
61
+ name?: string;
62
+ dataType?: string;
63
+ comment?: string;
64
+ }
65
+ export interface EniPdo {
66
+ index: number;
67
+ name: string;
68
+ syncManager?: number;
69
+ fixed?: boolean;
70
+ mandatory?: boolean;
71
+ entries: EniPdoEntry[];
72
+ }
73
+ export interface EniSyncManager {
74
+ index: number;
75
+ type: string;
76
+ startAddress: number;
77
+ controlByte: number;
78
+ enable: boolean;
79
+ minSize?: number;
80
+ maxSize?: number;
81
+ defaultSize?: number;
82
+ watchdog?: number;
83
+ }
84
+ export interface EniMailboxWindow {
85
+ start: number;
86
+ length: number;
87
+ pollTime?: number;
88
+ statusBitAddr?: number;
89
+ }
90
+ export interface EniSlave {
91
+ info: {
92
+ name: string;
93
+ physAddr: number;
94
+ autoIncAddr: number;
95
+ physics: string;
96
+ vendorId: number;
97
+ productCode: number;
98
+ revisionNo: number;
99
+ serialNo: number;
100
+ };
101
+ processData?: {
102
+ send?: {
103
+ bitStart: number;
104
+ bitLength: number;
105
+ };
106
+ recv?: {
107
+ bitStart: number;
108
+ bitLength: number;
109
+ };
110
+ syncManagers: EniSyncManager[];
111
+ rxPdos?: EniPdo[];
112
+ txPdos?: EniPdo[];
113
+ };
114
+ mailbox?: {
115
+ send: EniMailboxWindow;
116
+ recv: EniMailboxWindow;
117
+ bootstrap?: {
118
+ send: EniMailboxWindow;
119
+ recv: EniMailboxWindow;
120
+ };
121
+ protocols: string[];
122
+ coeInitCmds: EniCoeCmd[];
123
+ };
124
+ initCmds: EniInitCmd[];
125
+ previousPorts?: {
126
+ port: string;
127
+ selected: boolean;
128
+ physAddr?: number;
129
+ deviceId?: number;
130
+ }[];
131
+ dc?: {
132
+ potentialReferenceClock?: boolean;
133
+ referenceClock?: boolean;
134
+ cycleTime0Ns?: number;
135
+ cycleTime1Ns?: number;
136
+ shiftTimeNs?: number;
137
+ };
138
+ }
139
+ export interface EniVariable {
140
+ name: string;
141
+ bitSize: number;
142
+ bitOffs: number;
143
+ comment?: string;
144
+ dataType?: string;
145
+ }
146
+ export interface EniNetwork {
147
+ master: {
148
+ name: string;
149
+ destination: string;
150
+ source: string;
151
+ etherType?: number;
152
+ mailboxStates?: {
153
+ startAddr: number;
154
+ count: number;
155
+ };
156
+ eoe?: {
157
+ maxPorts: number;
158
+ maxFrames: number;
159
+ maxMacs: number;
160
+ };
161
+ initCmds: EniInitCmd[];
162
+ };
163
+ slaves: EniSlave[];
164
+ cyclic?: {
165
+ comment?: string;
166
+ taskId?: string;
167
+ cycleTimeUs?: number;
168
+ priority?: number;
169
+ frames: {
170
+ comment?: string;
171
+ cmds: EniInitCmd[];
172
+ }[];
173
+ };
174
+ processImage?: {
175
+ inputs?: {
176
+ byteSize: number;
177
+ variables: EniVariable[];
178
+ };
179
+ outputs?: {
180
+ byteSize: number;
181
+ variables: EniVariable[];
182
+ };
183
+ };
184
+ }
185
+ export interface EniParseResult {
186
+ network: EniNetwork;
187
+ warnings: string[];
188
+ summary: {
189
+ devices: number;
190
+ datagrams: number;
191
+ coeTransfers: number;
192
+ };
193
+ }
194
+ export declare function parseEni(baseUrl: string, xml: string, options?: {
195
+ fetch?: typeof fetch;
196
+ signal?: AbortSignal;
197
+ }): Promise<EniParseResult>;
package/dist/eni.js ADDED
@@ -0,0 +1,61 @@
1
+ // EtherCAT Network Information (ENI) export.
2
+ //
3
+ // The generated client types `GET /api/eni` as a `File`, which is what swagger-typescript-api makes
4
+ // of a binary response. An ENI is text, and what a caller wants is the document plus the warning
5
+ // count that came with it, so this wraps the call.
6
+ /// Exports the bus as an ENI document (`GET /api/eni`). `baseUrl` is the HTTP API origin (e.g.
7
+ /// `https://host:61447`). Throws on a non-OK response, with the response body's `error` message
8
+ /// when there is one — a bus that has not reached SAFE-OP or OP answers 409, because before that
9
+ /// there is no mapping to describe. Pass `fetch` to inject an implementation (Node, request
10
+ /// logging).
11
+ export async function fetchEni(baseUrl, options = {}) {
12
+ const doFetch = options.fetch ?? fetch;
13
+ const res = await doFetch(`${baseUrl.replace(/\/+$/, '')}/api/eni`, {
14
+ headers: { Accept: 'application/xml' },
15
+ signal: options.signal,
16
+ });
17
+ if (!res.ok) {
18
+ let message = `HTTP ${res.status}`;
19
+ try {
20
+ const body = (await res.json());
21
+ if (body?.error) {
22
+ message = body.error;
23
+ }
24
+ }
25
+ catch {
26
+ // Non-JSON error body — keep the status message.
27
+ }
28
+ throw new Error(message);
29
+ }
30
+ const warnings = Number.parseInt(res.headers.get('X-Eni-Warnings') ?? '0', 10);
31
+ return {
32
+ xml: await res.text(),
33
+ warnings: Number.isFinite(warnings) ? warnings : 0,
34
+ };
35
+ }
36
+ /// Parses an ENI document (`POST /api/eni/parse`). `baseUrl` is the HTTP API origin. The document
37
+ /// need not have come from this server — reading one another tool wrote is the point. Throws on a
38
+ /// non-OK response, with the server's `error` message when there is one.
39
+ export async function parseEni(baseUrl, xml, options = {}) {
40
+ const doFetch = options.fetch ?? fetch;
41
+ const res = await doFetch(`${baseUrl.replace(/\/+$/, '')}/api/eni/parse`, {
42
+ method: 'POST',
43
+ headers: { 'Content-Type': 'application/xml' },
44
+ body: xml,
45
+ signal: options.signal,
46
+ });
47
+ if (!res.ok) {
48
+ let message = `HTTP ${res.status}`;
49
+ try {
50
+ const body = (await res.json());
51
+ if (body?.error) {
52
+ message = body.error;
53
+ }
54
+ }
55
+ catch {
56
+ // Non-JSON error body — keep the status message.
57
+ }
58
+ throw new Error(message);
59
+ }
60
+ return (await res.json());
61
+ }