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