@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,48 +4,53 @@
4
4
  * TanStack Query hooks for order mutation operations.
5
5
  */
6
6
 
7
- import { useMutation, useQueryClient, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
8
- import { getApiClient } from '../client';
9
- import { orderKeys, OrderWithDetails } from '../queries/orders';
10
- import { productKeys } from '../queries/products';
11
- import type { Order, OrderStatus, ApiResponse } from '../types';
7
+ import {
8
+ useMutation,
9
+ useQueryClient,
10
+ type UseMutationOptions,
11
+ type UseMutationResult,
12
+ } from '@tanstack/react-query'
13
+ import {getApiClient} from '../client'
14
+ import {orderKeys, type OrderWithDetails} from '../queries/orders'
15
+ import {productKeys} from '../queries/products'
16
+ import type {Order, OrderStatus, ApiResponse} from '../types'
12
17
 
13
18
  // ============================================================================
14
19
  // TYPES
15
20
  // ============================================================================
16
21
 
17
22
  export interface CartItem {
18
- productId: string;
19
- quantity: number;
23
+ productId: string
24
+ quantity: number
20
25
  }
21
26
 
22
27
  export interface CreateOrderRequest {
23
- spotId: string;
24
- items: CartItem[];
25
- notes?: string;
26
- deliveryAddress?: string;
28
+ spotId: string
29
+ items: CartItem[]
30
+ notes?: string
31
+ deliveryAddress?: string
27
32
  }
28
33
 
29
34
  export interface CreateOrderResponse extends Order {
30
35
  items: Array<{
31
- id: string;
32
- productId: string;
33
- productName: string;
34
- quantity: number;
35
- unitPrice: number;
36
- totalPrice: number;
37
- }>;
36
+ id: string
37
+ productId: string
38
+ productName: string
39
+ quantity: number
40
+ unitPrice: number
41
+ totalPrice: number
42
+ }>
38
43
  }
39
44
 
40
45
  export interface PaymentIntentResponse {
41
- clientSecret: string;
42
- paymentIntentId: string;
46
+ clientSecret: string
47
+ paymentIntentId: string
43
48
  }
44
49
 
45
50
  export interface CoinbaseChargeResponse {
46
- chargeId: string;
47
- chargeCode: string;
48
- hostedUrl: string;
51
+ chargeId: string
52
+ chargeCode: string
53
+ hostedUrl: string
49
54
  }
50
55
 
51
56
  // ============================================================================
@@ -55,120 +60,146 @@ export interface CoinbaseChargeResponse {
55
60
  /**
56
61
  * Create a new order
57
62
  *
58
- * @endpoint POST /api/v1/orders
63
+ * @endpoint POST /orders
59
64
  */
60
65
  export function useCreateOrder(
61
- options?: Omit<UseMutationOptions<CreateOrderResponse, Error, CreateOrderRequest>, 'mutationFn'>
66
+ options?: Omit<
67
+ UseMutationOptions<CreateOrderResponse, Error, CreateOrderRequest>,
68
+ 'mutationFn'
69
+ >,
62
70
  ): UseMutationResult<CreateOrderResponse, Error, CreateOrderRequest> {
63
- const queryClient = useQueryClient();
71
+ const queryClient = useQueryClient()
64
72
 
65
73
  return useMutation({
66
74
  mutationFn: async (data: CreateOrderRequest): Promise<CreateOrderResponse> => {
67
- const client = getApiClient();
68
- const response = await client.post<ApiResponse<CreateOrderResponse>>('/api/v1/orders', data);
69
- return response.data.data;
75
+ const client = getApiClient()
76
+ const response = await client.post<ApiResponse<CreateOrderResponse>>(
77
+ '/orders',
78
+ data,
79
+ )
80
+ return response.data.data
70
81
  },
71
82
  onSuccess: (_, variables) => {
72
83
  // Invalidate products to reflect updated stock
73
- queryClient.invalidateQueries({ queryKey: productKeys.bySpot(variables.spotId) });
84
+ queryClient.invalidateQueries({queryKey: productKeys.bySpot(variables.spotId)})
74
85
  // Invalidate my orders list
75
- queryClient.invalidateQueries({ queryKey: orderKeys.list({ my: true }) });
86
+ queryClient.invalidateQueries({queryKey: orderKeys.list({my: true})})
76
87
  },
77
88
  ...options,
78
- });
89
+ })
79
90
  }
80
91
 
81
92
  /**
82
93
  * Create Stripe PaymentIntent for an order
83
94
  *
84
- * @endpoint POST /api/v1/payments/stripe/intent/{orderId}
95
+ * @endpoint POST /payments/stripe/intent/{orderId}
85
96
  */
86
97
  export function useCreateStripeIntent(
87
- options?: Omit<UseMutationOptions<PaymentIntentResponse, Error, string>, 'mutationFn'>
98
+ options?: Omit<
99
+ UseMutationOptions<PaymentIntentResponse, Error, string>,
100
+ 'mutationFn'
101
+ >,
88
102
  ): UseMutationResult<PaymentIntentResponse, Error, string> {
89
103
  return useMutation({
90
104
  mutationFn: async (orderId: string): Promise<PaymentIntentResponse> => {
91
- const client = getApiClient();
105
+ const client = getApiClient()
92
106
  const response = await client.post<ApiResponse<PaymentIntentResponse>>(
93
- `/api/v1/payments/stripe/intent/${orderId}`
94
- );
95
- return response.data.data;
107
+ `/payments/stripe/intent/${orderId}`,
108
+ )
109
+ return response.data.data
96
110
  },
97
111
  ...options,
98
- });
112
+ })
99
113
  }
100
114
 
101
115
  /**
102
116
  * Create Coinbase Commerce charge for an order
103
117
  *
104
- * @endpoint POST /api/v1/payments/coinbase/charge/{orderId}
118
+ * @endpoint POST /payments/coinbase/charge/{orderId}
105
119
  */
106
120
  export function useCreateCoinbaseCharge(
107
- options?: Omit<UseMutationOptions<CoinbaseChargeResponse, Error, string>, 'mutationFn'>
121
+ options?: Omit<
122
+ UseMutationOptions<CoinbaseChargeResponse, Error, string>,
123
+ 'mutationFn'
124
+ >,
108
125
  ): UseMutationResult<CoinbaseChargeResponse, Error, string> {
109
126
  return useMutation({
110
127
  mutationFn: async (orderId: string): Promise<CoinbaseChargeResponse> => {
111
- const client = getApiClient();
128
+ const client = getApiClient()
112
129
  const response = await client.post<ApiResponse<CoinbaseChargeResponse>>(
113
- `/api/v1/payments/coinbase/charge/${orderId}`
114
- );
115
- return response.data.data;
130
+ `/payments/coinbase/charge/${orderId}`,
131
+ )
132
+ return response.data.data
116
133
  },
117
134
  ...options,
118
- });
135
+ })
119
136
  }
120
137
 
121
138
  /**
122
139
  * Update order status (seller action)
123
140
  *
124
- * @endpoint PUT /api/v1/orders/{orderId}/status
141
+ * @endpoint PUT /orders/{orderId}/status
125
142
  */
126
143
  export function useUpdateOrderStatus(
127
144
  options?: Omit<
128
- UseMutationOptions<OrderWithDetails, Error, { orderId: string; status: OrderStatus }>,
145
+ UseMutationOptions<
146
+ OrderWithDetails,
147
+ Error,
148
+ {orderId: string; status: OrderStatus}
149
+ >,
129
150
  'mutationFn'
130
- >
131
- ): UseMutationResult<OrderWithDetails, Error, { orderId: string; status: OrderStatus }> {
132
- const queryClient = useQueryClient();
151
+ >,
152
+ ): UseMutationResult<
153
+ OrderWithDetails,
154
+ Error,
155
+ {orderId: string; status: OrderStatus}
156
+ > {
157
+ const queryClient = useQueryClient()
133
158
 
134
159
  return useMutation({
135
- mutationFn: async ({ orderId, status }): Promise<OrderWithDetails> => {
136
- const client = getApiClient();
137
- const response = await client.put<ApiResponse<OrderWithDetails>>(`/api/v1/orders/${orderId}/status`, {
138
- status,
139
- });
140
- return response.data.data;
160
+ mutationFn: async ({orderId, status}): Promise<OrderWithDetails> => {
161
+ const client = getApiClient()
162
+ const response = await client.put<ApiResponse<OrderWithDetails>>(
163
+ `/orders/${orderId}/status`,
164
+ {status},
165
+ )
166
+ return response.data.data
141
167
  },
142
168
  onSuccess: (data) => {
143
- queryClient.setQueryData(orderKeys.detail(data.id), data);
144
- queryClient.invalidateQueries({ queryKey: orderKeys.spotOrders(data.spotId) });
169
+ queryClient.setQueryData(orderKeys.detail(data.id), data)
170
+ queryClient.invalidateQueries({queryKey: orderKeys.spotOrders(data.spotId)})
145
171
  },
146
172
  ...options,
147
- });
173
+ })
148
174
  }
149
175
 
150
176
  /**
151
177
  * Cancel an order (buyer action, only for pending orders)
152
178
  *
153
- * @endpoint POST /api/v1/orders/{orderId}/cancel
179
+ * @endpoint POST /orders/{orderId}/cancel
154
180
  */
155
181
  export function useCancelOrder(
156
- options?: Omit<UseMutationOptions<OrderWithDetails, Error, string>, 'mutationFn'>
182
+ options?: Omit<
183
+ UseMutationOptions<OrderWithDetails, Error, string>,
184
+ 'mutationFn'
185
+ >,
157
186
  ): UseMutationResult<OrderWithDetails, Error, string> {
158
- const queryClient = useQueryClient();
187
+ const queryClient = useQueryClient()
159
188
 
160
189
  return useMutation({
161
190
  mutationFn: async (orderId: string): Promise<OrderWithDetails> => {
162
- const client = getApiClient();
163
- const response = await client.post<ApiResponse<OrderWithDetails>>(`/api/v1/orders/${orderId}/cancel`);
164
- return response.data.data;
191
+ const client = getApiClient()
192
+ const response = await client.post<ApiResponse<OrderWithDetails>>(
193
+ `/orders/${orderId}/cancel`,
194
+ )
195
+ return response.data.data
165
196
  },
166
197
  onSuccess: (data) => {
167
- queryClient.setQueryData(orderKeys.detail(data.id), data);
168
- queryClient.invalidateQueries({ queryKey: orderKeys.list({ my: true }) });
198
+ queryClient.setQueryData(orderKeys.detail(data.id), data)
199
+ queryClient.invalidateQueries({queryKey: orderKeys.list({my: true})})
169
200
  // Restore stock
170
- queryClient.invalidateQueries({ queryKey: productKeys.bySpot(data.spotId) });
201
+ queryClient.invalidateQueries({queryKey: productKeys.bySpot(data.spotId)})
171
202
  },
172
203
  ...options,
173
- });
204
+ })
174
205
  }