From 53048a029a1f3635a9aad86874da6f567ca55f85 Mon Sep 17 00:00:00 2001 From: Tanmai Gopal Date: Wed, 23 Oct 2024 19:15:25 -0700 Subject: [PATCH] things --- src/duckduckapi.ts | 21 ++++++++++++------ src/functions.ts | 19 +++++++++++++--- src/index.ts | 54 ++++++++++------------------------------------ src/schema.sql | 39 +++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 52 deletions(-) create mode 100644 src/schema.sql diff --git a/src/duckduckapi.ts b/src/duckduckapi.ts index 78aa269..81c7924 100644 --- a/src/duckduckapi.ts +++ b/src/duckduckapi.ts @@ -281,9 +281,18 @@ export async function makeConnector(dda: duckduckapi): Promise { - const oauthServices = headers.value as any; - const {access_token} = getTokensFromHeader(headers, 'google-calendar'); + let access_token: string | null = null; + try { + access_token = getTokensFromHeader(headers, 'google-calendar').access_token; + } catch (error) { + loaderStatus = `Error in getting the google-calendar oauth credentials: ${error}. Login to google-calendar?`; + return loaderStatus; + } if (!access_token) { console.log(headers.value); - loaderStatus = 'google-calendar key not found in oauth services. Login to google-calendar?'; + loaderStatus = 'google-calendar access token not found in oauth services. Login to google-calendar?'; return loaderStatus; } @@ -29,8 +39,10 @@ export async function __dda_loader_init(headers: JSONValue): Promise { if (!result) { loaderStatus = result + '. Have you logged in to google-calendar?'; + return loaderStatus; } + console.log('Initializing sync manager'); syncManager.initialize(); loaderStatus = 'running'; process.on('SIGINT', async () => { @@ -50,6 +62,7 @@ export async function __dda_loader_init(headers: JSONValue): Promise { * @readonly * */ export function __dda_loader_status(): string { + console.log(loaderStatus); return loaderStatus; } diff --git a/src/index.ts b/src/index.ts index 4723a2f..dbf2ce9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,52 +1,20 @@ import {start} from "@hasura/ndc-sdk-typescript"; -import {makeConnector, duckduckapi, db} from "./duckduckapi"; +import {makeConnector, duckduckapi} from "./duckduckapi"; +import {readFileSync} from 'fs'; +import {join} from 'path'; + +/* TODO: +- What is the easiest way to specify that I need to include a schema.sql file and and functions.ts file? +- Should the index.ts file be here kind of almost like a "don't" touch this file. You should just focus on the schema.sql and functions.ts files. +*/ -const calendar: duckduckapi = { - dbSchema: ` - CREATE TABLE IF NOT EXISTS calendar_events ( - id VARCHAR PRIMARY KEY, - summary VARCHAR, - description VARCHAR, - start_time TIMESTAMP, -- Will store both date-only and datetime values - end_time TIMESTAMP, -- Will store both date-only and datetime values - created_at TIMESTAMP, - updated_at TIMESTAMP, - creator_email VARCHAR, - organizer_email VARCHAR, - status VARCHAR, - location VARCHAR, - recurring_event_id VARCHAR, - recurrence JSON, - transparency VARCHAR, - visibility VARCHAR, - ical_uid VARCHAR, - attendees JSON, - reminders JSON, - conference_data JSON, - color_id VARCHAR, - original_start_time TIMESTAMP, - extended_properties JSON, - attachments JSON, - html_link VARCHAR, - meeting_type VARCHAR, - sequence INTEGER, - event_type VARCHAR, - calendar_id VARCHAR, - sync_status VARCHAR, - last_synced TIMESTAMP, - is_all_day BOOLEAN -- New field to distinguish all-day events -); -CREATE TABLE IF NOT EXISTS sync_state ( - calendar_id VARCHAR PRIMARY KEY, - sync_token VARCHAR, - last_sync TIMESTAMP -); - `, +const calendar: duckduckapi = { + dbSchema: readFileSync(join(__dirname, 'schema.sql'), 'utf-8'), functionsFilePath: './functions.ts' }; (async () => { const connector = await makeConnector(calendar); - start(connector); + start(connector); })(); diff --git a/src/schema.sql b/src/schema.sql new file mode 100644 index 0000000..55044af --- /dev/null +++ b/src/schema.sql @@ -0,0 +1,39 @@ + CREATE TABLE IF NOT EXISTS calendar_events ( + id VARCHAR PRIMARY KEY, + summary VARCHAR, + description VARCHAR, + start_time TIMESTAMP, -- Will store both date-only and datetime values + end_time TIMESTAMP, -- Will store both date-only and datetime values + created_at TIMESTAMP, + updated_at TIMESTAMP, + creator_email VARCHAR, + organizer_email VARCHAR, + status VARCHAR, + location VARCHAR, + recurring_event_id VARCHAR, + recurrence JSON, + transparency VARCHAR, + visibility VARCHAR, + ical_uid VARCHAR, + attendees JSON, + reminders JSON, + conference_data JSON, + color_id VARCHAR, + original_start_time TIMESTAMP, + extended_properties JSON, + attachments JSON, + html_link VARCHAR, + meeting_type VARCHAR, + sequence INTEGER, + event_type VARCHAR, + calendar_id VARCHAR, + sync_status VARCHAR, + last_synced TIMESTAMP, + is_all_day BOOLEAN -- New field to distinguish all-day events + ); + + CREATE TABLE IF NOT EXISTS sync_state ( + calendar_id VARCHAR PRIMARY KEY, + sync_token VARCHAR, + last_sync TIMESTAMP + ); \ No newline at end of file