1+ /**
2+ * This file contains the auth functions.
3+ *
4+ * @file src\auth.ts
5+ * @author Luca Liguori
6+ * @date 2024-05-01
7+ * @version 1.0.0
8+ *
9+ * Copyright 2024, 2025 Luca Liguori.
10+ *
11+ * Licensed under the Apache License, Version 2.0 (the "License");
12+ * you may not use this file except in compliance with the License.
13+ * You may obtain a copy of the License at
14+ *
15+ * http://www.apache.org/licenses/LICENSE-2.0
16+ *
17+ * Unless required by applicable law or agreed to in writing, software
18+ * distributed under the License is distributed on an "AS IS" BASIS,
19+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+ * See the License for the specific language governing permissions and
21+ * limitations under the License. *
22+ */
23+
124import crypto from 'crypto' ;
2- /*
3- import { AnsiLogger, TimestampFormat, db, idn, rs, zb } from 'node-ansi-logger';
4- import { Shelly } from './shelly.js';
5- import { ShellyDevice } from './shellyDevice.js';
6- */
725
826export interface AuthParams {
927 realm : string ; // device_id
@@ -53,6 +71,22 @@ export function getGen1BodyOptions(params?: Record<string, string | number | boo
5371 return new URLSearchParams ( params as any ) . toString ( ) ;
5472}
5573
74+ /*
75+ options: {
76+ "method":"POST",
77+ "headers": {
78+ "Content-Type":"application/json"
79+ },
80+ "body": "{
81+ \"jsonrpc\":\"2.0\",
82+ \"id\":10,
83+ \"src\":\"Matterbridge\",
84+ \"method\":\"Cover.GoToPosition \",
85+ \"params\":{\"id\":0,\"pos\":90}
86+ }"
87+ }
88+ */
89+
5690export function getGen2BodyOptions ( jsonrpc : string , id : number , src : string , method : string , params ?: Record < string , string | number | boolean > , auth ?: AuthParams ) : string {
5791 const body : Record < string , string | number | boolean | object | AuthParams > = { } ;
5892 body . jsonrpc = '2.0' ;
@@ -61,6 +95,7 @@ export function getGen2BodyOptions(jsonrpc: string, id: number, src: string, met
6195 body . method = method ;
6296 if ( params ) body . params = params ;
6397 if ( auth ) body . auth = auth ;
98+ // console.log(JSON.stringify(body));
6499 return JSON . stringify ( body ) ;
65100}
66101
0 commit comments