iobroker.unraid 0.4.0 → 0.5.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.
- package/README.md +26 -0
- package/admin/build/index.js +32 -32
- package/admin/build/index.js.map +3 -3
- package/build/apollo-client.d.ts +40 -0
- package/build/apollo-client.d.ts.map +1 -0
- package/build/apollo-client.js +196 -0
- package/build/apollo-client.js.map +1 -0
- package/build/main.js +579 -17
- package/build/main.js.map +1 -1
- package/build/shared/unraid-domains.d.ts +1 -1
- package/build/shared/unraid-domains.d.ts.map +1 -1
- package/build/shared/unraid-domains.js +383 -1
- package/build/shared/unraid-domains.js.map +1 -1
- package/build/subscription-manager.d.ts +78 -0
- package/build/subscription-manager.d.ts.map +1 -0
- package/build/subscription-manager.js +368 -0
- package/build/subscription-manager.js.map +1 -0
- package/io-package.json +29 -28
- package/package.json +7 -2
- package/build/graphql-client.d.ts +0 -47
- package/build/graphql-client.d.ts.map +0 -1
- package/build/graphql-client.js +0 -145
- package/build/graphql-client.js.map +0 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface ApolloClientOptions {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
apiToken: string;
|
|
4
|
+
allowSelfSigned?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class UnraidApolloClient {
|
|
7
|
+
private client;
|
|
8
|
+
private wsClient;
|
|
9
|
+
private readonly baseUrl;
|
|
10
|
+
private readonly apiToken;
|
|
11
|
+
constructor(options: ApolloClientOptions);
|
|
12
|
+
/**
|
|
13
|
+
* Execute a GraphQL query
|
|
14
|
+
*/
|
|
15
|
+
query<T = unknown>(query: string): Promise<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Execute a GraphQL mutation
|
|
18
|
+
*/
|
|
19
|
+
mutate<T = unknown>(mutation: string, variables?: Record<string, unknown>): Promise<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Subscribe to a GraphQL subscription
|
|
22
|
+
*/
|
|
23
|
+
subscribe<T = unknown>(subscription: string, variables?: Record<string, unknown>): import("zen-observable-ts", { with: { "resolution-mode": "import" } }).Observable<import("@apollo/client/core", { with: { "resolution-mode": "import" } }).InteropSubscribeResult<T>>;
|
|
24
|
+
/**
|
|
25
|
+
* Run an introspection query to discover available subscriptions
|
|
26
|
+
*/
|
|
27
|
+
introspectSubscriptions(): Promise<unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* Dispose the client and close connections
|
|
30
|
+
*/
|
|
31
|
+
dispose(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Check if WebSocket is connected
|
|
34
|
+
*/
|
|
35
|
+
isConnected(): boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare const METRICS_SUBSCRIPTION = "\n subscription MetricsSubscription {\n metrics {\n cpu {\n percentTotal\n }\n memory {\n percentTotal\n total\n used\n free\n }\n }\n }\n";
|
|
38
|
+
export declare const CPU_SUBSCRIPTION = "\n subscription CpuSubscription {\n cpu {\n percentTotal\n }\n }\n";
|
|
39
|
+
export declare const MEMORY_SUBSCRIPTION = "\n subscription MemorySubscription {\n memory {\n percentTotal\n total\n used\n free\n }\n }\n";
|
|
40
|
+
//# sourceMappingURL=apollo-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo-client.d.ts","sourceRoot":"","sources":["../src/apollo-client.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,mBAAmB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,OAAO,EAAE,mBAAmB;IA+ExC;;OAEG;IACG,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAOnD;;OAEG;IACG,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAQ5F;;OAEG;IACH,SAAS,CAAC,CAAC,GAAG,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAOhF;;OAEG;IACG,uBAAuB,IAAI,OAAO,CAAC,OAAO,CAAC;IAmCjD;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAK9B;;OAEG;IACH,WAAW,IAAI,OAAO;CAIzB;AAGD,eAAO,MAAM,oBAAoB,0RAchC,CAAC;AAEF,eAAO,MAAM,gBAAgB,sGAM5B,CAAC;AAEF,eAAO,MAAM,mBAAmB,mKAS/B,CAAC"}
|
|
@@ -0,0 +1,196 @@
|
|
|
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.MEMORY_SUBSCRIPTION = exports.CPU_SUBSCRIPTION = exports.METRICS_SUBSCRIPTION = exports.UnraidApolloClient = void 0;
|
|
7
|
+
const core_1 = require("@apollo/client/core");
|
|
8
|
+
const subscriptions_1 = require("@apollo/client/link/subscriptions");
|
|
9
|
+
const utilities_1 = require("@apollo/client/utilities");
|
|
10
|
+
const graphql_ws_1 = require("graphql-ws");
|
|
11
|
+
const ws_1 = __importDefault(require("ws"));
|
|
12
|
+
const undici_1 = require("undici");
|
|
13
|
+
class UnraidApolloClient {
|
|
14
|
+
client;
|
|
15
|
+
wsClient;
|
|
16
|
+
baseUrl;
|
|
17
|
+
apiToken;
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.baseUrl = options.baseUrl.replace(/\/$/, '');
|
|
20
|
+
this.apiToken = options.apiToken;
|
|
21
|
+
// Configure undici for self-signed certificates if needed
|
|
22
|
+
if (options.allowSelfSigned && this.baseUrl.startsWith('https://')) {
|
|
23
|
+
(0, undici_1.setGlobalDispatcher)(new undici_1.Agent({
|
|
24
|
+
connect: {
|
|
25
|
+
rejectUnauthorized: false
|
|
26
|
+
}
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
// Create WebSocket client for subscriptions
|
|
30
|
+
const wsUrl = this.baseUrl.replace(/^http/, 'ws') + '/graphql';
|
|
31
|
+
// Create a custom WebSocket class that includes our options
|
|
32
|
+
class CustomWebSocket extends ws_1.default {
|
|
33
|
+
constructor(url, protocols) {
|
|
34
|
+
const wsOptions = {
|
|
35
|
+
rejectUnauthorized: !options.allowSelfSigned,
|
|
36
|
+
headers: {
|
|
37
|
+
'x-api-key': options.apiToken
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
super(url, protocols, wsOptions);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
this.wsClient = (0, graphql_ws_1.createClient)({
|
|
44
|
+
url: wsUrl,
|
|
45
|
+
webSocketImpl: CustomWebSocket,
|
|
46
|
+
connectionParams: {
|
|
47
|
+
'x-api-key': this.apiToken
|
|
48
|
+
},
|
|
49
|
+
retryAttempts: 5,
|
|
50
|
+
shouldRetry: () => true,
|
|
51
|
+
keepAlive: 30000,
|
|
52
|
+
});
|
|
53
|
+
// Create HTTP link for queries and mutations
|
|
54
|
+
const httpLink = new core_1.HttpLink({
|
|
55
|
+
uri: `${this.baseUrl}/graphql`,
|
|
56
|
+
headers: {
|
|
57
|
+
'x-api-key': this.apiToken
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
// Create WebSocket link for subscriptions
|
|
61
|
+
const wsLink = new subscriptions_1.GraphQLWsLink(this.wsClient);
|
|
62
|
+
// Split link based on operation type
|
|
63
|
+
const splitLink = (0, core_1.split)(({ query }) => {
|
|
64
|
+
const definition = (0, utilities_1.getMainDefinition)(query);
|
|
65
|
+
return (definition.kind === 'OperationDefinition' &&
|
|
66
|
+
definition.operation === 'subscription');
|
|
67
|
+
}, wsLink, httpLink);
|
|
68
|
+
// Create Apollo Client
|
|
69
|
+
this.client = new core_1.ApolloClient({
|
|
70
|
+
link: splitLink,
|
|
71
|
+
cache: new core_1.InMemoryCache(),
|
|
72
|
+
defaultOptions: {
|
|
73
|
+
watchQuery: {
|
|
74
|
+
fetchPolicy: 'no-cache'
|
|
75
|
+
},
|
|
76
|
+
query: {
|
|
77
|
+
fetchPolicy: 'no-cache'
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Execute a GraphQL query
|
|
84
|
+
*/
|
|
85
|
+
async query(query) {
|
|
86
|
+
const result = await this.client.query({
|
|
87
|
+
query: (0, core_1.gql)(query)
|
|
88
|
+
});
|
|
89
|
+
return result.data;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Execute a GraphQL mutation
|
|
93
|
+
*/
|
|
94
|
+
async mutate(mutation, variables) {
|
|
95
|
+
const result = await this.client.mutate({
|
|
96
|
+
mutation: (0, core_1.gql)(mutation),
|
|
97
|
+
variables
|
|
98
|
+
});
|
|
99
|
+
return result.data;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Subscribe to a GraphQL subscription
|
|
103
|
+
*/
|
|
104
|
+
subscribe(subscription, variables) {
|
|
105
|
+
return this.client.subscribe({
|
|
106
|
+
query: (0, core_1.gql)(subscription),
|
|
107
|
+
variables
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Run an introspection query to discover available subscriptions
|
|
112
|
+
*/
|
|
113
|
+
async introspectSubscriptions() {
|
|
114
|
+
const introspectionQuery = `
|
|
115
|
+
query IntrospectionQuery {
|
|
116
|
+
__schema {
|
|
117
|
+
subscriptionType {
|
|
118
|
+
name
|
|
119
|
+
fields {
|
|
120
|
+
name
|
|
121
|
+
description
|
|
122
|
+
args {
|
|
123
|
+
name
|
|
124
|
+
type {
|
|
125
|
+
name
|
|
126
|
+
kind
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
type {
|
|
130
|
+
name
|
|
131
|
+
kind
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
`;
|
|
138
|
+
try {
|
|
139
|
+
const result = await this.query(introspectionQuery);
|
|
140
|
+
return result?.__schema?.subscriptionType;
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
console.error('Failed to introspect subscriptions:', error);
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Dispose the client and close connections
|
|
149
|
+
*/
|
|
150
|
+
async dispose() {
|
|
151
|
+
this.client.stop();
|
|
152
|
+
await this.wsClient.dispose();
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Check if WebSocket is connected
|
|
156
|
+
*/
|
|
157
|
+
isConnected() {
|
|
158
|
+
// This is a simplified check - you might want to implement more sophisticated logic
|
|
159
|
+
return this.wsClient !== null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.UnraidApolloClient = UnraidApolloClient;
|
|
163
|
+
// Export commonly used GraphQL subscriptions for Unraid metrics
|
|
164
|
+
exports.METRICS_SUBSCRIPTION = `
|
|
165
|
+
subscription MetricsSubscription {
|
|
166
|
+
metrics {
|
|
167
|
+
cpu {
|
|
168
|
+
percentTotal
|
|
169
|
+
}
|
|
170
|
+
memory {
|
|
171
|
+
percentTotal
|
|
172
|
+
total
|
|
173
|
+
used
|
|
174
|
+
free
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
`;
|
|
179
|
+
exports.CPU_SUBSCRIPTION = `
|
|
180
|
+
subscription CpuSubscription {
|
|
181
|
+
cpu {
|
|
182
|
+
percentTotal
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
`;
|
|
186
|
+
exports.MEMORY_SUBSCRIPTION = `
|
|
187
|
+
subscription MemorySubscription {
|
|
188
|
+
memory {
|
|
189
|
+
percentTotal
|
|
190
|
+
total
|
|
191
|
+
used
|
|
192
|
+
free
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
`;
|
|
196
|
+
//# sourceMappingURL=apollo-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo-client.js","sourceRoot":"","sources":["../src/apollo-client.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAwF;AACxF,qEAAkE;AAClE,wDAA6D;AAC7D,2CAA0C;AAE1C,4CAA2B;AAC3B,mCAAoD;AAQpD,MAAa,kBAAkB;IACnB,MAAM,CAAwB;IAC9B,QAAQ,CAAkC;IACjC,OAAO,CAAS;IAChB,QAAQ,CAAS;IAElC,YAAY,OAA4B;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAEjC,0DAA0D;QAC1D,IAAI,OAAO,CAAC,eAAe,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YACjE,IAAA,4BAAmB,EAAC,IAAI,cAAK,CAAC;gBAC1B,OAAO,EAAE;oBACL,kBAAkB,EAAE,KAAK;iBAC5B;aACJ,CAAC,CAAC,CAAC;QACR,CAAC;QAED,4CAA4C;QAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,UAAU,CAAC;QAE/D,4DAA4D;QAC5D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