Security fixes to lib files
This commit is contained in:
8
src/lib/google/client.ts
Normal file
8
src/lib/google/client.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* Client-side Google API integration module
|
||||||
|
*
|
||||||
|
* This module provides utilities for interacting with Google APIs from the client-side.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Re-export auth utilities
|
||||||
|
export * from './auth/client.js';
|
||||||
5
src/lib/google/client/index.ts
Normal file
5
src/lib/google/client/index.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
// Re-export client-side auth utilities
|
||||||
|
export * from '../auth/client.js';
|
||||||
|
|
||||||
|
// Re-export types
|
||||||
|
export * from './types.js';
|
||||||
14
src/lib/google/client/types.ts
Normal file
14
src/lib/google/client/types.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Client-side type definitions for Google API integration
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface GoogleSheet {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
modifiedTime: string;
|
||||||
|
webViewLink: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SheetData {
|
||||||
|
values: string[][];
|
||||||
|
}
|
||||||
@@ -1,18 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* Google API integration module
|
* Google API integration module
|
||||||
*
|
*
|
||||||
* This module provides utilities for interacting with Google APIs:
|
* This module provides utilities for interacting with Google APIs.
|
||||||
* - Authentication (server and client-side)
|
* NOTE: This is a client-side module. For server-side code, import from '$lib/google/server.js'
|
||||||
* - Sheets API
|
|
||||||
* - Gmail API
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Re-export auth utilities
|
// Re-export client-side auth utilities
|
||||||
export * from './auth/client.js';
|
export * from './auth/client.js';
|
||||||
export * as authServer from './auth/server.js';
|
|
||||||
|
|
||||||
// Re-export sheets utilities
|
|
||||||
export * as sheets from './sheets/index.js';
|
|
||||||
|
|
||||||
// Re-export Gmail utilities
|
|
||||||
export * as gmail from './gmail/index.js';
|
|
||||||
|
|||||||
14
src/lib/google/server.ts
Normal file
14
src/lib/google/server.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Server-side Google API integration module
|
||||||
|
*
|
||||||
|
* This module provides utilities for interacting with Google APIs from the server-side.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Re-export server-side auth utilities
|
||||||
|
export * from './auth/server.js';
|
||||||
|
|
||||||
|
// Re-export sheets utilities
|
||||||
|
export * from './sheets/index.js';
|
||||||
|
|
||||||
|
// Re-export Gmail utilities
|
||||||
|
export * from './gmail/index.js';
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
import type { RequestHandler } from './$types';
|
import type { RequestHandler } from './$types';
|
||||||
import { authServer } from '$lib/google/index.js';
|
import { getOAuthClient } from '$lib/google/server.js';
|
||||||
|
|
||||||
export const POST: RequestHandler = async ({ request }) => {
|
export const POST: RequestHandler = async ({ request }) => {
|
||||||
try {
|
try {
|
||||||
@@ -10,7 +10,7 @@ export const POST: RequestHandler = async ({ request }) => {
|
|||||||
return json({ error: 'Refresh token is required' }, { status: 400 });
|
return json({ error: 'Refresh token is required' }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const oauth = authServer.getOAuthClient();
|
const oauth = getOAuthClient();
|
||||||
oauth.setCredentials({ refresh_token: refreshToken });
|
oauth.setCredentials({ refresh_token: refreshToken });
|
||||||
|
|
||||||
const { credentials } = await oauth.refreshAccessToken();
|
const { credentials } = await oauth.refreshAccessToken();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
import type { RequestHandler } from './$types';
|
import type { RequestHandler } from './$types';
|
||||||
import { authServer } from '$lib/google/index.js';
|
import { getOAuthClient } from '$lib/google/server.js';
|
||||||
import { google } from 'googleapis';
|
import { google } from 'googleapis';
|
||||||
|
|
||||||
export const GET: RequestHandler = async ({ request }) => {
|
export const GET: RequestHandler = async ({ request }) => {
|
||||||
@@ -14,7 +14,7 @@ export const GET: RequestHandler = async ({ request }) => {
|
|||||||
const accessToken = authHeader.slice(7);
|
const accessToken = authHeader.slice(7);
|
||||||
|
|
||||||
// Create OAuth client with the token
|
// Create OAuth client with the token
|
||||||
const oauth = authServer.getOAuthClient();
|
const oauth = getOAuthClient();
|
||||||
oauth.setCredentials({ access_token: accessToken });
|
oauth.setCredentials({ access_token: accessToken });
|
||||||
|
|
||||||
// Call the userinfo endpoint to get user details
|
// Call the userinfo endpoint to get user details
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
import type { RequestHandler } from './$types';
|
import type { RequestHandler } from './$types';
|
||||||
import { sheets } from '$lib/google/index.js';
|
import { getSpreadsheetData } from '$lib/google/server.js';
|
||||||
|
|
||||||
export const GET: RequestHandler = async ({ params, request }) => {
|
export const GET: RequestHandler = async ({ params, request }) => {
|
||||||
try {
|
try {
|
||||||
@@ -12,7 +12,7 @@ export const GET: RequestHandler = async ({ params, request }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const refreshToken = authHeader.slice(7);
|
const refreshToken = authHeader.slice(7);
|
||||||
const sheetData = await sheets.getSpreadsheetData(refreshToken, sheetId, 'A1:Z10');
|
const sheetData = await getSpreadsheetData(refreshToken, sheetId, 'A1:Z10');
|
||||||
|
|
||||||
return json(sheetData);
|
return json(sheetData);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
import type { RequestHandler } from './$types';
|
import type { RequestHandler } from './$types';
|
||||||
import { sheets } from '$lib/google/index.js';
|
import { getRecentSpreadsheets } from '$lib/google/server.js';
|
||||||
|
|
||||||
export const GET: RequestHandler = async ({ request }) => {
|
export const GET: RequestHandler = async ({ request }) => {
|
||||||
try {
|
try {
|
||||||
@@ -10,7 +10,7 @@ export const GET: RequestHandler = async ({ request }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const refreshToken = authHeader.slice(7);
|
const refreshToken = authHeader.slice(7);
|
||||||
const spreadsheets = await sheets.getRecentSpreadsheets(refreshToken, 20);
|
const spreadsheets = await getRecentSpreadsheets(refreshToken, 20);
|
||||||
|
|
||||||
return json(spreadsheets);
|
return json(spreadsheets);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { sheets, isTokenValid, refreshAccessToken, getUserInfo, revokeToken } from '$lib/google/index.js';
|
import { isTokenValid, refreshAccessToken, getUserInfo, revokeToken } from '$lib/google/client.js';
|
||||||
import type { GoogleSheet } from '$lib/google/sheets/index.js';
|
import type { GoogleSheet } from '$lib/google/client/types.js';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
|
|
||||||
// Import Components
|
// Import Components
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { GoogleSheet } from '$lib/google/sheets/index.js';
|
import type { GoogleSheet } from '$lib/google/client/types.js';
|
||||||
|
|
||||||
// Props
|
// Props
|
||||||
let { sheetsData, errors, loadRecentSheets, selectSheet, toggleSheetList } = $props<{
|
let { sheetsData, errors, loadRecentSheets, selectSheet, toggleSheetList } = $props<{
|
||||||
|
|||||||
Reference in New Issue
Block a user