@whois-homebridge/homebridge-aranet4 0.2.0 → 0.2.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.
- package/dist/supabaseLogger.d.ts +12 -1
- package/dist/supabaseLogger.js +54 -4
- package/dist/supabaseLogger.js.map +1 -1
- package/package.json +1 -2
package/dist/supabaseLogger.d.ts
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface SupabaseConfig {
|
|
2
|
+
url: string;
|
|
3
|
+
key: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function insertRow(config: SupabaseConfig, table: string, row: Record<string, unknown>, log: {
|
|
6
|
+
warn(msg: string): void;
|
|
7
|
+
debug(msg: string): void;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
export declare function checkConnection(config: SupabaseConfig, table: string, log: {
|
|
10
|
+
info(msg: string): void;
|
|
11
|
+
warn(msg: string): void;
|
|
12
|
+
}): Promise<boolean>;
|
package/dist/supabaseLogger.js
CHANGED
|
@@ -1,7 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
exports.insertRow = insertRow;
|
|
4
|
+
exports.checkConnection = checkConnection;
|
|
5
|
+
function baseUrl(config) {
|
|
6
|
+
return config.url.replace(/\/$/, '');
|
|
7
|
+
}
|
|
8
|
+
const REQUEST_TIMEOUT_MS = 10_000;
|
|
9
|
+
async function insertRow(config, table, row, log) {
|
|
10
|
+
try {
|
|
11
|
+
const res = await fetch(`${baseUrl(config)}/rest/v1/${table}`, {
|
|
12
|
+
method: 'POST',
|
|
13
|
+
headers: {
|
|
14
|
+
'Content-Type': 'application/json',
|
|
15
|
+
'apikey': config.key,
|
|
16
|
+
'Authorization': `Bearer ${config.key}`,
|
|
17
|
+
'Prefer': 'return=minimal',
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify(row),
|
|
20
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
21
|
+
});
|
|
22
|
+
if (res.ok) {
|
|
23
|
+
log.debug(`[Supabase] Inserted row into ${table}`);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const body = await res.text();
|
|
27
|
+
log.warn(`[Supabase] Insert into ${table} failed (HTTP ${res.status}): ${body}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
log.warn(`[Supabase] Insert into ${table} error: ${err instanceof Error ? err.message : String(err)}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function checkConnection(config, table, log) {
|
|
35
|
+
try {
|
|
36
|
+
const res = await fetch(`${baseUrl(config)}/rest/v1/${table}?select=id&limit=1`, {
|
|
37
|
+
method: 'GET',
|
|
38
|
+
headers: {
|
|
39
|
+
'apikey': config.key,
|
|
40
|
+
'Authorization': `Bearer ${config.key}`,
|
|
41
|
+
},
|
|
42
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
43
|
+
});
|
|
44
|
+
if (res.ok) {
|
|
45
|
+
log.info(`[Supabase] Connection to "${table}" verified (HTTP ${res.status})`);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
const body = await res.text();
|
|
49
|
+
log.warn(`[Supabase] Connection check for "${table}" failed (HTTP ${res.status}): ${body}`);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
log.warn(`[Supabase] Connection check error: ${err instanceof Error ? err.message : String(err)}`);
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
7
57
|
//# sourceMappingURL=supabaseLogger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supabaseLogger.js","sourceRoot":"","sources":["../src/supabaseLogger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"supaba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AAG,CAAC,EAAE,CAAC,CAAC;IACzG,CAAC;AACH,CAAC;AAEM,KAAK,UAAU,eAAe,CACnC,MAAsB,EACtB,KAAa,EACb,GAAyD;IAEzD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,KAAK,oBAAoB,EAAE;YAC/E,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,QAAQ,EAAE,MAAM,CAAC,GAAG;gBACpB,eAAe,EAAE,UAAU,MAAM,CAAC,GAAG,EAAE;aACxC;YACD,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,kBAAkB,CAAC;SAChD,CAAC,CAAC;QACH,IAAI,GAAG,CAAC,EAAE,EAAE,CAAC;YACX,GAAG,CAAC,IAAI,CAAC,6BAA6B,KAAK,oBAAoB,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;YAC9E,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAC9B,GAAG,CAAC,IAAI,CAAC,oCAAoC,KAAK,kBAAkB,GAAG,CAAC,MAAM,MAAM,IAAI,EAAE,CAAC,CAAC;QAC5F,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,GAAG,CAAC,IAAI,CAAC,sCAAsC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACnG,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whois-homebridge/homebridge-aranet4",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Homebridge plugin for Aranet4 CO2/environment sensor via passive BLE scanning with Eve history support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@stoprocent/noble": "^2.4.0",
|
|
41
|
-
"@whois-homebridge/shared": "workspace:*",
|
|
42
41
|
"fakegato-history": "^0.6.4"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|