@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.
Files changed (129) hide show
  1. package/README.md +276 -0
  2. package/dist/__tests__/e2e.test.d.ts +7 -0
  3. package/dist/__tests__/e2e.test.js +472 -0
  4. package/dist/api/client.d.ts +11 -0
  5. package/dist/api/client.js +61 -0
  6. package/dist/api/mutations/admin.d.ts +167 -0
  7. package/dist/api/mutations/admin.js +326 -0
  8. package/dist/api/mutations/ambassadors.d.ts +52 -0
  9. package/dist/api/mutations/ambassadors.js +148 -0
  10. package/dist/api/mutations/auth.d.ts +267 -0
  11. package/dist/api/mutations/auth.js +332 -0
  12. package/dist/api/mutations/bookings.d.ts +59 -0
  13. package/dist/api/mutations/bookings.js +143 -0
  14. package/dist/api/mutations/event-chat.d.ts +35 -0
  15. package/dist/api/mutations/event-chat.js +147 -0
  16. package/dist/api/mutations/events.d.ts +87 -0
  17. package/dist/api/mutations/events.js +205 -0
  18. package/dist/api/mutations/grow90.d.ts +36 -0
  19. package/dist/api/mutations/grow90.js +132 -0
  20. package/dist/api/mutations/hubs.d.ts +111 -0
  21. package/dist/api/mutations/hubs.js +240 -0
  22. package/dist/api/mutations/index.d.ts +22 -0
  23. package/dist/api/mutations/index.js +39 -0
  24. package/dist/api/mutations/jack.d.ts +61 -0
  25. package/dist/api/mutations/jack.js +104 -0
  26. package/dist/api/mutations/library.d.ts +67 -0
  27. package/dist/api/mutations/library.js +168 -0
  28. package/dist/api/mutations/map.d.ts +153 -0
  29. package/dist/api/mutations/map.js +181 -0
  30. package/dist/api/mutations/matching.d.ts +130 -0
  31. package/dist/api/mutations/matching.js +204 -0
  32. package/dist/api/mutations/notifications.d.ts +63 -0
  33. package/dist/api/mutations/notifications.js +106 -0
  34. package/dist/api/mutations/offers.d.ts +26 -0
  35. package/dist/api/mutations/offers.js +47 -0
  36. package/dist/api/mutations/subscriptions.d.ts +127 -0
  37. package/dist/api/mutations/subscriptions.js +140 -0
  38. package/dist/api/mutations/support.d.ts +165 -0
  39. package/dist/api/mutations/support.js +307 -0
  40. package/dist/api/mutations/users.d.ts +211 -0
  41. package/dist/api/mutations/users.js +261 -0
  42. package/dist/api/queries/admin.d.ts +257 -0
  43. package/dist/api/queries/admin.js +320 -0
  44. package/dist/api/queries/ambassadors.d.ts +53 -0
  45. package/dist/api/queries/ambassadors.js +98 -0
  46. package/dist/api/queries/auth.d.ts +16 -0
  47. package/dist/api/queries/auth.js +25 -0
  48. package/dist/api/queries/bookings.d.ts +91 -0
  49. package/dist/api/queries/bookings.js +102 -0
  50. package/dist/api/queries/businesses.d.ts +212 -0
  51. package/dist/api/queries/businesses.js +154 -0
  52. package/dist/api/queries/event-chat.d.ts +19 -0
  53. package/dist/api/queries/event-chat.js +75 -0
  54. package/dist/api/queries/events.d.ts +322 -0
  55. package/dist/api/queries/events.js +221 -0
  56. package/dist/api/queries/grow90.d.ts +26 -0
  57. package/dist/api/queries/grow90.js +85 -0
  58. package/dist/api/queries/hubs.d.ts +165 -0
  59. package/dist/api/queries/hubs.js +143 -0
  60. package/dist/api/queries/index.d.ts +23 -0
  61. package/dist/api/queries/index.js +40 -0
  62. package/dist/api/queries/jack.d.ts +63 -0
  63. package/dist/api/queries/jack.js +92 -0
  64. package/dist/api/queries/library.d.ts +132 -0
  65. package/dist/api/queries/library.js +120 -0
  66. package/dist/api/queries/map.d.ts +216 -0
  67. package/dist/api/queries/map.js +278 -0
  68. package/dist/api/queries/matching.d.ts +136 -0
  69. package/dist/api/queries/matching.js +161 -0
  70. package/dist/api/queries/notifications.d.ts +78 -0
  71. package/dist/api/queries/notifications.js +88 -0
  72. package/dist/api/queries/offers.d.ts +91 -0
  73. package/dist/api/queries/offers.js +103 -0
  74. package/dist/api/queries/subscriptions.d.ts +56 -0
  75. package/dist/api/queries/subscriptions.js +73 -0
  76. package/dist/api/queries/support.d.ts +106 -0
  77. package/dist/api/queries/support.js +202 -0
  78. package/dist/api/queries/users.d.ts +293 -0
  79. package/dist/api/queries/users.js +370 -0
  80. package/dist/api/types.d.ts +464 -0
  81. package/dist/api/types.js +9 -0
  82. package/dist/hooks/useAuth.d.ts +5 -0
  83. package/dist/hooks/useAuth.js +39 -0
  84. package/dist/hooks/useUser.d.ts +43 -0
  85. package/dist/hooks/useUser.js +44 -0
  86. package/dist/index.d.ts +36 -0
  87. package/dist/index.js +67 -0
  88. package/package.json +62 -0
  89. package/src/__tests__/e2e.test.ts +502 -0
  90. package/src/api/client.ts +71 -0
  91. package/src/api/mutations/admin.ts +531 -0
  92. package/src/api/mutations/ambassadors.ts +185 -0
  93. package/src/api/mutations/auth.ts +350 -0
  94. package/src/api/mutations/bookings.ts +190 -0
  95. package/src/api/mutations/event-chat.ts +177 -0
  96. package/src/api/mutations/events.ts +273 -0
  97. package/src/api/mutations/grow90.ts +169 -0
  98. package/src/api/mutations/hubs.ts +385 -0
  99. package/src/api/mutations/index.ts +23 -0
  100. package/src/api/mutations/jack.ts +130 -0
  101. package/src/api/mutations/library.ts +212 -0
  102. package/src/api/mutations/map.ts +230 -0
  103. package/src/api/mutations/matching.ts +271 -0
  104. package/src/api/mutations/notifications.ts +114 -0
  105. package/src/api/mutations/offers.ts +73 -0
  106. package/src/api/mutations/subscriptions.ts +162 -0
  107. package/src/api/mutations/support.ts +390 -0
  108. package/src/api/mutations/users.ts +271 -0
  109. package/src/api/queries/admin.ts +480 -0
  110. package/src/api/queries/ambassadors.ts +139 -0
  111. package/src/api/queries/auth.ts +24 -0
  112. package/src/api/queries/bookings.ts +135 -0
  113. package/src/api/queries/businesses.ts +203 -0
  114. package/src/api/queries/event-chat.ts +78 -0
  115. package/src/api/queries/events.ts +272 -0
  116. package/src/api/queries/grow90.ts +98 -0
  117. package/src/api/queries/hubs.ts +211 -0
  118. package/src/api/queries/index.ts +24 -0
  119. package/src/api/queries/jack.ts +127 -0
  120. package/src/api/queries/library.ts +166 -0
  121. package/src/api/queries/map.ts +331 -0
  122. package/src/api/queries/matching.ts +238 -0
  123. package/src/api/queries/notifications.ts +103 -0
  124. package/src/api/queries/offers.ts +136 -0
  125. package/src/api/queries/subscriptions.ts +91 -0
  126. package/src/api/queries/support.ts +235 -0
  127. package/src/api/queries/users.ts +393 -0
  128. package/src/api/types.ts +596 -0
  129. package/src/index.ts +57 -0
@@ -0,0 +1,114 @@
1
+ import { useMutation, useQueryClient, UseMutationOptions } from '@tanstack/react-query';
2
+ import { getApiClient } from '../client';
3
+ import { notificationKeys } from '../queries/notifications';
4
+ import type { NotificationResponse } from '../types';
5
+
6
+ // ============================================================================
7
+ // MUTATION HOOKS
8
+ // ============================================================================
9
+
10
+ /**
11
+ * Mark a notification as read
12
+ *
13
+ * @param options - TanStack Query mutation options
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * const { mutate: markAsRead } = useMarkNotificationRead();
18
+ *
19
+ * const handleNotificationClick = (notificationId: string) => {
20
+ * markAsRead(notificationId);
21
+ * };
22
+ * ```
23
+ */
24
+ export function useMarkNotificationRead(
25
+ options?: Omit<UseMutationOptions<NotificationResponse, Error, string>, 'mutationFn'>
26
+ ) {
27
+ const queryClient = useQueryClient();
28
+
29
+ return useMutation({
30
+ mutationFn: async (id: string): Promise<NotificationResponse> => {
31
+ const client = getApiClient();
32
+ const response = await client.patch(`/api/v1/notifications/${id}/read`);
33
+ return response.data;
34
+ },
35
+ onSuccess: (data, id, context) => {
36
+ // Update notification in cache
37
+ queryClient.setQueryData(notificationKeys.detail(id), data);
38
+ // Invalidate lists to refetch
39
+ queryClient.invalidateQueries({ queryKey: notificationKeys.list() });
40
+ queryClient.invalidateQueries({ queryKey: notificationKeys.unreadCount() });
41
+ // User's onSuccess is handled by spreading options
42
+ },
43
+ ...options,
44
+ });
45
+ }
46
+
47
+ /**
48
+ * Mark all notifications as read
49
+ *
50
+ * @param options - TanStack Query mutation options
51
+ *
52
+ * @example
53
+ * ```tsx
54
+ * const { mutate: markAllRead, isPending } = useMarkAllNotificationsRead();
55
+ *
56
+ * const handleMarkAllRead = () => {
57
+ * markAllRead();
58
+ * };
59
+ * ```
60
+ */
61
+ export function useMarkAllNotificationsRead(
62
+ options?: Omit<UseMutationOptions<void, Error, void>, 'mutationFn'>
63
+ ) {
64
+ const queryClient = useQueryClient();
65
+
66
+ return useMutation({
67
+ mutationFn: async (): Promise<void> => {
68
+ const client = getApiClient();
69
+ await client.patch('/api/v1/notifications/read-all');
70
+ },
71
+ onSuccess: (data, variables, context) => {
72
+ // Invalidate all notification queries
73
+ queryClient.invalidateQueries({ queryKey: notificationKeys.all });
74
+ // User's onSuccess is handled by spreading options
75
+ },
76
+ ...options,
77
+ });
78
+ }
79
+
80
+ /**
81
+ * Delete a notification
82
+ *
83
+ * @param options - TanStack Query mutation options
84
+ *
85
+ * @example
86
+ * ```tsx
87
+ * const { mutate: deleteNotification } = useDeleteNotification();
88
+ *
89
+ * const handleDelete = (notificationId: string) => {
90
+ * deleteNotification(notificationId);
91
+ * };
92
+ * ```
93
+ */
94
+ export function useDeleteNotification(
95
+ options?: Omit<UseMutationOptions<void, Error, string>, 'mutationFn'>
96
+ ) {
97
+ const queryClient = useQueryClient();
98
+
99
+ return useMutation({
100
+ mutationFn: async (id: string): Promise<void> => {
101
+ const client = getApiClient();
102
+ await client.delete(`/api/v1/notifications/${id}`);
103
+ },
104
+ onSuccess: (data, id, context) => {
105
+ // Remove from cache
106
+ queryClient.removeQueries({ queryKey: notificationKeys.detail(id) });
107
+ // Invalidate lists to refetch
108
+ queryClient.invalidateQueries({ queryKey: notificationKeys.list() });
109
+ queryClient.invalidateQueries({ queryKey: notificationKeys.unreadCount() });
110
+ // User's onSuccess is handled by spreading options
111
+ },
112
+ ...options,
113
+ });
114
+ }
@@ -0,0 +1,73 @@
1
+ import {
2
+ useMutation,
3
+ useQueryClient,
4
+ UseMutationOptions,
5
+ UseMutationResult,
6
+ } from '@tanstack/react-query';
7
+ import { getApiClient } from '../client';
8
+ import type { OfferResponse, RedeemOfferRequest } from '../types';
9
+ import { offerKeys } from '../queries/offers';
10
+
11
+ // ============================================================================
12
+ // MUTATION HOOKS
13
+ // ============================================================================
14
+
15
+ /**
16
+ * Redeem an offer
17
+ *
18
+ * @param options - TanStack Query mutation options
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * const { mutate, isPending } = useRedeemOffer();
23
+ *
24
+ * mutate({
25
+ * id: 'offer-123',
26
+ * data: {
27
+ * // Add any required fields from RedeemOfferRequest
28
+ * }
29
+ * });
30
+ * ```
31
+ */
32
+ export function useRedeemOffer(
33
+ options?: Omit<
34
+ UseMutationOptions<
35
+ OfferResponse,
36
+ Error,
37
+ { id: string; data?: RedeemOfferRequest }
38
+ >,
39
+ 'mutationFn'
40
+ >
41
+ ): UseMutationResult<OfferResponse, Error, { id: string; data?: RedeemOfferRequest }> {
42
+ const queryClient = useQueryClient();
43
+
44
+ return useMutation({
45
+ mutationFn: async ({
46
+ id,
47
+ data,
48
+ }: {
49
+ id: string;
50
+ data?: RedeemOfferRequest;
51
+ }): Promise<OfferResponse> => {
52
+ const client = getApiClient();
53
+ const response = await client.post(`/api/v1/offers/${id}/redeem`, data);
54
+ return response.data;
55
+ },
56
+ onSuccess: (redeemedOffer, variables, context) => {
57
+ // Update the specific offer in cache
58
+ queryClient.setQueryData(
59
+ offerKeys.detail(variables.id),
60
+ redeemedOffer
61
+ );
62
+
63
+ // Invalidate the can-redeem check for this offer
64
+ queryClient.invalidateQueries({ queryKey: offerKeys.canRedeem(variables.id) });
65
+
66
+ // Invalidate offer lists to reflect redemption counts
67
+ queryClient.invalidateQueries({ queryKey: offerKeys.lists() });
68
+
69
+ // Call user's onSuccess if provided
70
+ },
71
+ ...options,
72
+ });
73
+ }
@@ -0,0 +1,162 @@
1
+ import { useMutation, useQueryClient, UseMutationOptions } from '@tanstack/react-query';
2
+ import { getApiClient } from '../client';
3
+ import { subscriptionKeys } from '../queries/subscriptions';
4
+ import type { CreateCheckoutRequest, SubscriptionResponse } from '../types';
5
+
6
+ // ============================================================================
7
+ // TYPES
8
+ // ============================================================================
9
+
10
+ export interface CheckoutSession {
11
+ sessionId: string;
12
+ url: string;
13
+ }
14
+
15
+ export interface CustomerPortalSession {
16
+ url: string;
17
+ }
18
+
19
+ // ============================================================================
20
+ // MUTATION HOOKS
21
+ // ============================================================================
22
+
23
+ /**
24
+ * Create a Stripe checkout session for subscription
25
+ *
26
+ * @param options - TanStack Query mutation options
27
+ *
28
+ * @example
29
+ * ```tsx
30
+ * const { mutate: createCheckout, isPending } = useCreateCheckout();
31
+ *
32
+ * const handleUpgrade = () => {
33
+ * createCheckout(
34
+ * { tier: 'PREMIUM', successUrl: '/success', cancelUrl: '/cancel' },
35
+ * {
36
+ * onSuccess: (session) => {
37
+ * window.location.href = session.url;
38
+ * },
39
+ * }
40
+ * );
41
+ * };
42
+ * ```
43
+ */
44
+ export function useCreateCheckout(
45
+ options?: Omit<UseMutationOptions<CheckoutSession, Error, CreateCheckoutRequest>, 'mutationFn'>
46
+ ) {
47
+ return useMutation({
48
+ mutationFn: async (data: CreateCheckoutRequest): Promise<CheckoutSession> => {
49
+ const client = getApiClient();
50
+ const response = await client.post('/api/v1/subscriptions/checkout', data);
51
+ return response.data;
52
+ },
53
+ ...options,
54
+ });
55
+ }
56
+
57
+ /**
58
+ * Get Stripe customer portal URL for managing subscription
59
+ *
60
+ * @param options - TanStack Query mutation options
61
+ *
62
+ * @example
63
+ * ```tsx
64
+ * const { mutate: getPortal, isPending } = useCustomerPortal();
65
+ *
66
+ * const handleManageSubscription = () => {
67
+ * getPortal(undefined, {
68
+ * onSuccess: (session) => {
69
+ * window.location.href = session.url;
70
+ * },
71
+ * });
72
+ * };
73
+ * ```
74
+ */
75
+ export function useCustomerPortal(
76
+ options?: Omit<UseMutationOptions<CustomerPortalSession, Error, void>, 'mutationFn'>
77
+ ) {
78
+ return useMutation({
79
+ mutationFn: async (): Promise<CustomerPortalSession> => {
80
+ const client = getApiClient();
81
+ const response = await client.post('/api/v1/subscriptions/portal');
82
+ return response.data;
83
+ },
84
+ ...options,
85
+ });
86
+ }
87
+
88
+ /**
89
+ * Cancel current subscription
90
+ *
91
+ * @param options - TanStack Query mutation options
92
+ *
93
+ * @example
94
+ * ```tsx
95
+ * const { mutate: cancelSubscription, isPending } = useCancelSubscription();
96
+ *
97
+ * const handleCancel = () => {
98
+ * cancelSubscription(undefined, {
99
+ * onSuccess: () => {
100
+ * // Subscription will be cancelled at period end
101
+ * },
102
+ * });
103
+ * };
104
+ * ```
105
+ */
106
+ export function useCancelSubscription(
107
+ options?: Omit<UseMutationOptions<SubscriptionResponse, Error, void>, 'mutationFn'>
108
+ ) {
109
+ const queryClient = useQueryClient();
110
+
111
+ return useMutation({
112
+ mutationFn: async (): Promise<SubscriptionResponse> => {
113
+ const client = getApiClient();
114
+ const response = await client.post('/api/v1/subscriptions/cancel');
115
+ return response.data;
116
+ },
117
+ onSuccess: (data, variables, context) => {
118
+ // Update subscription in cache
119
+ queryClient.setQueryData(subscriptionKeys.mine(), data);
120
+ // User's onSuccess is handled by spreading options
121
+ },
122
+ ...options,
123
+ });
124
+ }
125
+
126
+ /**
127
+ * Resume a cancelled subscription (before period end)
128
+ *
129
+ * @param options - TanStack Query mutation options
130
+ *
131
+ * @example
132
+ * ```tsx
133
+ * const { mutate: resumeSubscription, isPending } = useResumeSubscription();
134
+ *
135
+ * const handleResume = () => {
136
+ * resumeSubscription(undefined, {
137
+ * onSuccess: () => {
138
+ * // Subscription resumed
139
+ * },
140
+ * });
141
+ * };
142
+ * ```
143
+ */
144
+ export function useResumeSubscription(
145
+ options?: Omit<UseMutationOptions<SubscriptionResponse, Error, void>, 'mutationFn'>
146
+ ) {
147
+ const queryClient = useQueryClient();
148
+
149
+ return useMutation({
150
+ mutationFn: async (): Promise<SubscriptionResponse> => {
151
+ const client = getApiClient();
152
+ const response = await client.post('/api/v1/subscriptions/resume');
153
+ return response.data;
154
+ },
155
+ onSuccess: (data, variables, context) => {
156
+ // Update subscription in cache
157
+ queryClient.setQueryData(subscriptionKeys.mine(), data);
158
+ // User's onSuccess is handled by spreading options
159
+ },
160
+ ...options,
161
+ });
162
+ }