@usequota/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/server.d.mts CHANGED
@@ -1,93 +1,7 @@
1
- export { Q as QuotaError, a as QuotaInsufficientCreditsError, b as QuotaNotConnectedError, d as QuotaRateLimitError, c as QuotaTokenExpiredError, e as errorFromResponse } from './errors-CmNx3kSz.mjs';
1
+ import { QuotaTokenStorage } from '@usequota/core';
2
+ export { InMemoryTokenStorage, OAuthTokenResponse, QuotaClient, QuotaClientConfig, QuotaError, QuotaInsufficientCreditsError, QuotaNotConnectedError, QuotaRateLimitError, QuotaTokenExpiredError, QuotaTokenStorage, VerifyWebhookOptions, WebhookEvent, createWebhookHandler, errorFromResponse, exchangeCodeForToken, parseSSEStream, parseWebhook, refreshAccessToken, verifyWebhookSignature } from '@usequota/core';
2
3
  import { QuotaUser, CreditPackage } from '@usequota/types';
3
4
 
4
- /**
5
- * @usequota/nextjs - Token Storage Adapter
6
- *
7
- * Defines the interface for pluggable token storage backends.
8
- * The default implementation uses httpOnly cookies, but apps can
9
- * provide their own (e.g., Supabase, Redis, a database).
10
- */
11
- /**
12
- * Pluggable token storage adapter for the Quota SDK.
13
- *
14
- * Implement this interface to store Quota OAuth tokens in your own backend
15
- * (database, Redis, etc.) instead of the default httpOnly cookies.
16
- *
17
- * @example
18
- * ```typescript
19
- * import { QuotaTokenStorage } from '@usequota/nextjs/server';
20
- * import { createClient } from '@supabase/supabase-js';
21
- *
22
- * const supabaseTokenStorage: QuotaTokenStorage = {
23
- * async getTokens(request) {
24
- * const supabase = createClient(...);
25
- * const userId = await getUserId(request);
26
- * const { data } = await supabase
27
- * .from('quota_accounts')
28
- * .select('access_token, refresh_token')
29
- * .eq('user_id', userId)
30
- * .single();
31
- * if (!data) return null;
32
- * return { accessToken: data.access_token, refreshToken: data.refresh_token };
33
- * },
34
- *
35
- * async setTokens(tokens, request) {
36
- * const supabase = createClient(...);
37
- * const userId = await getUserId(request);
38
- * await supabase.from('quota_accounts').upsert({
39
- * user_id: userId,
40
- * access_token: tokens.accessToken,
41
- * refresh_token: tokens.refreshToken,
42
- * });
43
- * },
44
- *
45
- * async deleteTokens(request) {
46
- * const supabase = createClient(...);
47
- * const userId = await getUserId(request);
48
- * await supabase.from('quota_accounts').delete().eq('user_id', userId);
49
- * },
50
- * };
51
- * ```
52
- */
53
- interface QuotaTokenStorage {
54
- /**
55
- * Retrieve stored tokens for the current request's user.
56
- * Return null if no tokens are stored.
57
- */
58
- getTokens(request: Request): Promise<{
59
- accessToken: string;
60
- refreshToken?: string;
61
- } | null>;
62
- /**
63
- * Persist tokens for the current request's user.
64
- * Called after OAuth callback and after token refresh.
65
- *
66
- * For storage backends that modify the Response (like cookies),
67
- * return the modified Response. For backends that don't modify
68
- * the Response (like databases), return void.
69
- */
70
- setTokens(tokens: {
71
- accessToken: string;
72
- refreshToken?: string;
73
- expiresIn?: number;
74
- }, request: Request, response?: Response): Promise<Response | void>;
75
- /**
76
- * Delete all stored tokens for the current request's user.
77
- * Called on disconnect.
78
- *
79
- * For storage backends that modify the Response (like cookies),
80
- * return the modified Response. For backends that don't modify
81
- * the Response (like databases), return void.
82
- */
83
- deleteTokens(request: Request, response?: Response): Promise<Response | void>;
84
- /**
85
- * Get the external user ID for hosted mode.
86
- * Only required if you use hosted storage mode alongside tokenStorage.
87
- */
88
- getExternalUserId?(request: Request): Promise<string | null>;
89
- }
90
-
91
5
  /**
92
6
  * @usequota/nextjs - Route Handler Factory
93
7
  *
@@ -136,7 +50,7 @@ interface QuotaRouteHandlerConfig {
136
50
  clientSecret: string;
137
51
  /**
138
52
  * Quota API base URL
139
- * @default 'https://api.usequota.app'
53
+ * @default 'https://api.usequota.ai'
140
54
  */
141
55
  baseUrl?: string;
142
56
  /**
@@ -248,7 +162,7 @@ declare function createQuotaRouteHandlers(config: QuotaRouteHandlerConfig): Quot
248
162
  * // accessToken can be used to proxy AI requests through Quota
249
163
  * const client = new Anthropic({
250
164
  * authToken: accessToken,
251
- * baseURL: 'https://api.usequota.app',
165
+ * baseURL: 'https://api.usequota.ai',
252
166
  * });
253
167
  *
254
168
  * const result = await client.messages.create({ ... });
@@ -269,7 +183,7 @@ interface WithQuotaAuthConfig {
269
183
  clientSecret: string;
270
184
  /**
271
185
  * Quota API base URL
272
- * @default 'https://api.usequota.app'
186
+ * @default 'https://api.usequota.ai'
273
187
  */
274
188
  baseUrl?: string;
275
189
  /**
@@ -334,7 +248,7 @@ interface QuotaServerConfig {
334
248
  clientSecret: string;
335
249
  /**
336
250
  * Quota API base URL
337
- * @default 'https://api.usequota.app'
251
+ * @default 'https://api.usequota.ai'
338
252
  */
339
253
  baseUrl?: string;
340
254
  /**
@@ -474,4 +388,4 @@ declare function clearQuotaAuth(config?: {
474
388
  cookiePrefix?: string;
475
389
  }): Promise<void>;
476
390
 
477
- export { type QuotaAuthContext, type QuotaRouteHandlerConfig, type QuotaRouteHandlers, type QuotaServerConfig, type QuotaTokenStorage, type WithQuotaAuthConfig, clearQuotaAuth, createQuotaCheckout, createQuotaRouteHandlers, getQuotaPackages, getQuotaUser, requireQuotaAuth, withQuotaAuth };
391
+ export { type QuotaAuthContext, type QuotaRouteHandlerConfig, type QuotaRouteHandlers, type QuotaServerConfig, type WithQuotaAuthConfig, clearQuotaAuth, createQuotaCheckout, createQuotaRouteHandlers, getQuotaPackages, getQuotaUser, requireQuotaAuth, withQuotaAuth };
package/dist/server.d.ts CHANGED
@@ -1,93 +1,7 @@
1
- export { Q as QuotaError, a as QuotaInsufficientCreditsError, b as QuotaNotConnectedError, d as QuotaRateLimitError, c as QuotaTokenExpiredError, e as errorFromResponse } from './errors-CmNx3kSz.js';
1
+ import { QuotaTokenStorage } from '@usequota/core';
2
+ export { InMemoryTokenStorage, OAuthTokenResponse, QuotaClient, QuotaClientConfig, QuotaError, QuotaInsufficientCreditsError, QuotaNotConnectedError, QuotaRateLimitError, QuotaTokenExpiredError, QuotaTokenStorage, VerifyWebhookOptions, WebhookEvent, createWebhookHandler, errorFromResponse, exchangeCodeForToken, parseSSEStream, parseWebhook, refreshAccessToken, verifyWebhookSignature } from '@usequota/core';
2
3
  import { QuotaUser, CreditPackage } from '@usequota/types';
3
4
 
4
- /**
5
- * @usequota/nextjs - Token Storage Adapter
6
- *
7
- * Defines the interface for pluggable token storage backends.
8
- * The default implementation uses httpOnly cookies, but apps can
9
- * provide their own (e.g., Supabase, Redis, a database).
10
- */
11
- /**
12
- * Pluggable token storage adapter for the Quota SDK.
13
- *
14
- * Implement this interface to store Quota OAuth tokens in your own backend
15
- * (database, Redis, etc.) instead of the default httpOnly cookies.
16
- *
17
- * @example
18
- * ```typescript
19
- * import { QuotaTokenStorage } from '@usequota/nextjs/server';
20
- * import { createClient } from '@supabase/supabase-js';
21
- *
22
- * const supabaseTokenStorage: QuotaTokenStorage = {
23
- * async getTokens(request) {
24
- * const supabase = createClient(...);
25
- * const userId = await getUserId(request);
26
- * const { data } = await supabase
27
- * .from('quota_accounts')
28
- * .select('access_token, refresh_token')
29
- * .eq('user_id', userId)
30
- * .single();
31
- * if (!data) return null;
32
- * return { accessToken: data.access_token, refreshToken: data.refresh_token };
33
- * },
34
- *
35
- * async setTokens(tokens, request) {
36
- * const supabase = createClient(...);
37
- * const userId = await getUserId(request);
38
- * await supabase.from('quota_accounts').upsert({
39
- * user_id: userId,
40
- * access_token: tokens.accessToken,
41
- * refresh_token: tokens.refreshToken,
42
- * });
43
- * },
44
- *
45
- * async deleteTokens(request) {
46
- * const supabase = createClient(...);
47
- * const userId = await getUserId(request);
48
- * await supabase.from('quota_accounts').delete().eq('user_id', userId);
49
- * },
50
- * };
51
- * ```
52
- */
53
- interface QuotaTokenStorage {
54
- /**
55
- * Retrieve stored tokens for the current request's user.
56
- * Return null if no tokens are stored.
57
- */
58
- getTokens(request: Request): Promise<{
59
- accessToken: string;
60
- refreshToken?: string;
61
- } | null>;
62
- /**
63
- * Persist tokens for the current request's user.
64
- * Called after OAuth callback and after token refresh.
65
- *
66
- * For storage backends that modify the Response (like cookies),
67
- * return the modified Response. For backends that don't modify
68
- * the Response (like databases), return void.
69
- */
70
- setTokens(tokens: {
71
- accessToken: string;
72
- refreshToken?: string;
73
- expiresIn?: number;
74
- }, request: Request, response?: Response): Promise<Response | void>;
75
- /**
76
- * Delete all stored tokens for the current request's user.
77
- * Called on disconnect.
78
- *
79
- * For storage backends that modify the Response (like cookies),
80
- * return the modified Response. For backends that don't modify
81
- * the Response (like databases), return void.
82
- */
83
- deleteTokens(request: Request, response?: Response): Promise<Response | void>;
84
- /**
85
- * Get the external user ID for hosted mode.
86
- * Only required if you use hosted storage mode alongside tokenStorage.
87
- */
88
- getExternalUserId?(request: Request): Promise<string | null>;
89
- }
90
-
91
5
  /**
92
6
  * @usequota/nextjs - Route Handler Factory
93
7
  *
@@ -136,7 +50,7 @@ interface QuotaRouteHandlerConfig {
136
50
  clientSecret: string;
137
51
  /**
138
52
  * Quota API base URL
139
- * @default 'https://api.usequota.app'
53
+ * @default 'https://api.usequota.ai'
140
54
  */
141
55
  baseUrl?: string;
142
56
  /**
@@ -248,7 +162,7 @@ declare function createQuotaRouteHandlers(config: QuotaRouteHandlerConfig): Quot
248
162
  * // accessToken can be used to proxy AI requests through Quota
249
163
  * const client = new Anthropic({
250
164
  * authToken: accessToken,
251
- * baseURL: 'https://api.usequota.app',
165
+ * baseURL: 'https://api.usequota.ai',
252
166
  * });
253
167
  *
254
168
  * const result = await client.messages.create({ ... });
@@ -269,7 +183,7 @@ interface WithQuotaAuthConfig {
269
183
  clientSecret: string;
270
184
  /**
271
185
  * Quota API base URL
272
- * @default 'https://api.usequota.app'
186
+ * @default 'https://api.usequota.ai'
273
187
  */
274
188
  baseUrl?: string;
275
189
  /**
@@ -334,7 +248,7 @@ interface QuotaServerConfig {
334
248
  clientSecret: string;
335
249
  /**
336
250
  * Quota API base URL
337
- * @default 'https://api.usequota.app'
251
+ * @default 'https://api.usequota.ai'
338
252
  */
339
253
  baseUrl?: string;
340
254
  /**
@@ -474,4 +388,4 @@ declare function clearQuotaAuth(config?: {
474
388
  cookiePrefix?: string;
475
389
  }): Promise<void>;
476
390
 
477
- export { type QuotaAuthContext, type QuotaRouteHandlerConfig, type QuotaRouteHandlers, type QuotaServerConfig, type QuotaTokenStorage, type WithQuotaAuthConfig, clearQuotaAuth, createQuotaCheckout, createQuotaRouteHandlers, getQuotaPackages, getQuotaUser, requireQuotaAuth, withQuotaAuth };
391
+ export { type QuotaAuthContext, type QuotaRouteHandlerConfig, type QuotaRouteHandlers, type QuotaServerConfig, type WithQuotaAuthConfig, clearQuotaAuth, createQuotaCheckout, createQuotaRouteHandlers, getQuotaPackages, getQuotaUser, requireQuotaAuth, withQuotaAuth };