@ubercode/channelvault 0.1.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.
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Shared contracts for channelvault.
3
+ *
4
+ * The whole tool is organized around a single in-memory representation called
5
+ * the **canonical config**: a plain JSON object tree that mirrors Mirth's
6
+ * `serverConfiguration` document. Two adapters produce/consume it:
7
+ *
8
+ * - XML adapter (src/xml): backup .xml <-> canonical (dev / offline path)
9
+ * - Mirth client (src/client): live server <-> canonical (GET/PUT /server/configuration)
10
+ *
11
+ * The explode engine (src/explode) projects a canonical config onto a
12
+ * git-friendly directory tree and reverses it, with embedded JavaScript pulled
13
+ * out into sidecar `.js` files.
14
+ */
15
+ /** A JSON value as produced by the XML adapter or the live API. */
16
+ type Json = string | number | boolean | null | Json[] | {
17
+ [k: string]: Json;
18
+ };
19
+ /** A canonical config object (the `serverConfiguration` payload, unwrapped). */
20
+ type CanonicalConfig = {
21
+ [k: string]: Json;
22
+ };
23
+ /**
24
+ * Marker left in a `*.json` file in place of an extracted script/code leaf.
25
+ *
26
+ * During explode, a code-bearing string leaf (e.g. a transformer step's
27
+ * `script`, or a code template's `code`) is written to a sidecar `.js` file and
28
+ * the original string is replaced, in place, with `{ "@file": "<relpath>" }`.
29
+ * During implode, any object whose only key is `@file` is replaced by the text
30
+ * content of that file. The path is relative to the JSON file holding the marker.
31
+ */
32
+ interface FileRef {
33
+ '@file': string;
34
+ }
35
+ declare function isFileRef(v: unknown): v is FileRef;
36
+ /**
37
+ * The set of leaf element keys whose string values are treated as JavaScript
38
+ * and extracted to sidecar `.js` files. Detection is by key name plus a
39
+ * non-trivial-content check (see explode engine).
40
+ */
41
+ declare const CODE_KEYS: readonly ["script", "code"];
42
+ /**
43
+ * Channel-level script keys that live directly on a channel object (no nesting).
44
+ * Extracted into `<channel>/scripts/<name>.js`.
45
+ */
46
+ declare const CHANNEL_SCRIPT_KEYS: readonly ["preprocessingScript", "postprocessingScript", "deployScript", "undeployScript"];
47
+ interface XmlAdapter {
48
+ /** Parse a Mirth backup XML string into a canonical config. */
49
+ parse(xml: string): CanonicalConfig;
50
+ /** Serialize a canonical config back to Mirth backup XML. */
51
+ build(config: CanonicalConfig): string;
52
+ }
53
+ interface ExplodeOptions {
54
+ /** Absolute path to the working tree root. */
55
+ root: string;
56
+ }
57
+ interface ExplodeEngine {
58
+ /** Write a canonical config out as a directory tree under `root`. */
59
+ explode(config: CanonicalConfig, opts: ExplodeOptions): Promise<void>;
60
+ /** Read a directory tree under `root` back into a canonical config. */
61
+ implode(opts: ExplodeOptions): Promise<CanonicalConfig>;
62
+ }
63
+ interface ClientConfig {
64
+ host: string;
65
+ port: number;
66
+ username: string;
67
+ password: string;
68
+ /** default true */
69
+ https?: boolean;
70
+ /** default false; set true for self-signed certs */
71
+ disableTlsCheck?: boolean;
72
+ /**
73
+ * default false. Put the server's response body in error messages. A body
74
+ * can echo the credentials that were sent; it is decoded and has credential
75
+ * fields redacted, but the caller must still scrub known secret values.
76
+ */
77
+ includeResponseBodies?: boolean;
78
+ }
79
+ interface ApiError {
80
+ status: number;
81
+ statusText: string;
82
+ message: string;
83
+ body?: unknown;
84
+ }
85
+ interface ApiResponse<T> {
86
+ data: T | null;
87
+ error: ApiError | null;
88
+ }
89
+ interface MirthClient {
90
+ login(): Promise<void>;
91
+ logout(): Promise<void>;
92
+ isAuthenticated(): boolean;
93
+ /** GET /server/configuration -> canonical config (whole-server snapshot). */
94
+ getServerConfiguration(): Promise<CanonicalConfig>;
95
+ /** PUT /server/configuration <- canonical config. */
96
+ putServerConfiguration(config: CanonicalConfig): Promise<void>;
97
+ }
98
+
99
+ declare class XmlConfigAdapter implements XmlAdapter {
100
+ /** Parse a Mirth backup XML string into a canonical config. */
101
+ parse(xml: string): CanonicalConfig;
102
+ /** Serialize a canonical config back to Mirth backup XML. */
103
+ build(config: CanonicalConfig): string;
104
+ }
105
+
106
+ /**
107
+ * Explode / implode engine.
108
+ *
109
+ * Projects a canonical config (the unwrapped Mirth `serverConfiguration`) onto a
110
+ * git-friendly directory tree and reverses it losslessly. The exploded tree is a
111
+ * verbatim *projection* of the config split across files using two marker types:
112
+ *
113
+ * - `{ "@file": "<relpath>" }` replaces an extracted code/script STRING leaf;
114
+ * the string is written to a sidecar `.js` file (path relative to the JSON
115
+ * file holding the marker).
116
+ * - `{ "@ref": "<relpath>" }` replaces a whole sub-object split into its own
117
+ * `.json` file (path relative to the JSON file holding the marker).
118
+ *
119
+ * Invariant: `implode(explode(config))` deep-equals `config`.
120
+ */
121
+
122
+ declare function createExplodeEngine(): ExplodeEngine;
123
+
124
+ /** Optional flags accepted by `putServerConfiguration` (Mirth query params). */
125
+ interface PutServerConfigurationOptions {
126
+ /** Redeploy all channels after applying the configuration. */
127
+ deploy?: boolean;
128
+ /** Overwrite the global configuration map. */
129
+ overwriteConfigMap?: boolean;
130
+ }
131
+ /**
132
+ * The public client type. It satisfies the declared {@link MirthClient}
133
+ * contract but widens `putServerConfiguration` to accept the optional Mirth
134
+ * query-param flags. The widened signature is structurally assignable to the
135
+ * one-arg contract (the extra parameter is optional), so a `MirthClientExt`
136
+ * is a valid `MirthClient` wherever the bare contract is expected.
137
+ */
138
+ interface MirthClientExt extends MirthClient {
139
+ putServerConfiguration(config: CanonicalConfig, options?: PutServerConfigurationOptions): Promise<void>;
140
+ /** GET /server/id: the installation's ID, which a configuration restore does not change (verified on 4.5.2). */
141
+ getServerId(): Promise<string>;
142
+ /** GET /server/configuration as the server's own XML (the Administrator's Backup Config document). */
143
+ getServerConfigurationXml(): Promise<string>;
144
+ /** PUT /server/configuration from backup XML, as the Administrator's Restore Config does. */
145
+ putServerConfigurationXml(xml: string, options?: PutServerConfigurationOptions): Promise<void>;
146
+ /** GET /channels/{id}, unwrapped; includes the tag and dependency data the server configuration omits. */
147
+ getChannel(id: string): Promise<Record<string, unknown> | null>;
148
+ /** PUT /channels/{id}; creates the channel if the id is new. */
149
+ putChannel(channel: Record<string, unknown>): Promise<void>;
150
+ /** Release pooled connections so the process can exit promptly. */
151
+ close(): Promise<void>;
152
+ deleteChannel(id: string): Promise<void>;
153
+ /** PUT /codeTemplates/{id}; creates the template if the id is new. */
154
+ putCodeTemplate(template: Record<string, unknown>): Promise<void>;
155
+ deleteCodeTemplate(id: string): Promise<void>;
156
+ /** PUT /codeTemplateLibraries: replaces the whole list (membership and library settings). */
157
+ putCodeTemplateLibraries(libraries: Record<string, unknown>[]): Promise<void>;
158
+ /** PUT /server/globalScripts, from the `globalScripts` value of a server configuration. */
159
+ putGlobalScripts(globalScripts: unknown): Promise<void>;
160
+ /** POST /channels/{id}/_deploy; throws if deployment fails. */
161
+ deployChannel(id: string): Promise<void>;
162
+ /** Ids of the channels currently deployed (GET /channels/statuses). */
163
+ getDeployedChannelIds(): Promise<Set<string>>;
164
+ }
165
+ /**
166
+ * Factory for the live Mirth transport client.
167
+ */
168
+ declare function createMirthClient(config: ClientConfig): MirthClientExt;
169
+
170
+ export { type ApiError, type ApiResponse, CHANNEL_SCRIPT_KEYS, CODE_KEYS, type CanonicalConfig, type ClientConfig, type ExplodeEngine, type ExplodeOptions, type FileRef, type Json, type MirthClient, type MirthClientExt, type PutServerConfigurationOptions, type XmlAdapter, XmlConfigAdapter, createExplodeEngine, createMirthClient, isFileRef };