refactor: use strict typing

This commit is contained in:
Carlos Valente
2025-03-21 19:44:16 +01:00
committed by arc-alex
parent 14a7c04d3b
commit d48b2ae506
39 changed files with 339 additions and 246 deletions
@@ -2,17 +2,7 @@ import { isOntimeBlock, isOntimeEvent, OntimeEvent, OntimeEntry } from 'ontime-t
import { millisToString } from 'ontime-utils';
import type { sheets_v4 } from '@googleapis/sheets';
import { isObject } from '../../utils/assert.js';
// we expect client secret file to contain the following keys
const requiredClientKeys = [
'client_id',
'auth_uri',
'token_uri',
'token_uri',
'auth_provider_x509_cert_url',
'client_secret',
];
import { is } from '../../utils/is.js';
export type ClientSecret = {
installed: {
@@ -29,19 +19,25 @@ export type ClientSecret = {
* @param clientSecret
* @throws
*/
export function validateClientSecret(clientSecret: object): clientSecret is ClientSecret {
export function isClientSecret(clientSecret: object): clientSecret is ClientSecret {
if (!('installed' in clientSecret)) {
throw new Error('Missing "installed" object');
return false;
}
const { installed } = clientSecret;
isObject(installed);
if (requiredClientKeys.every((key) => Object.keys(installed).includes(key))) {
return;
if (!is.object(installed)) {
return false;
}
throw new Error('Missing keys in "installed" object');
// we expect client secret file to contain the following keys
return is.objectWithKeys(installed, [
'client_id',
'auth_uri',
'token_uri',
'token_uri',
'auth_provider_x509_cert_url',
'client_secret',
]);
}
/**