mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 06:29:07 +00:00
refactor: use strict typing
This commit is contained in:
@@ -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',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user