@githat/nextjs 0.2.1 → 0.3.1

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.d.mts CHANGED
@@ -22,6 +22,17 @@ interface GitHatConfig {
22
22
  signUpUrl?: string;
23
23
  afterSignInUrl?: string;
24
24
  afterSignOutUrl?: string;
25
+ /**
26
+ * Token storage mode:
27
+ * - 'localStorage' (default): Tokens stored in browser localStorage
28
+ * - 'cookie': Tokens stored in httpOnly cookies (more secure, XSS-resistant)
29
+ *
30
+ * When using 'cookie' mode:
31
+ * - Login/refresh automatically set httpOnly cookies
32
+ * - SDK reads auth state from cookies (server-side)
33
+ * - Better for apps with server-side rendering
34
+ */
35
+ tokenStorage?: 'localStorage' | 'cookie';
25
36
  }
26
37
  interface AuthState {
27
38
  user: GitHatUser | null;
@@ -56,9 +67,12 @@ interface GitHatProviderProps {
56
67
  }
57
68
  declare function GitHatProvider({ config: rawConfig, children }: GitHatProviderProps): react_jsx_runtime.JSX.Element;
58
69
 
70
+ interface OrgMetadata$1 {
71
+ [key: string]: unknown;
72
+ }
59
73
  declare function useAuth(): GitHatContextValue;
60
74
  declare function useGitHat(): {
61
- fetch: <T = any>(endpoint: string, options?: RequestInit) => Promise<T>;
75
+ fetch: <T = unknown>(endpoint: string, fetchOptions?: RequestInit) => Promise<T>;
62
76
  getUserOrgs: () => Promise<{
63
77
  orgs: GitHatOrg[];
64
78
  }>;
@@ -68,6 +82,101 @@ declare function useGitHat(): {
68
82
  verifyAgent: (wallet: string) => Promise<{
69
83
  verified: boolean;
70
84
  }>;
85
+ getOrgMetadata: () => Promise<OrgMetadata$1>;
86
+ updateOrgMetadata: (updates: OrgMetadata$1) => Promise<OrgMetadata$1>;
87
+ };
88
+
89
+ interface DataItem {
90
+ id: string;
91
+ [key: string]: unknown;
92
+ _createdAt?: string;
93
+ _updatedAt?: string;
94
+ }
95
+ interface QueryOptions {
96
+ limit?: number;
97
+ cursor?: string;
98
+ filter?: Record<string, unknown>;
99
+ }
100
+ interface QueryResult<T = DataItem> {
101
+ items: T[];
102
+ collection: string;
103
+ nextCursor: string | null;
104
+ count: number;
105
+ }
106
+ interface PutResult<T = DataItem> {
107
+ item: T;
108
+ collection: string;
109
+ created: boolean;
110
+ }
111
+ interface DeleteResult {
112
+ deleted: boolean;
113
+ id: string;
114
+ collection: string;
115
+ }
116
+ interface BatchOperation {
117
+ type: 'put' | 'delete';
118
+ id: string;
119
+ data?: Record<string, unknown>;
120
+ }
121
+ interface BatchResult {
122
+ processed: number;
123
+ put: number;
124
+ deleted: number;
125
+ collection: string;
126
+ }
127
+ /**
128
+ * Hook for interacting with GitHat's Customer Data API.
129
+ * Provides CRUD operations for storing app data in GitHat's managed DynamoDB.
130
+ *
131
+ * @example
132
+ * ```tsx
133
+ * const { put, get, query, remove, batch } = useData();
134
+ *
135
+ * // Store data
136
+ * await put('orders', { id: 'order_123', amount: 99.99, status: 'pending' });
137
+ *
138
+ * // Get single item
139
+ * const order = await get('orders', 'order_123');
140
+ *
141
+ * // Query collection
142
+ * const { items } = await query('orders', { filter: { status: 'pending' } });
143
+ *
144
+ * // Delete item
145
+ * await remove('orders', 'order_123');
146
+ * ```
147
+ */
148
+ declare function useData(): {
149
+ /**
150
+ * Store an item in a collection. If the item exists, it will be updated.
151
+ * @param collection - Collection name (e.g., 'orders', 'users')
152
+ * @param data - Data object with required `id` field
153
+ */
154
+ put: <T extends DataItem>(collection: string, data: T) => Promise<PutResult<T>>;
155
+ /**
156
+ * Get a single item from a collection.
157
+ * @param collection - Collection name
158
+ * @param id - Item ID
159
+ */
160
+ get: <T extends DataItem>(collection: string, id: string) => Promise<T | null>;
161
+ /**
162
+ * Query items from a collection with optional filters and pagination.
163
+ * @param collection - Collection name
164
+ * @param options - Query options (limit, cursor, filter)
165
+ */
166
+ query: <T extends DataItem>(collection: string, options?: QueryOptions) => Promise<QueryResult<T>>;
167
+ /**
168
+ * Delete an item from a collection.
169
+ * @param collection - Collection name
170
+ * @param id - Item ID
171
+ */
172
+ remove: (collection: string, id: string) => Promise<DeleteResult>;
173
+ /**
174
+ * Batch operations (put/delete) on a collection.
175
+ * Maximum 100 operations per request.
176
+ * @param collection - Collection name
177
+ * @param operations - Array of operations
178
+ */
179
+ batch: (collection: string, operations: BatchOperation[]) => Promise<BatchResult>;
71
180
  };
72
181
 
73
182
  interface SignInFormProps {
@@ -117,4 +226,34 @@ interface ProtectedRouteProps {
117
226
  }
118
227
  declare function ProtectedRoute({ children, fallback }: ProtectedRouteProps): react_jsx_runtime.JSX.Element | null;
119
228
 
120
- export { type AuthActions, type AuthState, type GitHatConfig, type GitHatContextValue, type GitHatOrg, GitHatProvider, type GitHatUser, OrgSwitcher, ProtectedRoute, SignInButton, SignInForm, SignUpButton, type SignUpData, SignUpForm, type SignUpResult, UserButton, VerifiedBadge, useAuth, useGitHat };
229
+ /**
230
+ * @githat/nextjs/server
231
+ *
232
+ * Server-side utilities for token verification in Next.js API routes and middleware.
233
+ * This module runs on the server only — do not import in client components.
234
+ */
235
+ interface AuthPayload {
236
+ userId: string;
237
+ email: string;
238
+ orgId: string | null;
239
+ orgSlug: string | null;
240
+ role: 'owner' | 'admin' | 'member' | null;
241
+ tier: 'free' | 'basic' | 'pro' | 'enterprise' | null;
242
+ }
243
+ interface VerifyOptions {
244
+ /**
245
+ * Secret key for local JWT verification. If provided, tokens are verified
246
+ * locally without making an API call (~1ms vs ~50-100ms).
247
+ * Must match the JWT_SECRET used by the GitHat backend.
248
+ */
249
+ secretKey?: string;
250
+ /**
251
+ * API URL for remote token verification. Defaults to https://api.githat.io
252
+ */
253
+ apiUrl?: string;
254
+ }
255
+ interface OrgMetadata {
256
+ [key: string]: unknown;
257
+ }
258
+
259
+ export { type AuthActions, type AuthPayload, type AuthState, type BatchOperation, type BatchResult, type DataItem, type DeleteResult, type GitHatConfig, type GitHatContextValue, type GitHatOrg, GitHatProvider, type GitHatUser, type OrgMetadata, OrgSwitcher, ProtectedRoute, type PutResult, type QueryOptions, type QueryResult, SignInButton, SignInForm, SignUpButton, type SignUpData, SignUpForm, type SignUpResult, UserButton, VerifiedBadge, type VerifyOptions, useAuth, useData, useGitHat };
package/dist/index.d.ts CHANGED
@@ -22,6 +22,17 @@ interface GitHatConfig {
22
22
  signUpUrl?: string;
23
23
  afterSignInUrl?: string;
24
24
  afterSignOutUrl?: string;
25
+ /**
26
+ * Token storage mode:
27
+ * - 'localStorage' (default): Tokens stored in browser localStorage
28
+ * - 'cookie': Tokens stored in httpOnly cookies (more secure, XSS-resistant)
29
+ *
30
+ * When using 'cookie' mode:
31
+ * - Login/refresh automatically set httpOnly cookies
32
+ * - SDK reads auth state from cookies (server-side)
33
+ * - Better for apps with server-side rendering
34
+ */
35
+ tokenStorage?: 'localStorage' | 'cookie';
25
36
  }
26
37
  interface AuthState {
27
38
  user: GitHatUser | null;
@@ -56,9 +67,12 @@ interface GitHatProviderProps {
56
67
  }
57
68
  declare function GitHatProvider({ config: rawConfig, children }: GitHatProviderProps): react_jsx_runtime.JSX.Element;
58
69
 
70
+ interface OrgMetadata$1 {
71
+ [key: string]: unknown;
72
+ }
59
73
  declare function useAuth(): GitHatContextValue;
60
74
  declare function useGitHat(): {
61
- fetch: <T = any>(endpoint: string, options?: RequestInit) => Promise<T>;
75
+ fetch: <T = unknown>(endpoint: string, fetchOptions?: RequestInit) => Promise<T>;
62
76
  getUserOrgs: () => Promise<{
63
77
  orgs: GitHatOrg[];
64
78
  }>;
@@ -68,6 +82,101 @@ declare function useGitHat(): {
68
82
  verifyAgent: (wallet: string) => Promise<{
69
83
  verified: boolean;
70
84
  }>;
85
+ getOrgMetadata: () => Promise<OrgMetadata$1>;
86
+ updateOrgMetadata: (updates: OrgMetadata$1) => Promise<OrgMetadata$1>;
87
+ };
88
+
89
+ interface DataItem {
90
+ id: string;
91
+ [key: string]: unknown;
92
+ _createdAt?: string;
93
+ _updatedAt?: string;
94
+ }
95
+ interface QueryOptions {
96
+ limit?: number;
97
+ cursor?: string;
98
+ filter?: Record<string, unknown>;
99
+ }
100
+ interface QueryResult<T = DataItem> {
101
+ items: T[];
102
+ collection: string;
103
+ nextCursor: string | null;
104
+ count: number;
105
+ }
106
+ interface PutResult<T = DataItem> {
107
+ item: T;
108
+ collection: string;
109
+ created: boolean;
110
+ }
111
+ interface DeleteResult {
112
+ deleted: boolean;
113
+ id: string;
114
+ collection: string;
115
+ }
116
+ interface BatchOperation {
117
+ type: 'put' | 'delete';
118
+ id: string;
119
+ data?: Record<string, unknown>;
120
+ }
121
+ interface BatchResult {
122
+ processed: number;
123
+ put: number;
124
+ deleted: number;
125
+ collection: string;
126
+ }
127
+ /**
128
+ * Hook for interacting with GitHat's Customer Data API.
129
+ * Provides CRUD operations for storing app data in GitHat's managed DynamoDB.
130
+ *
131
+ * @example
132
+ * ```tsx
133
+ * const { put, get, query, remove, batch } = useData();
134
+ *
135
+ * // Store data
136
+ * await put('orders', { id: 'order_123', amount: 99.99, status: 'pending' });
137
+ *
138
+ * // Get single item
139
+ * const order = await get('orders', 'order_123');
140
+ *
141
+ * // Query collection
142
+ * const { items } = await query('orders', { filter: { status: 'pending' } });
143
+ *
144
+ * // Delete item
145
+ * await remove('orders', 'order_123');
146
+ * ```
147
+ */
148
+ declare function useData(): {
149
+ /**
150
+ * Store an item in a collection. If the item exists, it will be updated.
151
+ * @param collection - Collection name (e.g., 'orders', 'users')
152
+ * @param data - Data object with required `id` field
153
+ */
154
+ put: <T extends DataItem>(collection: string, data: T) => Promise<PutResult<T>>;
155
+ /**
156
+ * Get a single item from a collection.
157
+ * @param collection - Collection name
158
+ * @param id - Item ID
159
+ */
160
+ get: <T extends DataItem>(collection: string, id: string) => Promise<T | null>;
161
+ /**
162
+ * Query items from a collection with optional filters and pagination.
163
+ * @param collection - Collection name
164
+ * @param options - Query options (limit, cursor, filter)
165
+ */
166
+ query: <T extends DataItem>(collection: string, options?: QueryOptions) => Promise<QueryResult<T>>;
167
+ /**
168
+ * Delete an item from a collection.
169
+ * @param collection - Collection name
170
+ * @param id - Item ID
171
+ */
172
+ remove: (collection: string, id: string) => Promise<DeleteResult>;
173
+ /**
174
+ * Batch operations (put/delete) on a collection.
175
+ * Maximum 100 operations per request.
176
+ * @param collection - Collection name
177
+ * @param operations - Array of operations
178
+ */
179
+ batch: (collection: string, operations: BatchOperation[]) => Promise<BatchResult>;
71
180
  };
72
181
 
73
182
  interface SignInFormProps {
@@ -117,4 +226,34 @@ interface ProtectedRouteProps {
117
226
  }
118
227
  declare function ProtectedRoute({ children, fallback }: ProtectedRouteProps): react_jsx_runtime.JSX.Element | null;
119
228
 
120
- export { type AuthActions, type AuthState, type GitHatConfig, type GitHatContextValue, type GitHatOrg, GitHatProvider, type GitHatUser, OrgSwitcher, ProtectedRoute, SignInButton, SignInForm, SignUpButton, type SignUpData, SignUpForm, type SignUpResult, UserButton, VerifiedBadge, useAuth, useGitHat };
229
+ /**
230
+ * @githat/nextjs/server
231
+ *
232
+ * Server-side utilities for token verification in Next.js API routes and middleware.
233
+ * This module runs on the server only — do not import in client components.
234
+ */
235
+ interface AuthPayload {
236
+ userId: string;
237
+ email: string;
238
+ orgId: string | null;
239
+ orgSlug: string | null;
240
+ role: 'owner' | 'admin' | 'member' | null;
241
+ tier: 'free' | 'basic' | 'pro' | 'enterprise' | null;
242
+ }
243
+ interface VerifyOptions {
244
+ /**
245
+ * Secret key for local JWT verification. If provided, tokens are verified
246
+ * locally without making an API call (~1ms vs ~50-100ms).
247
+ * Must match the JWT_SECRET used by the GitHat backend.
248
+ */
249
+ secretKey?: string;
250
+ /**
251
+ * API URL for remote token verification. Defaults to https://api.githat.io
252
+ */
253
+ apiUrl?: string;
254
+ }
255
+ interface OrgMetadata {
256
+ [key: string]: unknown;
257
+ }
258
+
259
+ export { type AuthActions, type AuthPayload, type AuthState, type BatchOperation, type BatchResult, type DataItem, type DeleteResult, type GitHatConfig, type GitHatContextValue, type GitHatOrg, GitHatProvider, type GitHatUser, type OrgMetadata, OrgSwitcher, ProtectedRoute, type PutResult, type QueryOptions, type QueryResult, SignInButton, SignInForm, SignUpButton, type SignUpData, SignUpForm, type SignUpResult, UserButton, VerifiedBadge, type VerifyOptions, useAuth, useData, useGitHat };