@growsober/sdk 1.0.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.
- package/README.md +276 -0
- package/dist/__tests__/e2e.test.d.ts +7 -0
- package/dist/__tests__/e2e.test.js +472 -0
- package/dist/api/client.d.ts +11 -0
- package/dist/api/client.js +61 -0
- package/dist/api/mutations/admin.d.ts +167 -0
- package/dist/api/mutations/admin.js +326 -0
- package/dist/api/mutations/ambassadors.d.ts +52 -0
- package/dist/api/mutations/ambassadors.js +148 -0
- package/dist/api/mutations/auth.d.ts +267 -0
- package/dist/api/mutations/auth.js +332 -0
- package/dist/api/mutations/bookings.d.ts +59 -0
- package/dist/api/mutations/bookings.js +143 -0
- package/dist/api/mutations/event-chat.d.ts +35 -0
- package/dist/api/mutations/event-chat.js +147 -0
- package/dist/api/mutations/events.d.ts +87 -0
- package/dist/api/mutations/events.js +205 -0
- package/dist/api/mutations/grow90.d.ts +36 -0
- package/dist/api/mutations/grow90.js +132 -0
- package/dist/api/mutations/hubs.d.ts +111 -0
- package/dist/api/mutations/hubs.js +240 -0
- package/dist/api/mutations/index.d.ts +22 -0
- package/dist/api/mutations/index.js +39 -0
- package/dist/api/mutations/jack.d.ts +61 -0
- package/dist/api/mutations/jack.js +104 -0
- package/dist/api/mutations/library.d.ts +67 -0
- package/dist/api/mutations/library.js +168 -0
- package/dist/api/mutations/map.d.ts +153 -0
- package/dist/api/mutations/map.js +181 -0
- package/dist/api/mutations/matching.d.ts +130 -0
- package/dist/api/mutations/matching.js +204 -0
- package/dist/api/mutations/notifications.d.ts +63 -0
- package/dist/api/mutations/notifications.js +106 -0
- package/dist/api/mutations/offers.d.ts +26 -0
- package/dist/api/mutations/offers.js +47 -0
- package/dist/api/mutations/subscriptions.d.ts +127 -0
- package/dist/api/mutations/subscriptions.js +140 -0
- package/dist/api/mutations/support.d.ts +165 -0
- package/dist/api/mutations/support.js +307 -0
- package/dist/api/mutations/users.d.ts +211 -0
- package/dist/api/mutations/users.js +261 -0
- package/dist/api/queries/admin.d.ts +257 -0
- package/dist/api/queries/admin.js +320 -0
- package/dist/api/queries/ambassadors.d.ts +53 -0
- package/dist/api/queries/ambassadors.js +98 -0
- package/dist/api/queries/auth.d.ts +16 -0
- package/dist/api/queries/auth.js +25 -0
- package/dist/api/queries/bookings.d.ts +91 -0
- package/dist/api/queries/bookings.js +102 -0
- package/dist/api/queries/businesses.d.ts +212 -0
- package/dist/api/queries/businesses.js +154 -0
- package/dist/api/queries/event-chat.d.ts +19 -0
- package/dist/api/queries/event-chat.js +75 -0
- package/dist/api/queries/events.d.ts +322 -0
- package/dist/api/queries/events.js +221 -0
- package/dist/api/queries/grow90.d.ts +26 -0
- package/dist/api/queries/grow90.js +85 -0
- package/dist/api/queries/hubs.d.ts +165 -0
- package/dist/api/queries/hubs.js +143 -0
- package/dist/api/queries/index.d.ts +23 -0
- package/dist/api/queries/index.js +40 -0
- package/dist/api/queries/jack.d.ts +63 -0
- package/dist/api/queries/jack.js +92 -0
- package/dist/api/queries/library.d.ts +132 -0
- package/dist/api/queries/library.js +120 -0
- package/dist/api/queries/map.d.ts +216 -0
- package/dist/api/queries/map.js +278 -0
- package/dist/api/queries/matching.d.ts +136 -0
- package/dist/api/queries/matching.js +161 -0
- package/dist/api/queries/notifications.d.ts +78 -0
- package/dist/api/queries/notifications.js +88 -0
- package/dist/api/queries/offers.d.ts +91 -0
- package/dist/api/queries/offers.js +103 -0
- package/dist/api/queries/subscriptions.d.ts +56 -0
- package/dist/api/queries/subscriptions.js +73 -0
- package/dist/api/queries/support.d.ts +106 -0
- package/dist/api/queries/support.js +202 -0
- package/dist/api/queries/users.d.ts +293 -0
- package/dist/api/queries/users.js +370 -0
- package/dist/api/types.d.ts +464 -0
- package/dist/api/types.js +9 -0
- package/dist/hooks/useAuth.d.ts +5 -0
- package/dist/hooks/useAuth.js +39 -0
- package/dist/hooks/useUser.d.ts +43 -0
- package/dist/hooks/useUser.js +44 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +67 -0
- package/package.json +62 -0
- package/src/__tests__/e2e.test.ts +502 -0
- package/src/api/client.ts +71 -0
- package/src/api/mutations/admin.ts +531 -0
- package/src/api/mutations/ambassadors.ts +185 -0
- package/src/api/mutations/auth.ts +350 -0
- package/src/api/mutations/bookings.ts +190 -0
- package/src/api/mutations/event-chat.ts +177 -0
- package/src/api/mutations/events.ts +273 -0
- package/src/api/mutations/grow90.ts +169 -0
- package/src/api/mutations/hubs.ts +385 -0
- package/src/api/mutations/index.ts +23 -0
- package/src/api/mutations/jack.ts +130 -0
- package/src/api/mutations/library.ts +212 -0
- package/src/api/mutations/map.ts +230 -0
- package/src/api/mutations/matching.ts +271 -0
- package/src/api/mutations/notifications.ts +114 -0
- package/src/api/mutations/offers.ts +73 -0
- package/src/api/mutations/subscriptions.ts +162 -0
- package/src/api/mutations/support.ts +390 -0
- package/src/api/mutations/users.ts +271 -0
- package/src/api/queries/admin.ts +480 -0
- package/src/api/queries/ambassadors.ts +139 -0
- package/src/api/queries/auth.ts +24 -0
- package/src/api/queries/bookings.ts +135 -0
- package/src/api/queries/businesses.ts +203 -0
- package/src/api/queries/event-chat.ts +78 -0
- package/src/api/queries/events.ts +272 -0
- package/src/api/queries/grow90.ts +98 -0
- package/src/api/queries/hubs.ts +211 -0
- package/src/api/queries/index.ts +24 -0
- package/src/api/queries/jack.ts +127 -0
- package/src/api/queries/library.ts +166 -0
- package/src/api/queries/map.ts +331 -0
- package/src/api/queries/matching.ts +238 -0
- package/src/api/queries/notifications.ts +103 -0
- package/src/api/queries/offers.ts +136 -0
- package/src/api/queries/subscriptions.ts +91 -0
- package/src/api/queries/support.ts +235 -0
- package/src/api/queries/users.ts +393 -0
- package/src/api/types.ts +596 -0
- package/src/index.ts +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
# @growsober/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the GrowSober API with TanStack Query hooks.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @growsober/sdk @tanstack/react-query axios
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
15
|
+
import { configureSDK, useCurrentUser, useHubs, useEvents } from '@growsober/sdk';
|
|
16
|
+
|
|
17
|
+
// Configure SDK
|
|
18
|
+
configureSDK({
|
|
19
|
+
baseURL: 'https://api.growsober.app',
|
|
20
|
+
getAccessToken: () => localStorage.getItem('accessToken'),
|
|
21
|
+
refreshAccessToken: async () => {
|
|
22
|
+
// Your token refresh logic
|
|
23
|
+
const response = await fetch('/refresh');
|
|
24
|
+
const { accessToken } = await response.json();
|
|
25
|
+
localStorage.setItem('accessToken', accessToken);
|
|
26
|
+
return accessToken;
|
|
27
|
+
},
|
|
28
|
+
onUnauthorized: () => {
|
|
29
|
+
window.location.href = '/login';
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Create query client
|
|
34
|
+
const queryClient = new QueryClient();
|
|
35
|
+
|
|
36
|
+
// Use in app
|
|
37
|
+
function App() {
|
|
38
|
+
return (
|
|
39
|
+
<QueryClientProvider client={queryClient}>
|
|
40
|
+
<MyComponent />
|
|
41
|
+
</QueryClientProvider>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function MyComponent() {
|
|
46
|
+
const { data: user, isLoading } = useCurrentUser();
|
|
47
|
+
const { data: hubs } = useHubs();
|
|
48
|
+
|
|
49
|
+
if (isLoading) return <Loading />;
|
|
50
|
+
|
|
51
|
+
return <div>Welcome, {user?.name}</div>;
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Available Hooks
|
|
56
|
+
|
|
57
|
+
### Auth Hooks
|
|
58
|
+
```typescript
|
|
59
|
+
// Queries
|
|
60
|
+
useMe() // Get current auth user
|
|
61
|
+
|
|
62
|
+
// Mutations
|
|
63
|
+
useRegister() // Register new user
|
|
64
|
+
useLogin() // Login with credentials
|
|
65
|
+
useFirebaseAuth() // Login with Firebase token
|
|
66
|
+
useRefreshAuthToken() // Refresh access token
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### User Hooks
|
|
70
|
+
```typescript
|
|
71
|
+
// Queries
|
|
72
|
+
useCurrentUser() // Get current user profile
|
|
73
|
+
useUser(id) // Get user by ID
|
|
74
|
+
usePublicProfile(id) // Get public profile
|
|
75
|
+
useMyBookmarks() // Get bookmarked content
|
|
76
|
+
useMyRedeemedOffers() // Get redeemed offers
|
|
77
|
+
|
|
78
|
+
// Mutations
|
|
79
|
+
useUpdateCurrentUser() // Update profile
|
|
80
|
+
useCompleteOnboarding() // Complete onboarding
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Hub Hooks
|
|
84
|
+
```typescript
|
|
85
|
+
// Queries
|
|
86
|
+
useHubs(filters?) // List hubs with filters
|
|
87
|
+
useHub(id) // Get hub by ID
|
|
88
|
+
useHubBySlug(slug) // Get hub by slug
|
|
89
|
+
useMyHubs() // Get joined hubs
|
|
90
|
+
useHubMembers(id) // Get hub members
|
|
91
|
+
useHubMembership(id) // Check membership status
|
|
92
|
+
|
|
93
|
+
// Mutations
|
|
94
|
+
useCreateHub() // Create new hub
|
|
95
|
+
useUpdateHub() // Update hub
|
|
96
|
+
useDeleteHub() // Delete hub
|
|
97
|
+
useJoinHub() // Join hub
|
|
98
|
+
useLeaveHub() // Leave hub
|
|
99
|
+
useApproveMember() // Approve member
|
|
100
|
+
useUpdateMemberRole() // Update member role
|
|
101
|
+
useRemoveMember() // Remove member
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Event Hooks
|
|
105
|
+
```typescript
|
|
106
|
+
// Queries
|
|
107
|
+
useEvents(filters?) // List events
|
|
108
|
+
useEvent(id) // Get event by ID
|
|
109
|
+
useEventBySlug(slug) // Get event by slug
|
|
110
|
+
useUpcomingEvents() // Get upcoming events
|
|
111
|
+
useFeaturedEvents() // Get featured events
|
|
112
|
+
useEventBookings(id) // Get event attendees
|
|
113
|
+
|
|
114
|
+
// Mutations
|
|
115
|
+
useCreateEvent() // Create event
|
|
116
|
+
useUpdateEvent() // Update event
|
|
117
|
+
useDeleteEvent() // Delete event
|
|
118
|
+
useCancelEvent() // Cancel event
|
|
119
|
+
usePublishEvent() // Publish event
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Booking Hooks
|
|
123
|
+
```typescript
|
|
124
|
+
// Queries
|
|
125
|
+
useBooking(id) // Get booking
|
|
126
|
+
useMyBookings() // Get my bookings
|
|
127
|
+
useBookingQrCode(id) // Get QR code
|
|
128
|
+
|
|
129
|
+
// Mutations
|
|
130
|
+
useCreateBooking() // Book event (RSVP)
|
|
131
|
+
useCancelBooking() // Cancel booking
|
|
132
|
+
useCheckInBooking() // Check in at event
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Library Hooks
|
|
136
|
+
```typescript
|
|
137
|
+
// Queries
|
|
138
|
+
useLibraryContent(filters?) // List content
|
|
139
|
+
useFeaturedContent() // Featured content
|
|
140
|
+
useLibraryCategories() // Content categories
|
|
141
|
+
useLibraryItem(id) // Get content item
|
|
142
|
+
useMyProgress() // Get reading progress
|
|
143
|
+
|
|
144
|
+
// Mutations
|
|
145
|
+
useMarkViewed() // Mark as viewed
|
|
146
|
+
useMarkCompleted() // Mark as completed
|
|
147
|
+
useToggleLike() // Like/unlike content
|
|
148
|
+
useAddBookmark() // Add bookmark
|
|
149
|
+
useRemoveBookmark() // Remove bookmark
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Business & Offer Hooks
|
|
153
|
+
```typescript
|
|
154
|
+
// Queries
|
|
155
|
+
useBusinesses(filters?) // List businesses
|
|
156
|
+
useBusiness(id) // Get business
|
|
157
|
+
useFeaturedBusinesses() // Featured businesses
|
|
158
|
+
useNearbyBusinesses(lat, lng) // Nearby businesses
|
|
159
|
+
useBusinessOffers(id) // Get business offers
|
|
160
|
+
useOffers(filters?) // List offers
|
|
161
|
+
useOffer(id) // Get offer
|
|
162
|
+
useCanRedeemOffer(id) // Check redemption
|
|
163
|
+
|
|
164
|
+
// Mutations
|
|
165
|
+
useRedeemOffer() // Redeem offer
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Subscription Hooks
|
|
169
|
+
```typescript
|
|
170
|
+
// Queries
|
|
171
|
+
useSubscriptionPlans() // Available plans
|
|
172
|
+
useMySubscription() // Current subscription
|
|
173
|
+
|
|
174
|
+
// Mutations
|
|
175
|
+
useCreateCheckout() // Create Stripe checkout
|
|
176
|
+
useCustomerPortal() // Get portal URL
|
|
177
|
+
useCancelSubscription() // Cancel subscription
|
|
178
|
+
useResumeSubscription() // Resume subscription
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Notification Hooks
|
|
182
|
+
```typescript
|
|
183
|
+
// Queries
|
|
184
|
+
useNotifications() // List notifications
|
|
185
|
+
useUnreadNotificationCount() // Unread count
|
|
186
|
+
useNotification(id) // Get notification
|
|
187
|
+
|
|
188
|
+
// Mutations
|
|
189
|
+
useMarkNotificationRead() // Mark as read
|
|
190
|
+
useMarkAllNotificationsRead() // Mark all read
|
|
191
|
+
useDeleteNotification() // Delete notification
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Support Hooks
|
|
195
|
+
```typescript
|
|
196
|
+
// Queries
|
|
197
|
+
useCheckIns() // List check-ins
|
|
198
|
+
useTodayCheckIn() // Today's check-in
|
|
199
|
+
useCheckInStreak() // Current streak
|
|
200
|
+
useMoodLogs() // List mood logs
|
|
201
|
+
useWins() // List wins
|
|
202
|
+
useWinsByCategory() // Wins by category
|
|
203
|
+
useHabits() // List habits
|
|
204
|
+
useReflections() // List reflections
|
|
205
|
+
|
|
206
|
+
// Mutations
|
|
207
|
+
useCreateCheckIn() // Create check-in
|
|
208
|
+
useCreateMoodLog() // Log mood
|
|
209
|
+
useCreateWin() // Log win
|
|
210
|
+
useCreateHabit() // Create habit
|
|
211
|
+
useUpdateHabit() // Update habit
|
|
212
|
+
useDeleteHabit() // Delete habit
|
|
213
|
+
useCompleteHabit() // Complete habit
|
|
214
|
+
useCreateReflection() // Create reflection
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Query Key Factories
|
|
218
|
+
|
|
219
|
+
Each module exports query key factories for cache management:
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import { userKeys, hubKeys, eventKeys } from '@growsober/sdk';
|
|
223
|
+
|
|
224
|
+
// Invalidate all user queries
|
|
225
|
+
queryClient.invalidateQueries({ queryKey: userKeys.all });
|
|
226
|
+
|
|
227
|
+
// Invalidate specific hub
|
|
228
|
+
queryClient.invalidateQueries({ queryKey: hubKeys.detail('hub-id') });
|
|
229
|
+
|
|
230
|
+
// Prefetch events
|
|
231
|
+
queryClient.prefetchQuery({
|
|
232
|
+
queryKey: eventKeys.list(),
|
|
233
|
+
queryFn: () => fetchEvents(),
|
|
234
|
+
});
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Types
|
|
238
|
+
|
|
239
|
+
All types are re-exported from `@growsober/types`:
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
import type {
|
|
243
|
+
UserResponse,
|
|
244
|
+
HubResponse,
|
|
245
|
+
EventResponse,
|
|
246
|
+
BookingResponse,
|
|
247
|
+
// ... etc
|
|
248
|
+
} from '@growsober/sdk';
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Error Handling
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
const { mutate: createEvent, error } = useCreateEvent({
|
|
255
|
+
onError: (error) => {
|
|
256
|
+
console.error('Failed to create event:', error.message);
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Development
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
# Type check
|
|
265
|
+
npm run type-check
|
|
266
|
+
|
|
267
|
+
# Build
|
|
268
|
+
npm run build
|
|
269
|
+
|
|
270
|
+
# Watch mode
|
|
271
|
+
npm run build:watch
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## License
|
|
275
|
+
|
|
276
|
+
UNLICENSED - Proprietary
|