@spotsdev/sdk 1.0.0 → 1.2.0

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.
Files changed (74) hide show
  1. package/dist/api/client.d.ts +1 -1
  2. package/dist/api/client.js +7 -3
  3. package/dist/api/entities.d.ts +318 -0
  4. package/dist/api/entities.js +9 -0
  5. package/dist/api/mutations/clubs.d.ts +6 -6
  6. package/dist/api/mutations/clubs.js +12 -10
  7. package/dist/api/mutations/conversations.d.ts +7 -7
  8. package/dist/api/mutations/conversations.js +17 -13
  9. package/dist/api/mutations/index.js +1 -1
  10. package/dist/api/mutations/notifications.d.ts +4 -4
  11. package/dist/api/mutations/notifications.js +7 -7
  12. package/dist/api/mutations/orders.d.ts +7 -7
  13. package/dist/api/mutations/orders.js +11 -13
  14. package/dist/api/mutations/posts.d.ts +13 -13
  15. package/dist/api/mutations/posts.js +41 -29
  16. package/dist/api/mutations/products.d.ts +5 -5
  17. package/dist/api/mutations/products.js +9 -13
  18. package/dist/api/mutations/spots.d.ts +42 -8
  19. package/dist/api/mutations/spots.js +51 -13
  20. package/dist/api/mutations/users.d.ts +12 -10
  21. package/dist/api/mutations/users.js +20 -18
  22. package/dist/api/queries/auth.d.ts +5 -5
  23. package/dist/api/queries/auth.js +7 -7
  24. package/dist/api/queries/clubs.d.ts +7 -7
  25. package/dist/api/queries/clubs.js +11 -11
  26. package/dist/api/queries/conversations.d.ts +5 -5
  27. package/dist/api/queries/conversations.js +7 -7
  28. package/dist/api/queries/index.js +1 -1
  29. package/dist/api/queries/misc.d.ts +8 -32
  30. package/dist/api/queries/misc.js +28 -66
  31. package/dist/api/queries/notifications.d.ts +4 -4
  32. package/dist/api/queries/notifications.js +5 -5
  33. package/dist/api/queries/orders.d.ts +4 -4
  34. package/dist/api/queries/orders.js +7 -7
  35. package/dist/api/queries/posts.d.ts +44 -7
  36. package/dist/api/queries/posts.js +118 -15
  37. package/dist/api/queries/products.d.ts +6 -10
  38. package/dist/api/queries/products.js +7 -9
  39. package/dist/api/queries/spots.d.ts +31 -16
  40. package/dist/api/queries/spots.js +113 -31
  41. package/dist/api/queries/templates.d.ts +6 -9
  42. package/dist/api/queries/templates.js +8 -13
  43. package/dist/api/queries/users.d.ts +25 -11
  44. package/dist/api/queries/users.js +75 -27
  45. package/dist/api/types.d.ts +36 -33
  46. package/dist/api/types.js +6 -7
  47. package/dist/index.d.ts +1 -2
  48. package/dist/index.js +1 -8
  49. package/package.json +6 -21
  50. package/src/api/client.ts +45 -30
  51. package/src/api/entities.ts +424 -0
  52. package/src/api/mutations/clubs.ts +73 -40
  53. package/src/api/mutations/conversations.ts +91 -47
  54. package/src/api/mutations/index.ts +8 -8
  55. package/src/api/mutations/notifications.ts +48 -25
  56. package/src/api/mutations/orders.ts +101 -70
  57. package/src/api/mutations/posts.ts +229 -118
  58. package/src/api/mutations/products.ts +120 -81
  59. package/src/api/mutations/spots.ts +167 -55
  60. package/src/api/mutations/users.ts +109 -76
  61. package/src/api/queries/auth.ts +49 -24
  62. package/src/api/queries/clubs.ts +53 -38
  63. package/src/api/queries/conversations.ts +48 -30
  64. package/src/api/queries/index.ts +21 -21
  65. package/src/api/queries/misc.ts +53 -82
  66. package/src/api/queries/notifications.ts +32 -21
  67. package/src/api/queries/orders.ts +59 -42
  68. package/src/api/queries/posts.ts +203 -48
  69. package/src/api/queries/products.ts +51 -44
  70. package/src/api/queries/spots.ts +216 -85
  71. package/src/api/queries/templates.ts +39 -32
  72. package/src/api/queries/users.ts +157 -64
  73. package/src/api/types.ts +72 -118
  74. package/src/index.ts +5 -11
@@ -4,20 +4,26 @@
4
4
  * TanStack Query hooks for post/board mutation operations.
5
5
  */
6
6
 
7
- import { useMutation, useQueryClient, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
8
- import { getApiClient } from '../client';
9
- import { postKeys } from '../queries/posts';
10
- import type {
11
- Post,
12
- PostResponse,
13
- CreatePostRequest,
14
- CreateReplyRequest,
15
- RespondToPostRequest,
16
- UpdateResponseRequest,
17
- ApiResponse,
18
- UpvoteResponse,
19
- PostStatusDto,
20
- } from '../types';
7
+ import {
8
+ useMutation,
9
+ type UseMutationOptions,
10
+ type UseMutationResult,
11
+ useQueryClient,
12
+ } from '@tanstack/react-query'
13
+
14
+ import {getApiClient} from '../client'
15
+ import {postKeys} from '../queries/posts'
16
+ import {
17
+ type ApiResponse,
18
+ type CreatePostRequest,
19
+ type CreateReplyRequest,
20
+ type Post,
21
+ type PostResponse,
22
+ type PostStatusDto,
23
+ type RespondToPostRequest,
24
+ type UpdateResponseRequest,
25
+ type UpvoteResponse,
26
+ } from '../types'
21
27
 
22
28
  // ============================================================================
23
29
  // MUTATION HOOKS
@@ -26,253 +32,358 @@ import type {
26
32
  /**
27
33
  * Create a new post
28
34
  *
29
- * @endpoint POST /api/v1/spots/{spotId}/posts
35
+ * @endpoint POST /spots/{spotId}/posts
30
36
  */
31
37
  export function useCreatePost(
32
- options?: Omit<UseMutationOptions<Post, Error, { spotId: string } & CreatePostRequest>, 'mutationFn'>
33
- ): UseMutationResult<Post, Error, { spotId: string } & CreatePostRequest> {
34
- const queryClient = useQueryClient();
38
+ options?: Omit<
39
+ UseMutationOptions<Post, Error, {spotId: string} & CreatePostRequest>,
40
+ 'mutationFn'
41
+ >,
42
+ ): UseMutationResult<Post, Error, {spotId: string} & CreatePostRequest> {
43
+ const queryClient = useQueryClient()
35
44
 
36
45
  return useMutation({
37
- mutationFn: async ({ spotId, ...data }): Promise<Post> => {
38
- const client = getApiClient();
39
- const response = await client.post<ApiResponse<Post>>(`/api/v1/spots/${spotId}/posts`, data);
40
- return response.data.data;
46
+ mutationFn: async ({spotId, ...data}): Promise<Post> => {
47
+ const client = getApiClient()
48
+ const response = await client.post<ApiResponse<Post>>(
49
+ `/spots/${spotId}/posts`,
50
+ data,
51
+ )
52
+ return response.data.data
41
53
  },
42
54
  onSuccess: (_, variables) => {
43
- queryClient.invalidateQueries({ queryKey: postKeys.bySpot(variables.spotId) });
55
+ queryClient.invalidateQueries({
56
+ queryKey: postKeys.bySpot(variables.spotId),
57
+ })
44
58
  },
45
59
  ...options,
46
- });
60
+ })
47
61
  }
48
62
 
49
63
  /**
50
64
  * Update a post
51
65
  *
52
- * @endpoint PUT /api/v1/posts/{postId}
66
+ * @endpoint PUT /posts/{postId}
53
67
  */
54
68
  export function useUpdatePost(
55
- options?: Omit<UseMutationOptions<Post, Error, { postId: string; title?: string; content?: string }>, 'mutationFn'>
56
- ): UseMutationResult<Post, Error, { postId: string; title?: string; content?: string }> {
57
- const queryClient = useQueryClient();
69
+ options?: Omit<
70
+ UseMutationOptions<
71
+ Post,
72
+ Error,
73
+ {postId: string; title?: string; content?: string}
74
+ >,
75
+ 'mutationFn'
76
+ >,
77
+ ): UseMutationResult<
78
+ Post,
79
+ Error,
80
+ {postId: string; title?: string; content?: string}
81
+ > {
82
+ const queryClient = useQueryClient()
58
83
 
59
84
  return useMutation({
60
- mutationFn: async ({ postId, ...data }): Promise<Post> => {
61
- const client = getApiClient();
62
- const response = await client.put<ApiResponse<Post>>(`/api/v1/posts/${postId}`, data);
63
- return response.data.data;
85
+ mutationFn: async ({postId, ...data}): Promise<Post> => {
86
+ const client = getApiClient()
87
+ const response = await client.put<ApiResponse<Post>>(
88
+ `/posts/${postId}`,
89
+ data,
90
+ )
91
+ return response.data.data
64
92
  },
65
93
  onSuccess: (data, variables) => {
66
- queryClient.setQueryData(postKeys.detail(variables.postId), data);
94
+ queryClient.setQueryData(postKeys.detail(variables.postId), data)
67
95
  },
68
96
  ...options,
69
- });
97
+ })
70
98
  }
71
99
 
72
100
  /**
73
101
  * Delete a post
74
102
  *
75
- * @endpoint DELETE /api/v1/posts/{postId}
103
+ * @endpoint DELETE /posts/{postId}
76
104
  */
77
105
  export function useDeletePost(
78
- options?: Omit<UseMutationOptions<void, Error, string>, 'mutationFn'>
106
+ options?: Omit<UseMutationOptions<void, Error, string>, 'mutationFn'>,
79
107
  ): UseMutationResult<void, Error, string> {
80
- const queryClient = useQueryClient();
108
+ const queryClient = useQueryClient()
81
109
 
82
110
  return useMutation({
83
111
  mutationFn: async (postId: string): Promise<void> => {
84
- const client = getApiClient();
85
- await client.delete(`/api/v1/posts/${postId}`);
112
+ const client = getApiClient()
113
+ await client.delete(`/posts/${postId}`)
86
114
  },
87
115
  onSuccess: (_, postId) => {
88
- queryClient.invalidateQueries({ queryKey: postKeys.detail(postId) });
89
- queryClient.invalidateQueries({ queryKey: postKeys.lists() });
116
+ queryClient.invalidateQueries({queryKey: postKeys.detail(postId)})
117
+ queryClient.invalidateQueries({queryKey: postKeys.lists()})
90
118
  },
91
119
  ...options,
92
- });
120
+ })
93
121
  }
94
122
 
95
123
  /**
96
124
  * Fulfill a post (mark as fulfilled)
97
125
  *
98
- * @endpoint PUT /api/v1/posts/{postId}/fulfill
126
+ * @endpoint PUT /posts/{postId}/fulfill
99
127
  */
100
128
  export function useFulfillPost(
101
- options?: Omit<UseMutationOptions<Post, Error, string>, 'mutationFn'>
129
+ options?: Omit<UseMutationOptions<Post, Error, string>, 'mutationFn'>,
102
130
  ): UseMutationResult<Post, Error, string> {
103
- const queryClient = useQueryClient();
131
+ const queryClient = useQueryClient()
104
132
 
105
133
  return useMutation({
106
134
  mutationFn: async (postId: string): Promise<Post> => {
107
- const client = getApiClient();
108
- const response = await client.put<ApiResponse<Post>>(`/api/v1/posts/${postId}/fulfill`);
109
- return response.data.data;
135
+ const client = getApiClient()
136
+ const response = await client.put<ApiResponse<Post>>(
137
+ `/posts/${postId}/fulfill`,
138
+ )
139
+ return response.data.data
110
140
  },
111
141
  onSuccess: (data, postId) => {
112
- queryClient.setQueryData(postKeys.detail(postId), data);
142
+ queryClient.setQueryData(postKeys.detail(postId), data)
113
143
  },
114
144
  ...options,
115
- });
145
+ })
116
146
  }
117
147
 
118
148
  /**
119
149
  * Upvote/unupvote a post
120
150
  *
121
- * @endpoint POST /api/v1/posts/{postId}/upvote
151
+ * @endpoint POST /posts/{postId}/upvote
122
152
  */
123
153
  export function useUpvotePost(
124
- options?: Omit<UseMutationOptions<UpvoteResponse, Error, string>, 'mutationFn'>
154
+ options?: Omit<
155
+ UseMutationOptions<UpvoteResponse, Error, string>,
156
+ 'mutationFn'
157
+ >,
125
158
  ): UseMutationResult<UpvoteResponse, Error, string> {
126
- const queryClient = useQueryClient();
159
+ const queryClient = useQueryClient()
127
160
 
128
161
  return useMutation({
129
162
  mutationFn: async (postId: string): Promise<UpvoteResponse> => {
130
- const client = getApiClient();
131
- const response = await client.post<ApiResponse<UpvoteResponse>>(`/api/v1/posts/${postId}/upvote`);
132
- return response.data.data;
163
+ const client = getApiClient()
164
+ const response = await client.post<ApiResponse<UpvoteResponse>>(
165
+ `/posts/${postId}/upvote`,
166
+ )
167
+ return response.data.data
133
168
  },
134
169
  onSuccess: (_, postId) => {
135
- queryClient.invalidateQueries({ queryKey: postKeys.detail(postId) });
170
+ queryClient.invalidateQueries({queryKey: postKeys.detail(postId)})
136
171
  },
137
172
  ...options,
138
- });
173
+ })
139
174
  }
140
175
 
141
176
  /**
142
177
  * Create a reply to a post
143
178
  *
144
- * @endpoint POST /api/v1/posts/{postId}/reply
179
+ * @endpoint POST /posts/{postId}/reply
145
180
  */
146
181
  export function useCreateReply(
147
- options?: Omit<UseMutationOptions<unknown, Error, { postId: string } & CreateReplyRequest>, 'mutationFn'>
148
- ): UseMutationResult<unknown, Error, { postId: string } & CreateReplyRequest> {
149
- const queryClient = useQueryClient();
182
+ options?: Omit<
183
+ UseMutationOptions<unknown, Error, {postId: string} & CreateReplyRequest>,
184
+ 'mutationFn'
185
+ >,
186
+ ): UseMutationResult<unknown, Error, {postId: string} & CreateReplyRequest> {
187
+ const queryClient = useQueryClient()
150
188
 
151
189
  return useMutation({
152
- mutationFn: async ({ postId, ...data }) => {
153
- const client = getApiClient();
154
- const response = await client.post<ApiResponse<unknown>>(`/api/v1/posts/${postId}/reply`, data);
155
- return response.data.data;
190
+ mutationFn: async ({postId, ...data}) => {
191
+ const client = getApiClient()
192
+ const response = await client.post<ApiResponse<unknown>>(
193
+ `/posts/${postId}/reply`,
194
+ data,
195
+ )
196
+ return response.data.data
156
197
  },
157
198
  onSuccess: (_, variables) => {
158
- queryClient.invalidateQueries({ queryKey: postKeys.detail(variables.postId) });
199
+ queryClient.invalidateQueries({
200
+ queryKey: postKeys.detail(variables.postId),
201
+ })
159
202
  },
160
203
  ...options,
161
- });
204
+ })
162
205
  }
163
206
 
164
207
  /**
165
208
  * Delete a reply
166
209
  *
167
- * @endpoint DELETE /api/v1/replies/{replyId}
210
+ * @endpoint DELETE /replies/{replyId}
168
211
  */
169
212
  export function useDeleteReply(
170
- options?: Omit<UseMutationOptions<void, Error, { replyId: string; postId: string }>, 'mutationFn'>
171
- ): UseMutationResult<void, Error, { replyId: string; postId: string }> {
172
- const queryClient = useQueryClient();
213
+ options?: Omit<
214
+ UseMutationOptions<void, Error, {replyId: string; postId: string}>,
215
+ 'mutationFn'
216
+ >,
217
+ ): UseMutationResult<void, Error, {replyId: string; postId: string}> {
218
+ const queryClient = useQueryClient()
173
219
 
174
220
  return useMutation({
175
- mutationFn: async ({ replyId }): Promise<void> => {
176
- const client = getApiClient();
177
- await client.delete(`/api/v1/replies/${replyId}`);
221
+ mutationFn: async ({replyId}): Promise<void> => {
222
+ const client = getApiClient()
223
+ await client.delete(`/replies/${replyId}`)
178
224
  },
179
225
  onSuccess: (_, variables) => {
180
- queryClient.invalidateQueries({ queryKey: postKeys.detail(variables.postId) });
226
+ queryClient.invalidateQueries({
227
+ queryKey: postKeys.detail(variables.postId),
228
+ })
181
229
  },
182
230
  ...options,
183
- });
231
+ })
184
232
  }
185
233
 
186
234
  /**
187
235
  * Respond to a post (express interest)
188
236
  *
189
- * @endpoint POST /api/v1/posts/{postId}/respond
237
+ * @endpoint POST /posts/{postId}/respond
190
238
  */
191
239
  export function useRespondToPost(
192
- options?: Omit<UseMutationOptions<PostResponse, Error, { postId: string } & RespondToPostRequest>, 'mutationFn'>
193
- ): UseMutationResult<PostResponse, Error, { postId: string } & RespondToPostRequest> {
194
- const queryClient = useQueryClient();
240
+ options?: Omit<
241
+ UseMutationOptions<
242
+ PostResponse,
243
+ Error,
244
+ {postId: string} & RespondToPostRequest
245
+ >,
246
+ 'mutationFn'
247
+ >,
248
+ ): UseMutationResult<
249
+ PostResponse,
250
+ Error,
251
+ {postId: string} & RespondToPostRequest
252
+ > {
253
+ const queryClient = useQueryClient()
195
254
 
196
255
  return useMutation({
197
- mutationFn: async ({ postId, ...data }): Promise<PostResponse> => {
198
- const client = getApiClient();
199
- const response = await client.post<ApiResponse<PostResponse>>(`/api/v1/posts/${postId}/respond`, data);
200
- return response.data.data;
256
+ mutationFn: async ({postId, ...data}): Promise<PostResponse> => {
257
+ const client = getApiClient()
258
+ const response = await client.post<ApiResponse<PostResponse>>(
259
+ `/posts/${postId}/respond`,
260
+ data,
261
+ )
262
+ return response.data.data
201
263
  },
202
264
  onSuccess: (_, variables) => {
203
- queryClient.invalidateQueries({ queryKey: postKeys.detail(variables.postId) });
204
- queryClient.invalidateQueries({ queryKey: postKeys.responses(variables.postId) });
265
+ queryClient.invalidateQueries({
266
+ queryKey: postKeys.detail(variables.postId),
267
+ })
268
+ queryClient.invalidateQueries({
269
+ queryKey: postKeys.responses(variables.postId),
270
+ })
205
271
  },
206
272
  ...options,
207
- });
273
+ })
208
274
  }
209
275
 
210
276
  /**
211
277
  * Accept or decline a response
212
278
  *
213
- * @endpoint PUT /api/v1/responses/{responseId}
279
+ * @endpoint PUT /responses/{responseId}
214
280
  */
215
281
  export function useUpdateResponse(
216
- options?: Omit<UseMutationOptions<PostResponse, Error, { responseId: string; postId: string } & UpdateResponseRequest>, 'mutationFn'>
217
- ): UseMutationResult<PostResponse, Error, { responseId: string; postId: string } & UpdateResponseRequest> {
218
- const queryClient = useQueryClient();
282
+ options?: Omit<
283
+ UseMutationOptions<
284
+ PostResponse,
285
+ Error,
286
+ {responseId: string; postId: string} & UpdateResponseRequest
287
+ >,
288
+ 'mutationFn'
289
+ >,
290
+ ): UseMutationResult<
291
+ PostResponse,
292
+ Error,
293
+ {responseId: string; postId: string} & UpdateResponseRequest
294
+ > {
295
+ const queryClient = useQueryClient()
219
296
 
220
297
  return useMutation({
221
- mutationFn: async ({ responseId, postId: _, ...data }): Promise<PostResponse> => {
222
- const client = getApiClient();
223
- const response = await client.put<ApiResponse<PostResponse>>(`/api/v1/responses/${responseId}`, data);
224
- return response.data.data;
298
+ mutationFn: async ({
299
+ responseId,
300
+ postId: _,
301
+ ...data
302
+ }): Promise<PostResponse> => {
303
+ const client = getApiClient()
304
+ const response = await client.put<ApiResponse<PostResponse>>(
305
+ `/responses/${responseId}`,
306
+ data,
307
+ )
308
+ return response.data.data
225
309
  },
226
310
  onSuccess: (_, variables) => {
227
- queryClient.invalidateQueries({ queryKey: postKeys.responses(variables.postId) });
311
+ queryClient.invalidateQueries({
312
+ queryKey: postKeys.responses(variables.postId),
313
+ })
228
314
  },
229
315
  ...options,
230
- });
316
+ })
231
317
  }
232
318
 
233
319
  /**
234
320
  * Report a post
235
321
  *
236
- * @endpoint POST /api/v1/posts/{postId}/report
322
+ * @endpoint POST /posts/{postId}/report
237
323
  */
238
324
  export function useReportPost(
239
- options?: Omit<UseMutationOptions<void, Error, { postId: string; reason: string; details?: string }>, 'mutationFn'>
240
- ): UseMutationResult<void, Error, { postId: string; reason: string; details?: string }> {
325
+ options?: Omit<
326
+ UseMutationOptions<
327
+ void,
328
+ Error,
329
+ {postId: string; reason: string; details?: string}
330
+ >,
331
+ 'mutationFn'
332
+ >,
333
+ ): UseMutationResult<
334
+ void,
335
+ Error,
336
+ {postId: string; reason: string; details?: string}
337
+ > {
241
338
  return useMutation({
242
- mutationFn: async ({ postId, ...data }): Promise<void> => {
243
- const client = getApiClient();
244
- await client.post(`/api/v1/posts/${postId}/report`, data);
339
+ mutationFn: async ({postId, ...data}): Promise<void> => {
340
+ const client = getApiClient()
341
+ await client.post(`/posts/${postId}/report`, data)
245
342
  },
246
343
  ...options,
247
- });
344
+ })
248
345
  }
249
346
 
250
347
  // PostStatusUpdate matches partial PostStatusDto for updates
251
348
  interface PostStatusUpdate {
252
- isRead?: boolean;
253
- isHidden?: boolean;
254
- isPinned?: boolean;
349
+ isRead?: boolean
350
+ isHidden?: boolean
351
+ isPinned?: boolean
255
352
  }
256
353
 
257
354
  /**
258
355
  * Update user's status for a post (read/hidden/pinned)
259
356
  *
260
- * @endpoint PUT /api/v1/posts/{postId}/status
357
+ * @endpoint PUT /posts/{postId}/status
261
358
  */
262
359
  export function useUpdatePostStatus(
263
- options?: Omit<UseMutationOptions<PostStatusDto, Error, { postId: string } & PostStatusUpdate>, 'mutationFn'>
264
- ): UseMutationResult<PostStatusDto, Error, { postId: string } & PostStatusUpdate> {
265
- const queryClient = useQueryClient();
360
+ options?: Omit<
361
+ UseMutationOptions<
362
+ PostStatusDto,
363
+ Error,
364
+ {postId: string} & PostStatusUpdate
365
+ >,
366
+ 'mutationFn'
367
+ >,
368
+ ): UseMutationResult<
369
+ PostStatusDto,
370
+ Error,
371
+ {postId: string} & PostStatusUpdate
372
+ > {
373
+ const queryClient = useQueryClient()
266
374
 
267
375
  return useMutation({
268
- mutationFn: async ({ postId, ...data }): Promise<PostStatusDto> => {
269
- const client = getApiClient();
270
- const response = await client.put<ApiResponse<PostStatusDto>>(`/api/v1/posts/${postId}/status`, data);
271
- return response.data.data;
376
+ mutationFn: async ({postId, ...data}): Promise<PostStatusDto> => {
377
+ const client = getApiClient()
378
+ const response = await client.put<ApiResponse<PostStatusDto>>(
379
+ `/posts/${postId}/status`,
380
+ data,
381
+ )
382
+ return response.data.data
272
383
  },
273
384
  onSuccess: (data, variables) => {
274
- queryClient.setQueryData(postKeys.status(variables.postId), data);
385
+ queryClient.setQueryData(postKeys.status(variables.postId), data)
275
386
  },
276
387
  ...options,
277
- });
388
+ })
278
389
  }