@paddock-connect/core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,293 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ PaddockConnect: () => PaddockConnect
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_supabase_js = require("@supabase/supabase-js");
27
+ var import_resend = require("resend");
28
+ var PaddockConnect = class {
29
+ supabase;
30
+ resend;
31
+ constructor(supabaseClient, resendClient) {
32
+ this.supabase = supabaseClient;
33
+ this.resend = resendClient;
34
+ }
35
+ async userSignIn(email, password) {
36
+ try {
37
+ const { data, error: sbError } = await this.supabase.auth.signInWithPassword({
38
+ email,
39
+ password
40
+ });
41
+ if (sbError) {
42
+ return { error: sbError };
43
+ }
44
+ return { data, error: null };
45
+ } catch (err) {
46
+ return { error: { message: "Internal Server Error" } };
47
+ }
48
+ }
49
+ async userSignUp(email, password) {
50
+ try {
51
+ const { data, error: sbError } = await this.supabase.auth.signUp({
52
+ email,
53
+ password
54
+ });
55
+ if (sbError) {
56
+ return { error: sbError };
57
+ }
58
+ return { data, error: null };
59
+ } catch (err) {
60
+ return { error: { message: "Internal Server Error" } };
61
+ }
62
+ }
63
+ async userSignOut() {
64
+ try {
65
+ await this.supabase.auth.signOut();
66
+ return {
67
+ data: {
68
+ status: true
69
+ }
70
+ };
71
+ } catch (err) {
72
+ return {
73
+ error: err
74
+ };
75
+ }
76
+ }
77
+ async getUserIdAndEmail() {
78
+ const { data } = await this.supabase.auth.getUser();
79
+ return {
80
+ email: data.user?.email,
81
+ id: data.user?.id
82
+ };
83
+ }
84
+ async getPosts(filters) {
85
+ try {
86
+ let query = this.supabase.from("posts").select("*");
87
+ if (filters?.county) query = query.eq("user_county", filters.county);
88
+ if (filters?.driver) query = query.eq("user_fav_driver", filters.driver);
89
+ if (filters?.team) query = query.eq("user_fav_team", filters.team);
90
+ const { data, error: sbError } = await query;
91
+ if (sbError) {
92
+ return { error: sbError };
93
+ }
94
+ return { data, error: null };
95
+ } catch (err) {
96
+ return { error: { message: "Internal Server Error" } };
97
+ }
98
+ }
99
+ async getAllRequestsSent(id) {
100
+ try {
101
+ const { data, error: sbError } = await this.supabase.from("requests").select().eq("user_id", id);
102
+ if (sbError) {
103
+ return { error: sbError };
104
+ }
105
+ return { data, error: null };
106
+ } catch (err) {
107
+ return {
108
+ error: {
109
+ message: err
110
+ }
111
+ };
112
+ }
113
+ }
114
+ async getAllRequestsReceived(email) {
115
+ try {
116
+ const { data, error: sbError } = await this.supabase.from("requests").select().eq("owner_email", email);
117
+ if (sbError) {
118
+ return {
119
+ error: sbError
120
+ };
121
+ }
122
+ return {
123
+ data,
124
+ error: null
125
+ };
126
+ } catch (err) {
127
+ return {
128
+ error: {
129
+ message: err
130
+ }
131
+ };
132
+ }
133
+ }
134
+ async deleteSentRequest(id) {
135
+ try {
136
+ const { error: sbError } = await this.supabase.from("requests").delete().eq("id", id);
137
+ if (sbError) {
138
+ return { error: sbError };
139
+ }
140
+ return { data: true, error: null };
141
+ } catch (err) {
142
+ return {
143
+ error: {
144
+ message: err
145
+ }
146
+ };
147
+ }
148
+ }
149
+ async updateReceivedRequest(id, post_id, status, user_id) {
150
+ try {
151
+ const { error: sbError } = await this.supabase.from("requests").update({
152
+ status
153
+ }).eq("id", id);
154
+ if (sbError) {
155
+ return { error: sbError };
156
+ }
157
+ const { data: postData, error: postError } = await this.supabase.from("posts").select("post_title").eq("id", post_id).single();
158
+ if (postError) {
159
+ return {
160
+ error: postError
161
+ };
162
+ }
163
+ const { data: requesterEmail, error: requesterError } = await this.supabase.from("profiles").select("user_email").eq("id", user_id).single();
164
+ const emailPromises = [
165
+ this.resend.emails.send({
166
+ from: "Paddock Connect <notifications@paddockconnect.social>",
167
+ to: requesterEmail?.user_email,
168
+ subject: `Your Request for ${postData.post_title} has been updated!`,
169
+ html: `<p>Your request to join <strong>${postData.post_title}</strong> has been ${status}</p>`
170
+ })
171
+ ];
172
+ await Promise.all(emailPromises);
173
+ return {
174
+ data: true,
175
+ error: null
176
+ };
177
+ } catch (err) {
178
+ return {
179
+ error: {
180
+ message: err
181
+ }
182
+ };
183
+ }
184
+ }
185
+ async getPost(id) {
186
+ try {
187
+ const { data, error: sbError } = await this.supabase.from("posts").select().eq("id", id).single();
188
+ if (sbError) {
189
+ return { error: sbError };
190
+ }
191
+ return { data, error: null };
192
+ } catch (err) {
193
+ return { error: { message: "Internal Server Error" } };
194
+ }
195
+ }
196
+ async handleRequestToJoin(post_id, requesterId, requesterEmail) {
197
+ try {
198
+ const { data: postInfo, error: postError } = await this.supabase.from("posts").select(`post_title,author:profiles!user_id(user_email)`).eq("id", post_id).single();
199
+ console.log(postInfo, postError);
200
+ if (postError || !postInfo?.author) {
201
+ return {
202
+ error: { message: "Could not find event or author details." }
203
+ };
204
+ }
205
+ const authorEmail = postInfo.author.user_email;
206
+ const eventTitle = postInfo.post_title;
207
+ const { error: sbError } = await this.supabase.from("requests").insert({
208
+ post_id,
209
+ user_id: requesterId,
210
+ status: "PENDING",
211
+ owner_email: authorEmail,
212
+ post_title: eventTitle
213
+ });
214
+ if (sbError) return { error: { message: sbError.message } };
215
+ const emailPromises = [
216
+ this.resend.emails.send({
217
+ from: "Paddock Connect <notifications@paddockconnect.social>",
218
+ to: requesterEmail,
219
+ subject: `Request Sent: ${eventTitle}`,
220
+ html: `<p>Your request to join <strong>${eventTitle}</strong> has been sent successfully!</p>`
221
+ }),
222
+ this.resend.emails.send({
223
+ from: "Paddock Connect <notifications@paddockconnect.social>",
224
+ to: authorEmail,
225
+ subject: "New Request for your Event!",
226
+ html: `
227
+ <h3>New Join Request</h3>
228
+ <p>User <strong>${requesterEmail}</strong> wants to join your event: <strong>${eventTitle}</strong>.</p>
229
+ <p>Head to your dashboard to respond to this request.</p>
230
+ `
231
+ })
232
+ ];
233
+ await Promise.all(emailPromises);
234
+ return { data: true, error: null };
235
+ } catch (err) {
236
+ console.error("Join Request Error:", err);
237
+ return { error: { message: "Internal Server Error" } };
238
+ }
239
+ }
240
+ async createNewPost(formData, id) {
241
+ try {
242
+ const { data: profile } = await this.supabase.from("profiles").select("*").eq("id", id).single();
243
+ const { error: sbError } = await this.supabase.from("posts").insert({
244
+ user_id: id,
245
+ post_title: formData.get("title"),
246
+ post_content: formData.get("content"),
247
+ post_event_date: formData.get("screeningDate"),
248
+ user_address: profile.address,
249
+ user_fav_team: profile.fav_team,
250
+ user_fav_driver: profile.fav_driver,
251
+ user_county: profile.county
252
+ });
253
+ if (sbError) {
254
+ return { error: sbError };
255
+ }
256
+ return { data: true, error: null };
257
+ } catch (err) {
258
+ return { error: { message: "Internal Server Error" } };
259
+ }
260
+ }
261
+ async getUserProfile() {
262
+ try {
263
+ const { data, error: sbError } = await this.supabase.from("profiles").select();
264
+ if (sbError) {
265
+ return { error: sbError };
266
+ }
267
+ return { data: data[0], error: null };
268
+ } catch (err) {
269
+ return { error: { message: "Internal Server Error" } };
270
+ }
271
+ }
272
+ async updateUserProfile(formData, id) {
273
+ try {
274
+ const { error: sbError } = await this.supabase.from("profiles").update({
275
+ full_name: formData.get("fullName"),
276
+ address: formData.get("address"),
277
+ county: formData.get("county"),
278
+ fav_team: formData.get("favTeam"),
279
+ fav_driver: formData.get("favDriver")
280
+ }).eq("id", id);
281
+ if (sbError) {
282
+ return { error: sbError };
283
+ }
284
+ return { data: true, error: null };
285
+ } catch (err) {
286
+ return { error: { message: "Internal Server Error" } };
287
+ }
288
+ }
289
+ };
290
+ // Annotate the CommonJS export names for ESM import in node:
291
+ 0 && (module.exports = {
292
+ PaddockConnect
293
+ });
@@ -0,0 +1,33 @@
1
+ import { SupabaseClient } from '@supabase/supabase-js';
2
+ import { Resend } from 'resend';
3
+
4
+ interface Response {
5
+ data?: object | boolean;
6
+ error?: object | null;
7
+ }
8
+
9
+ declare class PaddockConnect {
10
+ private supabase;
11
+ private resend;
12
+ constructor(supabaseClient: SupabaseClient, resendClient: Resend);
13
+ userSignIn(email: string, password: string): Promise<Response>;
14
+ userSignUp(email: string, password: string): Promise<Response>;
15
+ userSignOut(): Promise<Response>;
16
+ getUserIdAndEmail(): Promise<object>;
17
+ getPosts(filters: {
18
+ county?: string;
19
+ team?: string;
20
+ driver?: string;
21
+ }): Promise<Response>;
22
+ getAllRequestsSent(id: string | undefined): Promise<Response>;
23
+ getAllRequestsReceived(email: string | undefined): Promise<Response>;
24
+ deleteSentRequest(id: string): Promise<Response>;
25
+ updateReceivedRequest(id: string, post_id: string, status: string, user_id: string): Promise<Response>;
26
+ getPost(id: string): Promise<Response>;
27
+ handleRequestToJoin(post_id: string, requesterId: string | undefined, requesterEmail: string | undefined): Promise<Response>;
28
+ createNewPost(formData: FormData, id: string | undefined): Promise<Response>;
29
+ getUserProfile(): Promise<Response>;
30
+ updateUserProfile(formData: FormData, id: string | undefined): Promise<Response>;
31
+ }
32
+
33
+ export { PaddockConnect };
@@ -0,0 +1,33 @@
1
+ import { SupabaseClient } from '@supabase/supabase-js';
2
+ import { Resend } from 'resend';
3
+
4
+ interface Response {
5
+ data?: object | boolean;
6
+ error?: object | null;
7
+ }
8
+
9
+ declare class PaddockConnect {
10
+ private supabase;
11
+ private resend;
12
+ constructor(supabaseClient: SupabaseClient, resendClient: Resend);
13
+ userSignIn(email: string, password: string): Promise<Response>;
14
+ userSignUp(email: string, password: string): Promise<Response>;
15
+ userSignOut(): Promise<Response>;
16
+ getUserIdAndEmail(): Promise<object>;
17
+ getPosts(filters: {
18
+ county?: string;
19
+ team?: string;
20
+ driver?: string;
21
+ }): Promise<Response>;
22
+ getAllRequestsSent(id: string | undefined): Promise<Response>;
23
+ getAllRequestsReceived(email: string | undefined): Promise<Response>;
24
+ deleteSentRequest(id: string): Promise<Response>;
25
+ updateReceivedRequest(id: string, post_id: string, status: string, user_id: string): Promise<Response>;
26
+ getPost(id: string): Promise<Response>;
27
+ handleRequestToJoin(post_id: string, requesterId: string | undefined, requesterEmail: string | undefined): Promise<Response>;
28
+ createNewPost(formData: FormData, id: string | undefined): Promise<Response>;
29
+ getUserProfile(): Promise<Response>;
30
+ updateUserProfile(formData: FormData, id: string | undefined): Promise<Response>;
31
+ }
32
+
33
+ export { PaddockConnect };
package/dist/index.js ADDED
@@ -0,0 +1,268 @@
1
+ // src/index.ts
2
+ import "@supabase/supabase-js";
3
+ import "resend";
4
+ var PaddockConnect = class {
5
+ supabase;
6
+ resend;
7
+ constructor(supabaseClient, resendClient) {
8
+ this.supabase = supabaseClient;
9
+ this.resend = resendClient;
10
+ }
11
+ async userSignIn(email, password) {
12
+ try {
13
+ const { data, error: sbError } = await this.supabase.auth.signInWithPassword({
14
+ email,
15
+ password
16
+ });
17
+ if (sbError) {
18
+ return { error: sbError };
19
+ }
20
+ return { data, error: null };
21
+ } catch (err) {
22
+ return { error: { message: "Internal Server Error" } };
23
+ }
24
+ }
25
+ async userSignUp(email, password) {
26
+ try {
27
+ const { data, error: sbError } = await this.supabase.auth.signUp({
28
+ email,
29
+ password
30
+ });
31
+ if (sbError) {
32
+ return { error: sbError };
33
+ }
34
+ return { data, error: null };
35
+ } catch (err) {
36
+ return { error: { message: "Internal Server Error" } };
37
+ }
38
+ }
39
+ async userSignOut() {
40
+ try {
41
+ await this.supabase.auth.signOut();
42
+ return {
43
+ data: {
44
+ status: true
45
+ }
46
+ };
47
+ } catch (err) {
48
+ return {
49
+ error: err
50
+ };
51
+ }
52
+ }
53
+ async getUserIdAndEmail() {
54
+ const { data } = await this.supabase.auth.getUser();
55
+ return {
56
+ email: data.user?.email,
57
+ id: data.user?.id
58
+ };
59
+ }
60
+ async getPosts(filters) {
61
+ try {
62
+ let query = this.supabase.from("posts").select("*");
63
+ if (filters?.county) query = query.eq("user_county", filters.county);
64
+ if (filters?.driver) query = query.eq("user_fav_driver", filters.driver);
65
+ if (filters?.team) query = query.eq("user_fav_team", filters.team);
66
+ const { data, error: sbError } = await query;
67
+ if (sbError) {
68
+ return { error: sbError };
69
+ }
70
+ return { data, error: null };
71
+ } catch (err) {
72
+ return { error: { message: "Internal Server Error" } };
73
+ }
74
+ }
75
+ async getAllRequestsSent(id) {
76
+ try {
77
+ const { data, error: sbError } = await this.supabase.from("requests").select().eq("user_id", id);
78
+ if (sbError) {
79
+ return { error: sbError };
80
+ }
81
+ return { data, error: null };
82
+ } catch (err) {
83
+ return {
84
+ error: {
85
+ message: err
86
+ }
87
+ };
88
+ }
89
+ }
90
+ async getAllRequestsReceived(email) {
91
+ try {
92
+ const { data, error: sbError } = await this.supabase.from("requests").select().eq("owner_email", email);
93
+ if (sbError) {
94
+ return {
95
+ error: sbError
96
+ };
97
+ }
98
+ return {
99
+ data,
100
+ error: null
101
+ };
102
+ } catch (err) {
103
+ return {
104
+ error: {
105
+ message: err
106
+ }
107
+ };
108
+ }
109
+ }
110
+ async deleteSentRequest(id) {
111
+ try {
112
+ const { error: sbError } = await this.supabase.from("requests").delete().eq("id", id);
113
+ if (sbError) {
114
+ return { error: sbError };
115
+ }
116
+ return { data: true, error: null };
117
+ } catch (err) {
118
+ return {
119
+ error: {
120
+ message: err
121
+ }
122
+ };
123
+ }
124
+ }
125
+ async updateReceivedRequest(id, post_id, status, user_id) {
126
+ try {
127
+ const { error: sbError } = await this.supabase.from("requests").update({
128
+ status
129
+ }).eq("id", id);
130
+ if (sbError) {
131
+ return { error: sbError };
132
+ }
133
+ const { data: postData, error: postError } = await this.supabase.from("posts").select("post_title").eq("id", post_id).single();
134
+ if (postError) {
135
+ return {
136
+ error: postError
137
+ };
138
+ }
139
+ const { data: requesterEmail, error: requesterError } = await this.supabase.from("profiles").select("user_email").eq("id", user_id).single();
140
+ const emailPromises = [
141
+ this.resend.emails.send({
142
+ from: "Paddock Connect <notifications@paddockconnect.social>",
143
+ to: requesterEmail?.user_email,
144
+ subject: `Your Request for ${postData.post_title} has been updated!`,
145
+ html: `<p>Your request to join <strong>${postData.post_title}</strong> has been ${status}</p>`
146
+ })
147
+ ];
148
+ await Promise.all(emailPromises);
149
+ return {
150
+ data: true,
151
+ error: null
152
+ };
153
+ } catch (err) {
154
+ return {
155
+ error: {
156
+ message: err
157
+ }
158
+ };
159
+ }
160
+ }
161
+ async getPost(id) {
162
+ try {
163
+ const { data, error: sbError } = await this.supabase.from("posts").select().eq("id", id).single();
164
+ if (sbError) {
165
+ return { error: sbError };
166
+ }
167
+ return { data, error: null };
168
+ } catch (err) {
169
+ return { error: { message: "Internal Server Error" } };
170
+ }
171
+ }
172
+ async handleRequestToJoin(post_id, requesterId, requesterEmail) {
173
+ try {
174
+ const { data: postInfo, error: postError } = await this.supabase.from("posts").select(`post_title,author:profiles!user_id(user_email)`).eq("id", post_id).single();
175
+ console.log(postInfo, postError);
176
+ if (postError || !postInfo?.author) {
177
+ return {
178
+ error: { message: "Could not find event or author details." }
179
+ };
180
+ }
181
+ const authorEmail = postInfo.author.user_email;
182
+ const eventTitle = postInfo.post_title;
183
+ const { error: sbError } = await this.supabase.from("requests").insert({
184
+ post_id,
185
+ user_id: requesterId,
186
+ status: "PENDING",
187
+ owner_email: authorEmail,
188
+ post_title: eventTitle
189
+ });
190
+ if (sbError) return { error: { message: sbError.message } };
191
+ const emailPromises = [
192
+ this.resend.emails.send({
193
+ from: "Paddock Connect <notifications@paddockconnect.social>",
194
+ to: requesterEmail,
195
+ subject: `Request Sent: ${eventTitle}`,
196
+ html: `<p>Your request to join <strong>${eventTitle}</strong> has been sent successfully!</p>`
197
+ }),
198
+ this.resend.emails.send({
199
+ from: "Paddock Connect <notifications@paddockconnect.social>",
200
+ to: authorEmail,
201
+ subject: "New Request for your Event!",
202
+ html: `
203
+ <h3>New Join Request</h3>
204
+ <p>User <strong>${requesterEmail}</strong> wants to join your event: <strong>${eventTitle}</strong>.</p>
205
+ <p>Head to your dashboard to respond to this request.</p>
206
+ `
207
+ })
208
+ ];
209
+ await Promise.all(emailPromises);
210
+ return { data: true, error: null };
211
+ } catch (err) {
212
+ console.error("Join Request Error:", err);
213
+ return { error: { message: "Internal Server Error" } };
214
+ }
215
+ }
216
+ async createNewPost(formData, id) {
217
+ try {
218
+ const { data: profile } = await this.supabase.from("profiles").select("*").eq("id", id).single();
219
+ const { error: sbError } = await this.supabase.from("posts").insert({
220
+ user_id: id,
221
+ post_title: formData.get("title"),
222
+ post_content: formData.get("content"),
223
+ post_event_date: formData.get("screeningDate"),
224
+ user_address: profile.address,
225
+ user_fav_team: profile.fav_team,
226
+ user_fav_driver: profile.fav_driver,
227
+ user_county: profile.county
228
+ });
229
+ if (sbError) {
230
+ return { error: sbError };
231
+ }
232
+ return { data: true, error: null };
233
+ } catch (err) {
234
+ return { error: { message: "Internal Server Error" } };
235
+ }
236
+ }
237
+ async getUserProfile() {
238
+ try {
239
+ const { data, error: sbError } = await this.supabase.from("profiles").select();
240
+ if (sbError) {
241
+ return { error: sbError };
242
+ }
243
+ return { data: data[0], error: null };
244
+ } catch (err) {
245
+ return { error: { message: "Internal Server Error" } };
246
+ }
247
+ }
248
+ async updateUserProfile(formData, id) {
249
+ try {
250
+ const { error: sbError } = await this.supabase.from("profiles").update({
251
+ full_name: formData.get("fullName"),
252
+ address: formData.get("address"),
253
+ county: formData.get("county"),
254
+ fav_team: formData.get("favTeam"),
255
+ fav_driver: formData.get("favDriver")
256
+ }).eq("id", id);
257
+ if (sbError) {
258
+ return { error: sbError };
259
+ }
260
+ return { data: true, error: null };
261
+ } catch (err) {
262
+ return { error: { message: "Internal Server Error" } };
263
+ }
264
+ }
265
+ };
266
+ export {
267
+ PaddockConnect
268
+ };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@paddock-connect/core",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "require": {
18
+ "types": "./dist/index.d.cts",
19
+ "default": "./dist/index.cjs"
20
+ }
21
+ }
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "scripts": {
27
+ "build": "tsup",
28
+ "dev": "tsup src/index.ts --format cjs,esm --watch --dts"
29
+ },
30
+ "devDependencies": {
31
+ "@supabase/supabase-js": "^2.103.0",
32
+ "@types/node": "^25.6.0",
33
+ "nodemon": "^3.1.14",
34
+ "resend": "^6.10.0",
35
+ "tsup": "^8.5.1",
36
+ "typescript": "^6.0.2"
37
+ },
38
+ "peerDependencies": {
39
+ "@supabase/supabase-js": "^2.103.0",
40
+ "resend": "^6.10.0"
41
+ }
42
+ }