Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@sveltejs/adapter-vercel": "^5.5.3",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@types/node": "^25.9.2",
"autoprefixer": "^10.4.20",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
8 changes: 7 additions & 1 deletion src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ const supabase: Handle = async ({ event, resolve }) => {
* the cookie options. Setting `path` to `/` replicates previous/
* standard behavior.
*/
setAll: (cookiesToSet) => {
setAll: (
cookiesToSet: {
name: string;
value: string;
options: import('cookie').CookieSerializeOptions;
}[]
) => {
cookiesToSet.forEach(({ name, value, options }) => {
event.cookies.set(name, value, { ...options, path: '/' });
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/PostFilters.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@
};
}

function onselect(args: any[], type: string) {
function onselect(args: unknown[], type: string) {
if (args[1] && typeof args[1] === 'object' && 'title' in args[1]) {
const elements = args[1].title;
const elements = (args[1] as { title: string[] }).title;
if (type === 'keyword') {
keywords = elements;
} else if (type === 'education') {
Expand Down
6 changes: 5 additions & 1 deletion src/lib/components/PostForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@
<Button
disabled={!title || !description || !contact || !education || !expiration_date}
onclick={() => {
editing ? updatePost() : addPost();
if (editing) {
updatePost();
} else {
addPost();
}
}}
>
{editing ? 'Update' : 'Create'}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/components/ui/Toggle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
class={twMerge('flex cursor-pointer items-center gap-2', classNames)}
onclick={() => {
checked = !checked;
onchange && onchange(checked);
if (onchange) {
onchange(checked);
}
}}
>
<input type="checkbox" bind:checked class="peer sr-only" />
Expand Down
14 changes: 7 additions & 7 deletions src/routes/api/newsletter/daily-digest/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
RESEND_API_KEY,
RESEND_AUDIENCE_ID
} from '$env/static/private';
import { json } from '@sveltejs/kit';
import { json, error } from '@sveltejs/kit';
import { Resend } from 'resend';
import type { RequestHandler } from './$types';

Expand All @@ -31,7 +31,7 @@ export const POST: RequestHandler = async ({ locals: { supabase }, request }) =>

if (postsError) {
console.error('Error fetching vetted posts:', postsError);
throw new Error('Error fetching posts');
throw error(500, 'Error fetching posts');
}

if (!posts || posts.length === 0) {
Expand Down Expand Up @@ -82,14 +82,14 @@ export const POST: RequestHandler = async ({ locals: { supabase }, request }) =>

if (broadcast.error || !broadcast.data) {
console.error('Error creating daily digest broadcast:', broadcast.error);
throw new Error('Error creating daily digest broadcast');
throw error(500, 'Error creating daily digest broadcast');
}

const sendResult = await resend.broadcasts.send(broadcast.data.id);

if (sendResult.error) {
console.error('Error sending daily digest:', sendResult.error);
throw new Error('Error sending daily digest');
throw error(500, 'Error sending daily digest');
}

// Post to LinkedIn
Expand Down Expand Up @@ -136,8 +136,8 @@ export const POST: RequestHandler = async ({ locals: { supabase }, request }) =>
success: true,
message: `Digest processed.`
});
} catch (error: unknown) {
console.error('Error in daily digest endpoint:', error);
throw new Error('Internal Server Error');
} catch (err: unknown) {
console.error('Error in daily digest endpoint:', err);
throw error(500, 'Internal Server Error');
}
};
4 changes: 2 additions & 2 deletions src/routes/api/newsletter/subscribe/+server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RESEND_API_KEY, RESEND_AUDIENCE_ID } from '$env/static/private';
import { json } from '@sveltejs/kit';
import { json, error } from '@sveltejs/kit';
import { Resend } from 'resend';
import type { RequestHandler } from './$types';

Expand All @@ -21,7 +21,7 @@ export const POST: RequestHandler = async ({ request }) => {
});

if (subscribeResult.error) {
throw new Error('Failed to subscribe.');
throw error(500, 'Failed to subscribe.');
}

return json({ success: true, message: 'Successfully subscribed!' });
Expand Down
10 changes: 6 additions & 4 deletions src/routes/api/post/+server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { error } from '@sveltejs/kit';

export const POST = async ({ locals: { supabase, safeGetSession }, request }) => {
const { session } = await safeGetSession();

if (!session) {
throw new Error('Unauthorized');
throw error(401, 'Unauthorized');
}

const { title, description, contact, industry, education, keywords, expiration_date } =
Expand Down Expand Up @@ -33,11 +35,11 @@ export const POST = async ({ locals: { supabase, safeGetSession }, request }) =>
.single();

if (postError) {
throw new Error('Failed to create post.');
throw error(500, 'Failed to create post.');
}

if (!postData) {
throw new Error('Post creation succeeded but no data returned.');
throw error(500, 'Post creation succeeded but no data returned.');
}

// Insert new keyword associations
Expand All @@ -50,7 +52,7 @@ export const POST = async ({ locals: { supabase, safeGetSession }, request }) =>
);

if (keywordError) {
throw new Error('Failed to associate keywords.');
throw error(500, 'Failed to associate keywords.');
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/routes/api/post/[id]/+server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { text } from '@sveltejs/kit';
import { text, error } from '@sveltejs/kit';
export const DELETE = async ({ locals: { supabase, safeGetSession }, params }) => {
const { session } = await safeGetSession();

if (!session) {
throw new Error('Unauthorized');
throw error(401, 'Unauthorized');
}

const { data: posts } = await supabase
Expand All @@ -12,13 +12,13 @@ export const DELETE = async ({ locals: { supabase, safeGetSession }, params }) =
.eq('id', params.id)
.eq('creator', session.user.email);
if (!posts?.length) {
throw new Error('Not found or unauthorized');
throw error(404, 'Not found or unauthorized');
}

const { error } = await supabase.from('post').delete().eq('id', params.id);
const { error: dbError } = await supabase.from('post').delete().eq('id', params.id);

if (error) {
throw new Error('Internal Server Error');
if (dbError) {
throw error(500, 'Internal Server Error');
}

return text('Post deleted');
Expand All @@ -28,7 +28,7 @@ export const PATCH = async ({ locals: { supabase, safeGetSession }, params, requ
const { session } = await safeGetSession();

if (!session) {
throw new Error('Unauthorized');
throw error(401, 'Unauthorized');
}

const data = await request.json();
Expand All @@ -52,7 +52,7 @@ export const PATCH = async ({ locals: { supabase, safeGetSession }, params, requ
.eq('creator', session.user.email);

if (postError) {
throw new Error('Internal Server Error');
throw error(500, 'Internal Server Error');
}

// Delete existing keyword associations
Expand All @@ -62,7 +62,7 @@ export const PATCH = async ({ locals: { supabase, safeGetSession }, params, requ
.eq('post_id', params.id);

if (deleteError) {
throw new Error('Internal Server Error');
throw error(500, 'Internal Server Error');
}

// Insert new keyword associations
Expand All @@ -75,7 +75,7 @@ export const PATCH = async ({ locals: { supabase, safeGetSession }, params, requ
);

if (keywordError) {
throw new Error('Internal Server Error');
throw error(500, 'Internal Server Error');
}
}

Expand Down
2 changes: 1 addition & 1 deletion supabase/functions/daily-digest-trigger/deno.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"imports": {}
"imports": {}
}
2 changes: 1 addition & 1 deletion supabase/functions/daily-digest-trigger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'jsr:@supabase/functions-js/edge-runtime.d.ts';
console.log('Daily Digest Trigger Function Started');

// Use Deno.serve directly
Deno.serve(async (_req) => {
Deno.serve(async () => {
// _req is unused, which is fine for this trigger
// 1. Get Environment Variables
const siteUrl = 'https://vispositions.com';
Expand Down