@usequota/nextjs 0.1.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 +462 -0
- package/dist/chunk-BMI3VFWV.mjs +120 -0
- package/dist/chunk-RSPDHXC2.mjs +119 -0
- package/dist/chunk-SJ3X4KTV.mjs +117 -0
- package/dist/chunk-ZF7WJBQC.mjs +114 -0
- package/dist/errors-CmNx3kSz.d.mts +109 -0
- package/dist/errors-CmNx3kSz.d.ts +109 -0
- package/dist/errors-DVurmYT7.d.mts +109 -0
- package/dist/errors-DVurmYT7.d.ts +109 -0
- package/dist/index.d.mts +585 -0
- package/dist/index.d.ts +585 -0
- package/dist/index.js +1079 -0
- package/dist/index.mjs +968 -0
- package/dist/server.d.mts +477 -0
- package/dist/server.d.ts +477 -0
- package/dist/server.js +1068 -0
- package/dist/server.mjs +916 -0
- package/dist/styles.css +439 -0
- package/package.json +69 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var QuotaError = class extends Error {
|
|
3
|
+
/** Machine-readable error code */
|
|
4
|
+
code;
|
|
5
|
+
/** HTTP status code associated with this error */
|
|
6
|
+
statusCode;
|
|
7
|
+
/** Optional hint for resolving the error */
|
|
8
|
+
hint;
|
|
9
|
+
constructor(message, code, statusCode, hint) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "QuotaError";
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.statusCode = statusCode;
|
|
14
|
+
this.hint = hint;
|
|
15
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var QuotaInsufficientCreditsError = class extends QuotaError {
|
|
19
|
+
/** Current balance (if available) */
|
|
20
|
+
balance;
|
|
21
|
+
/** Credits required for the operation (if available) */
|
|
22
|
+
required;
|
|
23
|
+
constructor(message, options) {
|
|
24
|
+
super(
|
|
25
|
+
message ?? "Insufficient credits to complete this operation",
|
|
26
|
+
"insufficient_credits",
|
|
27
|
+
402,
|
|
28
|
+
"Purchase more credits or reduce usage"
|
|
29
|
+
);
|
|
30
|
+
this.name = "QuotaInsufficientCreditsError";
|
|
31
|
+
this.balance = options?.balance;
|
|
32
|
+
this.required = options?.required;
|
|
33
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var QuotaNotConnectedError = class extends QuotaError {
|
|
37
|
+
constructor(message) {
|
|
38
|
+
super(
|
|
39
|
+
message ?? "User has not connected a Quota account",
|
|
40
|
+
"not_connected",
|
|
41
|
+
401,
|
|
42
|
+
"Connect your Quota account to use this feature"
|
|
43
|
+
);
|
|
44
|
+
this.name = "QuotaNotConnectedError";
|
|
45
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var QuotaTokenExpiredError = class extends QuotaError {
|
|
49
|
+
constructor(message) {
|
|
50
|
+
super(
|
|
51
|
+
message ?? "Quota access token has expired and could not be refreshed",
|
|
52
|
+
"token_expired",
|
|
53
|
+
401,
|
|
54
|
+
"Reconnect your Quota account"
|
|
55
|
+
);
|
|
56
|
+
this.name = "QuotaTokenExpiredError";
|
|
57
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var QuotaRateLimitError = class extends QuotaError {
|
|
61
|
+
/** Seconds until the rate limit resets */
|
|
62
|
+
retryAfter;
|
|
63
|
+
constructor(message, retryAfter) {
|
|
64
|
+
super(
|
|
65
|
+
message ?? "Rate limit exceeded",
|
|
66
|
+
"rate_limit_exceeded",
|
|
67
|
+
429,
|
|
68
|
+
"Wait before retrying"
|
|
69
|
+
);
|
|
70
|
+
this.name = "QuotaRateLimitError";
|
|
71
|
+
this.retryAfter = retryAfter ?? 60;
|
|
72
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
async function errorFromResponse(response) {
|
|
76
|
+
if (response.ok) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
let body;
|
|
80
|
+
try {
|
|
81
|
+
body = await response.json();
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
const message = body?.error?.message ?? response.statusText;
|
|
85
|
+
const code = body?.error?.code;
|
|
86
|
+
switch (response.status) {
|
|
87
|
+
case 402:
|
|
88
|
+
return new QuotaInsufficientCreditsError(message, {
|
|
89
|
+
balance: body?.error?.balance,
|
|
90
|
+
required: body?.error?.required
|
|
91
|
+
});
|
|
92
|
+
case 429: {
|
|
93
|
+
const retryAfter = parseInt(
|
|
94
|
+
response.headers.get("retry-after") ?? "60",
|
|
95
|
+
10
|
|
96
|
+
);
|
|
97
|
+
return new QuotaRateLimitError(message, retryAfter);
|
|
98
|
+
}
|
|
99
|
+
case 401: {
|
|
100
|
+
if (code === "not_connected") {
|
|
101
|
+
return new QuotaNotConnectedError(message);
|
|
102
|
+
}
|
|
103
|
+
return new QuotaTokenExpiredError(message);
|
|
104
|
+
}
|
|
105
|
+
default:
|
|
106
|
+
return new QuotaError(message, code ?? "unknown", response.status);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export {
|
|
111
|
+
QuotaError,
|
|
112
|
+
QuotaInsufficientCreditsError,
|
|
113
|
+
QuotaNotConnectedError,
|
|
114
|
+
QuotaTokenExpiredError,
|
|
115
|
+
QuotaRateLimitError,
|
|
116
|
+
errorFromResponse
|
|
117
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var QuotaError = class extends Error {
|
|
3
|
+
/** Machine-readable error code */
|
|
4
|
+
code;
|
|
5
|
+
/** HTTP status code associated with this error */
|
|
6
|
+
statusCode;
|
|
7
|
+
/** Optional hint for resolving the error */
|
|
8
|
+
hint;
|
|
9
|
+
constructor(message, code, statusCode, hint) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "QuotaError";
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.statusCode = statusCode;
|
|
14
|
+
this.hint = hint;
|
|
15
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var QuotaInsufficientCreditsError = class extends QuotaError {
|
|
19
|
+
/** Current balance (if available) */
|
|
20
|
+
balance;
|
|
21
|
+
/** Credits required for the operation (if available) */
|
|
22
|
+
required;
|
|
23
|
+
constructor(message, options) {
|
|
24
|
+
super(
|
|
25
|
+
message ?? "Insufficient credits to complete this operation",
|
|
26
|
+
"insufficient_credits",
|
|
27
|
+
402,
|
|
28
|
+
"Purchase more credits or reduce usage"
|
|
29
|
+
);
|
|
30
|
+
this.name = "QuotaInsufficientCreditsError";
|
|
31
|
+
this.balance = options?.balance;
|
|
32
|
+
this.required = options?.required;
|
|
33
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var QuotaNotConnectedError = class extends QuotaError {
|
|
37
|
+
constructor(message) {
|
|
38
|
+
super(
|
|
39
|
+
message ?? "User has not connected a Quota account",
|
|
40
|
+
"not_connected",
|
|
41
|
+
401,
|
|
42
|
+
"Connect your Quota account to use this feature"
|
|
43
|
+
);
|
|
44
|
+
this.name = "QuotaNotConnectedError";
|
|
45
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var QuotaTokenExpiredError = class extends QuotaError {
|
|
49
|
+
constructor(message) {
|
|
50
|
+
super(
|
|
51
|
+
message ?? "Quota access token has expired and could not be refreshed",
|
|
52
|
+
"token_expired",
|
|
53
|
+
401,
|
|
54
|
+
"Reconnect your Quota account"
|
|
55
|
+
);
|
|
56
|
+
this.name = "QuotaTokenExpiredError";
|
|
57
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var QuotaRateLimitError = class extends QuotaError {
|
|
61
|
+
/** Seconds until the rate limit resets */
|
|
62
|
+
retryAfter;
|
|
63
|
+
constructor(message, retryAfter) {
|
|
64
|
+
super(
|
|
65
|
+
message ?? "Rate limit exceeded",
|
|
66
|
+
"rate_limit_exceeded",
|
|
67
|
+
429,
|
|
68
|
+
"Wait before retrying"
|
|
69
|
+
);
|
|
70
|
+
this.name = "QuotaRateLimitError";
|
|
71
|
+
this.retryAfter = retryAfter ?? 60;
|
|
72
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
async function errorFromResponse(response) {
|
|
76
|
+
if (response.ok) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
let body;
|
|
80
|
+
try {
|
|
81
|
+
body = await response.json();
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
const message = body?.error?.message ?? response.statusText;
|
|
85
|
+
const code = body?.error?.code;
|
|
86
|
+
switch (response.status) {
|
|
87
|
+
case 402:
|
|
88
|
+
return new QuotaInsufficientCreditsError(message);
|
|
89
|
+
case 429: {
|
|
90
|
+
const retryAfter = parseInt(
|
|
91
|
+
response.headers.get("retry-after") ?? "60",
|
|
92
|
+
10
|
|
93
|
+
);
|
|
94
|
+
return new QuotaRateLimitError(message, retryAfter);
|
|
95
|
+
}
|
|
96
|
+
case 401: {
|
|
97
|
+
if (code === "not_connected") {
|
|
98
|
+
return new QuotaNotConnectedError(message);
|
|
99
|
+
}
|
|
100
|
+
return new QuotaTokenExpiredError(message);
|
|
101
|
+
}
|
|
102
|
+
default:
|
|
103
|
+
return new QuotaError(message, code ?? "unknown", response.status);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
QuotaError,
|
|
109
|
+
QuotaInsufficientCreditsError,
|
|
110
|
+
QuotaNotConnectedError,
|
|
111
|
+
QuotaTokenExpiredError,
|
|
112
|
+
QuotaRateLimitError,
|
|
113
|
+
errorFromResponse
|
|
114
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @usequota/nextjs - Typed error classes for Quota SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides specific error classes for common Quota error scenarios,
|
|
5
|
+
* enabling pattern matching with instanceof checks.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Base error class for all Quota SDK errors
|
|
9
|
+
*/
|
|
10
|
+
declare class QuotaError extends Error {
|
|
11
|
+
/** Machine-readable error code */
|
|
12
|
+
readonly code: string;
|
|
13
|
+
/** HTTP status code associated with this error */
|
|
14
|
+
readonly statusCode: number;
|
|
15
|
+
/** Optional hint for resolving the error */
|
|
16
|
+
readonly hint: string | undefined;
|
|
17
|
+
constructor(message: string, code: string, statusCode: number, hint?: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Thrown when a user does not have enough credits for an operation
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* try {
|
|
25
|
+
* await makeAICall();
|
|
26
|
+
* } catch (e) {
|
|
27
|
+
* if (e instanceof QuotaInsufficientCreditsError) {
|
|
28
|
+
* // Prompt user to buy more credits
|
|
29
|
+
* showBuyCreditsDialog();
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare class QuotaInsufficientCreditsError extends QuotaError {
|
|
35
|
+
/** Current balance (if available) */
|
|
36
|
+
readonly balance: number | undefined;
|
|
37
|
+
/** Credits required for the operation (if available) */
|
|
38
|
+
readonly required: number | undefined;
|
|
39
|
+
constructor(message?: string, options?: {
|
|
40
|
+
balance?: number;
|
|
41
|
+
required?: number;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Thrown when a user has not connected their Quota account
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* try {
|
|
50
|
+
* const user = await getQuotaUser(config);
|
|
51
|
+
* } catch (e) {
|
|
52
|
+
* if (e instanceof QuotaNotConnectedError) {
|
|
53
|
+
* // Redirect to Quota OAuth
|
|
54
|
+
* redirectToQuotaAuth();
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare class QuotaNotConnectedError extends QuotaError {
|
|
60
|
+
constructor(message?: string);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Thrown when the OAuth access token has expired and cannot be refreshed
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* try {
|
|
68
|
+
* await callQuotaAPI();
|
|
69
|
+
* } catch (e) {
|
|
70
|
+
* if (e instanceof QuotaTokenExpiredError) {
|
|
71
|
+
* // Re-authenticate the user
|
|
72
|
+
* redirectToQuotaAuth();
|
|
73
|
+
* }
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare class QuotaTokenExpiredError extends QuotaError {
|
|
78
|
+
constructor(message?: string);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Thrown when the Quota API rate limit is exceeded
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* try {
|
|
86
|
+
* await callQuotaAPI();
|
|
87
|
+
* } catch (e) {
|
|
88
|
+
* if (e instanceof QuotaRateLimitError) {
|
|
89
|
+
* // Wait and retry
|
|
90
|
+
* await delay(e.retryAfter * 1000);
|
|
91
|
+
* await callQuotaAPI();
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
declare class QuotaRateLimitError extends QuotaError {
|
|
97
|
+
/** Seconds until the rate limit resets */
|
|
98
|
+
readonly retryAfter: number;
|
|
99
|
+
constructor(message?: string, retryAfter?: number);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Maps an HTTP response to the appropriate typed error.
|
|
103
|
+
* Returns null if the response doesn't represent a known error.
|
|
104
|
+
*
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
declare function errorFromResponse(response: Response): Promise<QuotaError | null>;
|
|
108
|
+
|
|
109
|
+
export { QuotaError as Q, QuotaInsufficientCreditsError as a, QuotaNotConnectedError as b, QuotaTokenExpiredError as c, QuotaRateLimitError as d, errorFromResponse as e };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @usequota/nextjs - Typed error classes for Quota SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides specific error classes for common Quota error scenarios,
|
|
5
|
+
* enabling pattern matching with instanceof checks.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Base error class for all Quota SDK errors
|
|
9
|
+
*/
|
|
10
|
+
declare class QuotaError extends Error {
|
|
11
|
+
/** Machine-readable error code */
|
|
12
|
+
readonly code: string;
|
|
13
|
+
/** HTTP status code associated with this error */
|
|
14
|
+
readonly statusCode: number;
|
|
15
|
+
/** Optional hint for resolving the error */
|
|
16
|
+
readonly hint: string | undefined;
|
|
17
|
+
constructor(message: string, code: string, statusCode: number, hint?: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Thrown when a user does not have enough credits for an operation
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* try {
|
|
25
|
+
* await makeAICall();
|
|
26
|
+
* } catch (e) {
|
|
27
|
+
* if (e instanceof QuotaInsufficientCreditsError) {
|
|
28
|
+
* // Prompt user to buy more credits
|
|
29
|
+
* showBuyCreditsDialog();
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare class QuotaInsufficientCreditsError extends QuotaError {
|
|
35
|
+
/** Current balance (if available) */
|
|
36
|
+
readonly balance: number | undefined;
|
|
37
|
+
/** Credits required for the operation (if available) */
|
|
38
|
+
readonly required: number | undefined;
|
|
39
|
+
constructor(message?: string, options?: {
|
|
40
|
+
balance?: number;
|
|
41
|
+
required?: number;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Thrown when a user has not connected their Quota account
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* try {
|
|
50
|
+
* const user = await getQuotaUser(config);
|
|
51
|
+
* } catch (e) {
|
|
52
|
+
* if (e instanceof QuotaNotConnectedError) {
|
|
53
|
+
* // Redirect to Quota OAuth
|
|
54
|
+
* redirectToQuotaAuth();
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare class QuotaNotConnectedError extends QuotaError {
|
|
60
|
+
constructor(message?: string);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Thrown when the OAuth access token has expired and cannot be refreshed
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* try {
|
|
68
|
+
* await callQuotaAPI();
|
|
69
|
+
* } catch (e) {
|
|
70
|
+
* if (e instanceof QuotaTokenExpiredError) {
|
|
71
|
+
* // Re-authenticate the user
|
|
72
|
+
* redirectToQuotaAuth();
|
|
73
|
+
* }
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare class QuotaTokenExpiredError extends QuotaError {
|
|
78
|
+
constructor(message?: string);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Thrown when the Quota API rate limit is exceeded
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* try {
|
|
86
|
+
* await callQuotaAPI();
|
|
87
|
+
* } catch (e) {
|
|
88
|
+
* if (e instanceof QuotaRateLimitError) {
|
|
89
|
+
* // Wait and retry
|
|
90
|
+
* await delay(e.retryAfter * 1000);
|
|
91
|
+
* await callQuotaAPI();
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
declare class QuotaRateLimitError extends QuotaError {
|
|
97
|
+
/** Seconds until the rate limit resets */
|
|
98
|
+
readonly retryAfter: number;
|
|
99
|
+
constructor(message?: string, retryAfter?: number);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Maps an HTTP response to the appropriate typed error.
|
|
103
|
+
* Returns null if the response doesn't represent a known error.
|
|
104
|
+
*
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
declare function errorFromResponse(response: Response): Promise<QuotaError | null>;
|
|
108
|
+
|
|
109
|
+
export { QuotaError as Q, QuotaInsufficientCreditsError as a, QuotaNotConnectedError as b, QuotaTokenExpiredError as c, QuotaRateLimitError as d, errorFromResponse as e };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @quota/nextjs - Typed error classes for Quota SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides specific error classes for common Quota error scenarios,
|
|
5
|
+
* enabling pattern matching with instanceof checks.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Base error class for all Quota SDK errors
|
|
9
|
+
*/
|
|
10
|
+
declare class QuotaError extends Error {
|
|
11
|
+
/** Machine-readable error code */
|
|
12
|
+
readonly code: string;
|
|
13
|
+
/** HTTP status code associated with this error */
|
|
14
|
+
readonly statusCode: number;
|
|
15
|
+
/** Optional hint for resolving the error */
|
|
16
|
+
readonly hint: string | undefined;
|
|
17
|
+
constructor(message: string, code: string, statusCode: number, hint?: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Thrown when a user does not have enough credits for an operation
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* try {
|
|
25
|
+
* await makeAICall();
|
|
26
|
+
* } catch (e) {
|
|
27
|
+
* if (e instanceof QuotaInsufficientCreditsError) {
|
|
28
|
+
* // Prompt user to buy more credits
|
|
29
|
+
* showBuyCreditsDialog();
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare class QuotaInsufficientCreditsError extends QuotaError {
|
|
35
|
+
/** Current balance (if available) */
|
|
36
|
+
readonly balance: number | undefined;
|
|
37
|
+
/** Credits required for the operation (if available) */
|
|
38
|
+
readonly required: number | undefined;
|
|
39
|
+
constructor(message?: string, options?: {
|
|
40
|
+
balance?: number;
|
|
41
|
+
required?: number;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Thrown when a user has not connected their Quota account
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* try {
|
|
50
|
+
* const user = await getQuotaUser(config);
|
|
51
|
+
* } catch (e) {
|
|
52
|
+
* if (e instanceof QuotaNotConnectedError) {
|
|
53
|
+
* // Redirect to Quota OAuth
|
|
54
|
+
* redirectToQuotaAuth();
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare class QuotaNotConnectedError extends QuotaError {
|
|
60
|
+
constructor(message?: string);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Thrown when the OAuth access token has expired and cannot be refreshed
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* try {
|
|
68
|
+
* await callQuotaAPI();
|
|
69
|
+
* } catch (e) {
|
|
70
|
+
* if (e instanceof QuotaTokenExpiredError) {
|
|
71
|
+
* // Re-authenticate the user
|
|
72
|
+
* redirectToQuotaAuth();
|
|
73
|
+
* }
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare class QuotaTokenExpiredError extends QuotaError {
|
|
78
|
+
constructor(message?: string);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Thrown when the Quota API rate limit is exceeded
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* try {
|
|
86
|
+
* await callQuotaAPI();
|
|
87
|
+
* } catch (e) {
|
|
88
|
+
* if (e instanceof QuotaRateLimitError) {
|
|
89
|
+
* // Wait and retry
|
|
90
|
+
* await delay(e.retryAfter * 1000);
|
|
91
|
+
* await callQuotaAPI();
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
declare class QuotaRateLimitError extends QuotaError {
|
|
97
|
+
/** Seconds until the rate limit resets */
|
|
98
|
+
readonly retryAfter: number;
|
|
99
|
+
constructor(message?: string, retryAfter?: number);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Maps an HTTP response to the appropriate typed error.
|
|
103
|
+
* Returns null if the response doesn't represent a known error.
|
|
104
|
+
*
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
declare function errorFromResponse(response: Response): Promise<QuotaError | null>;
|
|
108
|
+
|
|
109
|
+
export { QuotaError as Q, QuotaInsufficientCreditsError as a, QuotaNotConnectedError as b, QuotaTokenExpiredError as c, QuotaRateLimitError as d, errorFromResponse as e };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @quota/nextjs - Typed error classes for Quota SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides specific error classes for common Quota error scenarios,
|
|
5
|
+
* enabling pattern matching with instanceof checks.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Base error class for all Quota SDK errors
|
|
9
|
+
*/
|
|
10
|
+
declare class QuotaError extends Error {
|
|
11
|
+
/** Machine-readable error code */
|
|
12
|
+
readonly code: string;
|
|
13
|
+
/** HTTP status code associated with this error */
|
|
14
|
+
readonly statusCode: number;
|
|
15
|
+
/** Optional hint for resolving the error */
|
|
16
|
+
readonly hint: string | undefined;
|
|
17
|
+
constructor(message: string, code: string, statusCode: number, hint?: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Thrown when a user does not have enough credits for an operation
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* try {
|
|
25
|
+
* await makeAICall();
|
|
26
|
+
* } catch (e) {
|
|
27
|
+
* if (e instanceof QuotaInsufficientCreditsError) {
|
|
28
|
+
* // Prompt user to buy more credits
|
|
29
|
+
* showBuyCreditsDialog();
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare class QuotaInsufficientCreditsError extends QuotaError {
|
|
35
|
+
/** Current balance (if available) */
|
|
36
|
+
readonly balance: number | undefined;
|
|
37
|
+
/** Credits required for the operation (if available) */
|
|
38
|
+
readonly required: number | undefined;
|
|
39
|
+
constructor(message?: string, options?: {
|
|
40
|
+
balance?: number;
|
|
41
|
+
required?: number;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Thrown when a user has not connected their Quota account
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* try {
|
|
50
|
+
* const user = await getQuotaUser(config);
|
|
51
|
+
* } catch (e) {
|
|
52
|
+
* if (e instanceof QuotaNotConnectedError) {
|
|
53
|
+
* // Redirect to Quota OAuth
|
|
54
|
+
* redirectToQuotaAuth();
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare class QuotaNotConnectedError extends QuotaError {
|
|
60
|
+
constructor(message?: string);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Thrown when the OAuth access token has expired and cannot be refreshed
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* try {
|
|
68
|
+
* await callQuotaAPI();
|
|
69
|
+
* } catch (e) {
|
|
70
|
+
* if (e instanceof QuotaTokenExpiredError) {
|
|
71
|
+
* // Re-authenticate the user
|
|
72
|
+
* redirectToQuotaAuth();
|
|
73
|
+
* }
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare class QuotaTokenExpiredError extends QuotaError {
|
|
78
|
+
constructor(message?: string);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Thrown when the Quota API rate limit is exceeded
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* try {
|
|
86
|
+
* await callQuotaAPI();
|
|
87
|
+
* } catch (e) {
|
|
88
|
+
* if (e instanceof QuotaRateLimitError) {
|
|
89
|
+
* // Wait and retry
|
|
90
|
+
* await delay(e.retryAfter * 1000);
|
|
91
|
+
* await callQuotaAPI();
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
declare class QuotaRateLimitError extends QuotaError {
|
|
97
|
+
/** Seconds until the rate limit resets */
|
|
98
|
+
readonly retryAfter: number;
|
|
99
|
+
constructor(message?: string, retryAfter?: number);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Maps an HTTP response to the appropriate typed error.
|
|
103
|
+
* Returns null if the response doesn't represent a known error.
|
|
104
|
+
*
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
declare function errorFromResponse(response: Response): Promise<QuotaError | null>;
|
|
108
|
+
|
|
109
|
+
export { QuotaError as Q, QuotaInsufficientCreditsError as a, QuotaNotConnectedError as b, QuotaTokenExpiredError as c, QuotaRateLimitError as d, errorFromResponse as e };
|