@nehorai/credits 1.0.2 → 1.3.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/dist/adapters/index.cjs +463 -0
- package/dist/adapters/index.cjs.map +1 -0
- package/dist/adapters/index.d.cts +66 -0
- package/dist/adapters/index.d.ts +66 -3
- package/dist/adapters/index.js +435 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/auth/index.cjs +96 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/{api-key.d.ts → index.d.cts} +9 -6
- package/dist/auth/index.d.ts +37 -5
- package/dist/auth/index.js +65 -7
- package/dist/auth/index.js.map +1 -1
- package/dist/core/index.cjs +522 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +119 -0
- package/dist/core/index.d.ts +115 -25
- package/dist/core/index.js +475 -27
- package/dist/core/index.js.map +1 -1
- package/dist/{core/deferred.d.ts → deferred-C7rrRfkm.d.cts} +7 -6
- package/dist/{core/deferred.js → deferred-C7rrRfkm.d.ts} +23 -29
- package/dist/index.cjs +2506 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +437 -0
- package/dist/index.d.ts +429 -49
- package/dist/index.js +2399 -62
- package/dist/index.js.map +1 -1
- package/dist/repository/index.cjs +816 -0
- package/dist/repository/index.cjs.map +1 -0
- package/dist/repository/{memory/index.d.ts → index.d.cts} +35 -5
- package/dist/repository/index.d.ts +97 -7
- package/dist/repository/index.js +783 -10
- package/dist/repository/index.js.map +1 -1
- package/dist/sdk/index.cjs +608 -0
- package/dist/sdk/index.cjs.map +1 -0
- package/dist/sdk/index.d.cts +495 -0
- package/dist/sdk/index.d.ts +491 -9
- package/dist/sdk/index.js +568 -12
- package/dist/sdk/index.js.map +1 -1
- package/dist/service/index.cjs +670 -0
- package/dist/service/index.cjs.map +1 -0
- package/dist/service/{credits-service.d.ts → index.d.cts} +9 -7
- package/dist/service/index.d.ts +141 -3
- package/dist/service/index.js +641 -1
- package/dist/service/index.js.map +1 -1
- package/dist/{core/types.d.ts → types-BBxIWHK2.d.cts} +25 -35
- package/dist/types-BBxIWHK2.d.ts +277 -0
- package/dist/types-D1vdeBcA.d.cts +305 -0
- package/dist/{auth/types.d.ts → types-OZU3I5OM.d.cts} +5 -4
- package/dist/types-OZU3I5OM.d.ts +32 -0
- package/dist/{repository/types.d.ts → types-aJsyv8df.d.ts} +35 -13
- package/package.json +14 -13
- package/dist/adapters/generic.d.ts +0 -18
- package/dist/adapters/generic.d.ts.map +0 -1
- package/dist/adapters/generic.js +0 -147
- package/dist/adapters/generic.js.map +0 -1
- package/dist/adapters/index.d.ts.map +0 -1
- package/dist/adapters/types.d.ts +0 -45
- package/dist/adapters/types.d.ts.map +0 -1
- package/dist/adapters/types.js +0 -8
- package/dist/adapters/types.js.map +0 -1
- package/dist/auth/api-key.d.ts.map +0 -1
- package/dist/auth/api-key.js +0 -94
- package/dist/auth/api-key.js.map +0 -1
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js +0 -2
- package/dist/auth/types.js.map +0 -1
- package/dist/config/costs.d.ts +0 -61
- package/dist/config/costs.d.ts.map +0 -1
- package/dist/config/costs.js +0 -86
- package/dist/config/costs.js.map +0 -1
- package/dist/config/index.d.ts +0 -165
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -286
- package/dist/config/index.js.map +0 -1
- package/dist/core/deferred.d.ts.map +0 -1
- package/dist/core/deferred.js.map +0 -1
- package/dist/core/errors.d.ts +0 -78
- package/dist/core/errors.d.ts.map +0 -1
- package/dist/core/errors.js +0 -110
- package/dist/core/errors.js.map +0 -1
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/operations.d.ts +0 -36
- package/dist/core/operations.d.ts.map +0 -1
- package/dist/core/operations.js +0 -87
- package/dist/core/operations.js.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js +0 -93
- package/dist/core/types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/notifications/index.d.ts +0 -76
- package/dist/notifications/index.d.ts.map +0 -1
- package/dist/notifications/index.js +0 -182
- package/dist/notifications/index.js.map +0 -1
- package/dist/repository/index.d.ts.map +0 -1
- package/dist/repository/memory/index.d.ts.map +0 -1
- package/dist/repository/memory/index.js +0 -518
- package/dist/repository/memory/index.js.map +0 -1
- package/dist/repository/types.d.ts.map +0 -1
- package/dist/repository/types.js +0 -39
- package/dist/repository/types.js.map +0 -1
- package/dist/repository/utils.d.ts +0 -22
- package/dist/repository/utils.d.ts.map +0 -1
- package/dist/repository/utils.js +0 -40
- package/dist/repository/utils.js.map +0 -1
- package/dist/sdk/admin-client.d.ts +0 -146
- package/dist/sdk/admin-client.d.ts.map +0 -1
- package/dist/sdk/admin-client.js +0 -196
- package/dist/sdk/admin-client.js.map +0 -1
- package/dist/sdk/client.d.ts +0 -144
- package/dist/sdk/client.d.ts.map +0 -1
- package/dist/sdk/client.js +0 -247
- package/dist/sdk/client.js.map +0 -1
- package/dist/sdk/errors.d.ts +0 -91
- package/dist/sdk/errors.d.ts.map +0 -1
- package/dist/sdk/errors.js +0 -185
- package/dist/sdk/errors.js.map +0 -1
- package/dist/sdk/index.d.ts.map +0 -1
- package/dist/sdk/types.d.ts +0 -110
- package/dist/sdk/types.d.ts.map +0 -1
- package/dist/sdk/types.js +0 -20
- package/dist/sdk/types.js.map +0 -1
- package/dist/service/credits-service.d.ts.map +0 -1
- package/dist/service/credits-service.js +0 -372
- package/dist/service/credits-service.js.map +0 -1
- package/dist/service/index.d.ts.map +0 -1
- package/dist/utils/error-utils.d.ts +0 -48
- package/dist/utils/error-utils.d.ts.map +0 -1
- package/dist/utils/error-utils.js +0 -57
- package/dist/utils/error-utils.js.map +0 -1
- package/dist/utils/index.d.ts +0 -54
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -72
- package/dist/utils/index.js.map +0 -1
package/dist/sdk/client.js
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CreditsClient - REST API client for the credits system
|
|
3
|
-
*
|
|
4
|
-
* Provides a type-safe interface for consuming credits API endpoints
|
|
5
|
-
* from external services or other applications.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* const client = new CreditsClient({
|
|
10
|
-
* baseUrl: process.env.CREDITS_API_URL,
|
|
11
|
-
* getAuthToken: async () => session.accessToken,
|
|
12
|
-
* });
|
|
13
|
-
*
|
|
14
|
-
* // Check if user has sufficient credits
|
|
15
|
-
* const check = await client.checkAvailability("story_generation");
|
|
16
|
-
* if (!check.hasCredits) {
|
|
17
|
-
* console.log("Insufficient credits");
|
|
18
|
-
* return;
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* // Two-phase commit pattern
|
|
22
|
-
* const reservation = await client.reserve("story_generation");
|
|
23
|
-
* try {
|
|
24
|
-
* const result = await doExpensiveWork();
|
|
25
|
-
* await client.commit(reservation.reservationId);
|
|
26
|
-
* return result;
|
|
27
|
-
* } catch (error) {
|
|
28
|
-
* await client.release(reservation.reservationId);
|
|
29
|
-
* throw error;
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
import { parseApiError, NetworkError } from "./errors.js";
|
|
34
|
-
export class CreditsClient {
|
|
35
|
-
baseUrl;
|
|
36
|
-
getAuthToken;
|
|
37
|
-
fetchFn;
|
|
38
|
-
constructor(config) {
|
|
39
|
-
// Ensure baseUrl doesn't have trailing slash
|
|
40
|
-
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
41
|
-
this.getAuthToken = config.getAuthToken;
|
|
42
|
-
this.fetchFn = config.fetch ?? fetch;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Make an authenticated request to the API
|
|
46
|
-
*/
|
|
47
|
-
async request(path, options = {}) {
|
|
48
|
-
const { method = "GET", body, params } = options;
|
|
49
|
-
// Build URL with query params
|
|
50
|
-
let url = `${this.baseUrl}${path}`;
|
|
51
|
-
if (params) {
|
|
52
|
-
const searchParams = new URLSearchParams();
|
|
53
|
-
for (const [key, value] of Object.entries(params)) {
|
|
54
|
-
if (value !== undefined) {
|
|
55
|
-
searchParams.set(key, String(value));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const queryString = searchParams.toString();
|
|
59
|
-
if (queryString) {
|
|
60
|
-
url += `?${queryString}`;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Build headers
|
|
64
|
-
const headers = {
|
|
65
|
-
"Content-Type": "application/json",
|
|
66
|
-
};
|
|
67
|
-
// Add auth token if available
|
|
68
|
-
if (this.getAuthToken) {
|
|
69
|
-
try {
|
|
70
|
-
const token = await this.getAuthToken();
|
|
71
|
-
if (token) {
|
|
72
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
// Auth token not available, proceed without it
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// Make the request
|
|
80
|
-
let response;
|
|
81
|
-
try {
|
|
82
|
-
response = await this.fetchFn(url, {
|
|
83
|
-
method,
|
|
84
|
-
headers,
|
|
85
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
throw new NetworkError(error instanceof Error ? error.message : "Network request failed", error instanceof Error ? error : undefined);
|
|
90
|
-
}
|
|
91
|
-
// Parse response
|
|
92
|
-
const responseBody = (await response.json());
|
|
93
|
-
// Handle errors
|
|
94
|
-
if (!response.ok) {
|
|
95
|
-
throw parseApiError(response.status, responseBody);
|
|
96
|
-
}
|
|
97
|
-
// Return data
|
|
98
|
-
return responseBody.data;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Get the current user's credit balance
|
|
102
|
-
*
|
|
103
|
-
* @returns User's credit information
|
|
104
|
-
* @throws AuthenticationError if not authenticated
|
|
105
|
-
*/
|
|
106
|
-
async getBalance() {
|
|
107
|
-
return this.request("/api/v1/credits/balance");
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Check if the user has sufficient credits for an operation
|
|
111
|
-
*
|
|
112
|
-
* @param operationType - Type of operation to check
|
|
113
|
-
* @param customCost - Optional custom cost to check against
|
|
114
|
-
* @returns Credit availability status
|
|
115
|
-
* @throws AuthenticationError if not authenticated
|
|
116
|
-
*/
|
|
117
|
-
async checkAvailability(operationType, customCost) {
|
|
118
|
-
return this.request("/api/v1/credits/availability", {
|
|
119
|
-
params: {
|
|
120
|
-
operationType,
|
|
121
|
-
customCost: customCost?.toString(),
|
|
122
|
-
},
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Reserve credits for an operation
|
|
127
|
-
*
|
|
128
|
-
* This is the first step in the two-phase commit pattern.
|
|
129
|
-
* Reserved credits are held for 5 minutes before expiring.
|
|
130
|
-
*
|
|
131
|
-
* @param operationType - Type of operation
|
|
132
|
-
* @param options - Optional reservation options
|
|
133
|
-
* @returns Reservation details including ID and expiry
|
|
134
|
-
* @throws InsufficientCreditsError if not enough credits
|
|
135
|
-
* @throws AuthenticationError if not authenticated
|
|
136
|
-
*/
|
|
137
|
-
async reserve(operationType, options) {
|
|
138
|
-
return this.request("/api/v1/credits/reserve", {
|
|
139
|
-
method: "POST",
|
|
140
|
-
body: {
|
|
141
|
-
operationType,
|
|
142
|
-
...options,
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Commit a reservation (deduct credits)
|
|
148
|
-
*
|
|
149
|
-
* This is the second step in the two-phase commit pattern.
|
|
150
|
-
* Call this after your operation succeeds.
|
|
151
|
-
*
|
|
152
|
-
* @param reservationId - ID of the reservation to commit
|
|
153
|
-
* @throws ReservationNotFoundError if reservation doesn't exist
|
|
154
|
-
* @throws ReservationExpiredError if reservation has expired
|
|
155
|
-
* @throws AuthenticationError if not authenticated
|
|
156
|
-
*/
|
|
157
|
-
async commit(reservationId) {
|
|
158
|
-
await this.request("/api/v1/credits/commit", {
|
|
159
|
-
method: "POST",
|
|
160
|
-
body: { reservationId },
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Release a reservation (refund credits)
|
|
165
|
-
*
|
|
166
|
-
* Call this if your operation fails after reserving credits.
|
|
167
|
-
*
|
|
168
|
-
* @param reservationId - ID of the reservation to release
|
|
169
|
-
* @throws ReservationNotFoundError if reservation doesn't exist
|
|
170
|
-
* @throws AuthenticationError if not authenticated
|
|
171
|
-
*/
|
|
172
|
-
async release(reservationId) {
|
|
173
|
-
await this.request("/api/v1/credits/release", {
|
|
174
|
-
method: "POST",
|
|
175
|
-
body: { reservationId },
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Get usage history for the current user
|
|
180
|
-
*
|
|
181
|
-
* @param options - Optional pagination options
|
|
182
|
-
* @returns Paginated list of usage entries
|
|
183
|
-
* @throws AuthenticationError if not authenticated
|
|
184
|
-
*/
|
|
185
|
-
async getHistory(options) {
|
|
186
|
-
return this.request("/api/v1/credits/history", {
|
|
187
|
-
params: {
|
|
188
|
-
page: options?.page,
|
|
189
|
-
limit: options?.limit,
|
|
190
|
-
},
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Get the available credits (balance + bonus - reserved)
|
|
195
|
-
*
|
|
196
|
-
* Convenience method that calculates available credits from balance.
|
|
197
|
-
*
|
|
198
|
-
* @returns Number of available credits
|
|
199
|
-
* @throws AuthenticationError if not authenticated
|
|
200
|
-
*/
|
|
201
|
-
async getAvailableCredits() {
|
|
202
|
-
const balance = await this.getBalance();
|
|
203
|
-
return balance.balance + balance.bonusCredits - balance.reserved;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Execute an operation with automatic credit handling
|
|
207
|
-
*
|
|
208
|
-
* This is a convenience method that handles the full two-phase commit
|
|
209
|
-
* pattern automatically.
|
|
210
|
-
*
|
|
211
|
-
* @param operationType - Type of operation
|
|
212
|
-
* @param operation - The operation to execute
|
|
213
|
-
* @param options - Optional reservation options
|
|
214
|
-
* @returns Result of the operation
|
|
215
|
-
* @throws InsufficientCreditsError if not enough credits
|
|
216
|
-
* @throws AuthenticationError if not authenticated
|
|
217
|
-
*
|
|
218
|
-
* @example
|
|
219
|
-
* ```typescript
|
|
220
|
-
* const result = await client.withCredits(
|
|
221
|
-
* "story_generation",
|
|
222
|
-
* async () => {
|
|
223
|
-
* return generateStory(data);
|
|
224
|
-
* }
|
|
225
|
-
* );
|
|
226
|
-
* ```
|
|
227
|
-
*/
|
|
228
|
-
async withCredits(operationType, operation, options) {
|
|
229
|
-
const reservation = await this.reserve(operationType, options);
|
|
230
|
-
try {
|
|
231
|
-
const result = await operation();
|
|
232
|
-
await this.commit(reservation.reservationId);
|
|
233
|
-
return result;
|
|
234
|
-
}
|
|
235
|
-
catch (error) {
|
|
236
|
-
// Always attempt to release on failure
|
|
237
|
-
try {
|
|
238
|
-
await this.release(reservation.reservationId);
|
|
239
|
-
}
|
|
240
|
-
catch {
|
|
241
|
-
// Ignore release errors, original error is more important
|
|
242
|
-
}
|
|
243
|
-
throw error;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
//# sourceMappingURL=client.js.map
|
package/dist/sdk/client.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/sdk/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAUH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,OAAO,aAAa;IACP,OAAO,CAAS;IAChB,YAAY,CAAyB;IACrC,OAAO,CAAe;IAEvC,YAAY,MAA2B;QACrC,6CAA6C;Q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C;QAE/D,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;YACjC,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;YAC7C,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,uCAAuC;YACvC,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;YAChD,CAAC;YAAC,MAAM,CAAC;gBACP,0DAA0D;YAC5D,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
package/dist/sdk/errors.d.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SDK error classes
|
|
3
|
-
*
|
|
4
|
-
* Provides typed error handling for SDK operations.
|
|
5
|
-
*/
|
|
6
|
-
import { type SDKErrorCodeType } from "./types.js";
|
|
7
|
-
/**
|
|
8
|
-
* Base error class for SDK errors
|
|
9
|
-
*/
|
|
10
|
-
export declare class CreditsSDKError extends Error {
|
|
11
|
-
readonly code: SDKErrorCodeType;
|
|
12
|
-
readonly details?: Record<string, unknown>;
|
|
13
|
-
readonly statusCode?: number;
|
|
14
|
-
constructor(message: string, code: SDKErrorCodeType, options?: {
|
|
15
|
-
details?: Record<string, unknown>;
|
|
16
|
-
statusCode?: number;
|
|
17
|
-
cause?: Error;
|
|
18
|
-
});
|
|
19
|
-
/**
|
|
20
|
-
* Check if this is a specific error type
|
|
21
|
-
*/
|
|
22
|
-
is(code: SDKErrorCodeType): boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Create a JSON representation for logging
|
|
25
|
-
*/
|
|
26
|
-
toJSON(): Record<string, unknown>;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Error thrown when a network request fails
|
|
30
|
-
*/
|
|
31
|
-
export declare class NetworkError extends CreditsSDKError {
|
|
32
|
-
constructor(message: string, cause?: Error);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Error thrown when authentication fails
|
|
36
|
-
*/
|
|
37
|
-
export declare class AuthenticationError extends CreditsSDKError {
|
|
38
|
-
constructor(message?: string);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Error thrown when authorization fails
|
|
42
|
-
*/
|
|
43
|
-
export declare class AuthorizationError extends CreditsSDKError {
|
|
44
|
-
constructor(message?: string);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Error thrown when credits are insufficient
|
|
48
|
-
*/
|
|
49
|
-
export declare class InsufficientCreditsError extends CreditsSDKError {
|
|
50
|
-
readonly available: number;
|
|
51
|
-
readonly required: number;
|
|
52
|
-
constructor(available: number, required: number);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Error thrown when a reservation is not found
|
|
56
|
-
*/
|
|
57
|
-
export declare class ReservationNotFoundError extends CreditsSDKError {
|
|
58
|
-
readonly reservationId: string;
|
|
59
|
-
constructor(reservationId: string);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Error thrown when a reservation has expired
|
|
63
|
-
*/
|
|
64
|
-
export declare class ReservationExpiredError extends CreditsSDKError {
|
|
65
|
-
readonly reservationId: string;
|
|
66
|
-
constructor(reservationId: string);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Error thrown for validation failures
|
|
70
|
-
*/
|
|
71
|
-
export declare class ValidationError extends CreditsSDKError {
|
|
72
|
-
readonly field?: string;
|
|
73
|
-
constructor(message: string, field?: string);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Error thrown for server errors
|
|
77
|
-
*/
|
|
78
|
-
export declare class ServerError extends CreditsSDKError {
|
|
79
|
-
constructor(message?: string);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Parse an API error response into the appropriate SDK error
|
|
83
|
-
*/
|
|
84
|
-
export declare function parseApiError(statusCode: number, body: {
|
|
85
|
-
error?: {
|
|
86
|
-
code?: string;
|
|
87
|
-
message?: string;
|
|
88
|
-
details?: unknown;
|
|
89
|
-
};
|
|
90
|
-
}): CreditsSDKError;
|
|
91
|
-
//# sourceMappingURL=errors.d.ts.map
|
package/dist/sdk/errors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/sdk/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEjE;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,SAAgB,IAAI,EAAE,gBAAgB,CAAC;IACvC,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClD,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;gBAGlC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,gBAAgB,EACtB,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,KAAK,CAAC,EAAE,KAAK,CAAC;KACf;IASH;;OAEG;IACH,EAAE,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO;IAInC;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CASlC;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,eAAe;gBACnC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAI3C;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,eAAe;gBAC1C,OAAO,GAAE,MAAkC;CAIxD;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,eAAe;gBACzC,OAAO,GAAE,MAAwB;CAI9C;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,eAAe;IAC3D,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAErB,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAahD;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,eAAe;IAC3D,SAAgB,aAAa,EAAE,MAAM,CAAC;gBAE1B,aAAa,EAAE,MAAM;CAYlC;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,eAAe;IAC1D,SAAgB,aAAa,EAAE,MAAM,CAAC;gBAE1B,aAAa,EAAE,MAAM;CAYlC;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,eAAe;IAClD,SAAgB,KAAK,CAAC,EAAE,MAAM,CAAC;gBAEnB,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAQ5C;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,eAAe;gBAClC,OAAO,GAAE,MAAgC;CAItD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE;IAAE,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,GACvE,eAAe,CAmDjB"}
|
package/dist/sdk/errors.js
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SDK error classes
|
|
3
|
-
*
|
|
4
|
-
* Provides typed error handling for SDK operations.
|
|
5
|
-
*/
|
|
6
|
-
import { SDKErrorCode } from "./types.js";
|
|
7
|
-
/**
|
|
8
|
-
* Base error class for SDK errors
|
|
9
|
-
*/
|
|
10
|
-
export class CreditsSDKError extends Error {
|
|
11
|
-
code;
|
|
12
|
-
details;
|
|
13
|
-
statusCode;
|
|
14
|
-
constructor(message, code, options) {
|
|
15
|
-
super(message, { cause: options?.cause });
|
|
16
|
-
this.name = "CreditsSDKError";
|
|
17
|
-
this.code = code;
|
|
18
|
-
this.details = options?.details;
|
|
19
|
-
this.statusCode = options?.statusCode;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Check if this is a specific error type
|
|
23
|
-
*/
|
|
24
|
-
is(code) {
|
|
25
|
-
return this.code === code;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Create a JSON representation for logging
|
|
29
|
-
*/
|
|
30
|
-
toJSON() {
|
|
31
|
-
return {
|
|
32
|
-
name: this.name,
|
|
33
|
-
message: this.message,
|
|
34
|
-
code: this.code,
|
|
35
|
-
details: this.details,
|
|
36
|
-
statusCode: this.statusCode,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Error thrown when a network request fails
|
|
42
|
-
*/
|
|
43
|
-
export class NetworkError extends CreditsSDKError {
|
|
44
|
-
constructor(message, cause) {
|
|
45
|
-
super(message, SDKErrorCode.NETWORK_ERROR, { cause });
|
|
46
|
-
this.name = "NetworkError";
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Error thrown when authentication fails
|
|
51
|
-
*/
|
|
52
|
-
export class AuthenticationError extends CreditsSDKError {
|
|
53
|
-
constructor(message = "Authentication required") {
|
|
54
|
-
super(message, SDKErrorCode.AUTHENTICATION_ERROR, { statusCode: 401 });
|
|
55
|
-
this.name = "AuthenticationError";
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Error thrown when authorization fails
|
|
60
|
-
*/
|
|
61
|
-
export class AuthorizationError extends CreditsSDKError {
|
|
62
|
-
constructor(message = "Access denied") {
|
|
63
|
-
super(message, SDKErrorCode.AUTHORIZATION_ERROR, { statusCode: 403 });
|
|
64
|
-
this.name = "AuthorizationError";
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Error thrown when credits are insufficient
|
|
69
|
-
*/
|
|
70
|
-
export class InsufficientCreditsError extends CreditsSDKError {
|
|
71
|
-
available;
|
|
72
|
-
required;
|
|
73
|
-
constructor(available, required) {
|
|
74
|
-
super(`Insufficient credits: available ${available}, required ${required}`, SDKErrorCode.INSUFFICIENT_CREDITS, {
|
|
75
|
-
statusCode: 402,
|
|
76
|
-
details: { available, required },
|
|
77
|
-
});
|
|
78
|
-
this.name = "InsufficientCreditsError";
|
|
79
|
-
this.available = available;
|
|
80
|
-
this.required = required;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Error thrown when a reservation is not found
|
|
85
|
-
*/
|
|
86
|
-
export class ReservationNotFoundError extends CreditsSDKError {
|
|
87
|
-
reservationId;
|
|
88
|
-
constructor(reservationId) {
|
|
89
|
-
super(`Reservation not found: ${reservationId}`, SDKErrorCode.RESERVATION_NOT_FOUND, {
|
|
90
|
-
statusCode: 404,
|
|
91
|
-
details: { reservationId },
|
|
92
|
-
});
|
|
93
|
-
this.name = "ReservationNotFoundError";
|
|
94
|
-
this.reservationId = reservationId;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Error thrown when a reservation has expired
|
|
99
|
-
*/
|
|
100
|
-
export class ReservationExpiredError extends CreditsSDKError {
|
|
101
|
-
reservationId;
|
|
102
|
-
constructor(reservationId) {
|
|
103
|
-
super(`Reservation expired: ${reservationId}`, SDKErrorCode.RESERVATION_EXPIRED, {
|
|
104
|
-
statusCode: 410,
|
|
105
|
-
details: { reservationId },
|
|
106
|
-
});
|
|
107
|
-
this.name = "ReservationExpiredError";
|
|
108
|
-
this.reservationId = reservationId;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Error thrown for validation failures
|
|
113
|
-
*/
|
|
114
|
-
export class ValidationError extends CreditsSDKError {
|
|
115
|
-
field;
|
|
116
|
-
constructor(message, field) {
|
|
117
|
-
super(message, SDKErrorCode.VALIDATION_ERROR, {
|
|
118
|
-
statusCode: 400,
|
|
119
|
-
details: field ? { field } : undefined,
|
|
120
|
-
});
|
|
121
|
-
this.name = "ValidationError";
|
|
122
|
-
this.field = field;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Error thrown for server errors
|
|
127
|
-
*/
|
|
128
|
-
export class ServerError extends CreditsSDKError {
|
|
129
|
-
constructor(message = "Internal server error") {
|
|
130
|
-
super(message, SDKErrorCode.SERVER_ERROR, { statusCode: 500 });
|
|
131
|
-
this.name = "ServerError";
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Parse an API error response into the appropriate SDK error
|
|
136
|
-
*/
|
|
137
|
-
export function parseApiError(statusCode, body) {
|
|
138
|
-
const errorCode = body.error?.code || "";
|
|
139
|
-
const errorMessage = body.error?.message || "An error occurred";
|
|
140
|
-
const details = body.error?.details;
|
|
141
|
-
switch (statusCode) {
|
|
142
|
-
case 401:
|
|
143
|
-
return new AuthenticationError(errorMessage);
|
|
144
|
-
case 403:
|
|
145
|
-
return new AuthorizationError(errorMessage);
|
|
146
|
-
case 402:
|
|
147
|
-
// Parse insufficient credits details
|
|
148
|
-
if (details?.available !== undefined && details?.required !== undefined) {
|
|
149
|
-
return new InsufficientCreditsError(details.available, details.required);
|
|
150
|
-
}
|
|
151
|
-
return new CreditsSDKError(errorMessage, SDKErrorCode.INSUFFICIENT_CREDITS, {
|
|
152
|
-
statusCode,
|
|
153
|
-
details,
|
|
154
|
-
});
|
|
155
|
-
case 404:
|
|
156
|
-
if (errorCode === "RESERVATION_NOT_FOUND" && details?.reservationId) {
|
|
157
|
-
return new ReservationNotFoundError(details.reservationId);
|
|
158
|
-
}
|
|
159
|
-
return new CreditsSDKError(errorMessage, SDKErrorCode.RESERVATION_NOT_FOUND, {
|
|
160
|
-
statusCode,
|
|
161
|
-
details,
|
|
162
|
-
});
|
|
163
|
-
case 410:
|
|
164
|
-
if (errorCode === "RESERVATION_EXPIRED" && details?.reservationId) {
|
|
165
|
-
return new ReservationExpiredError(details.reservationId);
|
|
166
|
-
}
|
|
167
|
-
return new CreditsSDKError(errorMessage, SDKErrorCode.RESERVATION_EXPIRED, {
|
|
168
|
-
statusCode,
|
|
169
|
-
details,
|
|
170
|
-
});
|
|
171
|
-
case 400:
|
|
172
|
-
case 422:
|
|
173
|
-
return new ValidationError(errorMessage, details?.field);
|
|
174
|
-
case 500:
|
|
175
|
-
default:
|
|
176
|
-
if (statusCode >= 500) {
|
|
177
|
-
return new ServerError(errorMessage);
|
|
178
|
-
}
|
|
179
|
-
return new CreditsSDKError(errorMessage, SDKErrorCode.UNKNOWN_ERROR, {
|
|
180
|
-
statusCode,
|
|
181
|
-
details,
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
//# sourceMappingURL=errors.js.map
|
package/dist/sdk/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/sdk/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAyB,MAAM,YAAY,CAAC;AAEjE;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxB,IAAI,CAAmB;IACvB,OAAO,CAA2B;IAClC,UAAU,CAAU;IAEpC,YACE,OAAe,EACf,IAAsB,EACtB,OAIC;QAED,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,CAAC;QAChC,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,UAAU,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,EAAE,CAAC,IAAsB;QACvB,OAAO,IAAI,CAAC,IAAI,KAA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,CAAC,qBAAqB,EAAE;gBAC3E,UAAU;gBACV,OAAO;aACR,CAAC,CAAC;QACL,KAAK,GAAG;YACN,IAAI,SAAS,KAAK,qBAAqB,IAAI,OAAO,EAAE,aAAa,EAAE,CAAC;gBAClE,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,aAAuB,CAAC,CAAC;YACtE,CAAC;YACD,OAAO,IAAI,eAAe,CAAC,YAAY,EAAE,YAAY,CAAC,mBAAmB,EAAE;gBACzE,UAAU;gBACV,OAAO;aACR,CAAC,CAAC;QACL,KAAK,GAAG,CAAC;QACT,KAAK,GAAG;YACN,OAAO,IAAI,eAAe,CAAC,YAAY,EAAE,OAAO,EAAE,KAA2B,CAAC,CAAC;QACjF,KAAK,GAAG,CAAC;QACT;YACE,IAAI,UAAU,IAAI,GAAG,EAAE,CAAC;gBACtB,OAAO,IAAI,WAAW,CAAC,YAAY,CAAC,CAAC;YACvC,CAAC;YACD,OAAO,IAAI,eAAe,CAAC,YAAY,EAAE,YAAY,CAAC,aAAa,EAAE;gBACnE,UAAU;gBACV,OAAO;aACR,CAAC,CAAC;IACP,CAAC;AACH,CAAC"}
|
package/dist/sdk/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sdk/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGvD,YAAY,EACV,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,WAAW,EACX,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C,OAAO,EACL,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,eAAe,EACf,WAAW,EACX,aAAa,GACd,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC"}
|
package/dist/sdk/types.d.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SDK types for the credits system
|
|
3
|
-
*
|
|
4
|
-
* These types are used by the client SDKs for REST API consumption.
|
|
5
|
-
*/
|
|
6
|
-
export type { PortableUserCredits as UserCredits, PortableReservation as CreditReservation, CreditCheckResult, SubscriptionTier, } from "../core/types.js";
|
|
7
|
-
/**
|
|
8
|
-
* Configuration for CreditsClient
|
|
9
|
-
*/
|
|
10
|
-
export interface CreditsClientConfig {
|
|
11
|
-
/** Base URL of the credits API (e.g., "https://api.example.com") */
|
|
12
|
-
baseUrl: string;
|
|
13
|
-
/** Function to get the auth token for session-based auth */
|
|
14
|
-
getAuthToken?: () => Promise<string>;
|
|
15
|
-
/** Optional custom fetch function for testing */
|
|
16
|
-
fetch?: typeof fetch;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Configuration for AdminCreditsClient
|
|
20
|
-
*/
|
|
21
|
-
export interface AdminCreditsClientConfig {
|
|
22
|
-
/** Base URL of the credits API */
|
|
23
|
-
baseUrl: string;
|
|
24
|
-
/** Admin API key */
|
|
25
|
-
apiKey: string;
|
|
26
|
-
/** Optional custom fetch function for testing */
|
|
27
|
-
fetch?: typeof fetch;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Result of a credit reservation
|
|
31
|
-
*/
|
|
32
|
-
export interface ReservationResult {
|
|
33
|
-
/** The reservation ID */
|
|
34
|
-
reservationId: string;
|
|
35
|
-
/** Amount of credits reserved */
|
|
36
|
-
amount: number;
|
|
37
|
-
/** When the reservation expires (ISO 8601) */
|
|
38
|
-
expiresAt: string;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Pagination options for API requests
|
|
42
|
-
*/
|
|
43
|
-
export interface PaginationOptions {
|
|
44
|
-
/** Page number (1-indexed) */
|
|
45
|
-
page?: number;
|
|
46
|
-
/** Number of items per page */
|
|
47
|
-
limit?: number;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Usage history entry
|
|
51
|
-
*/
|
|
52
|
-
export interface UsageHistoryEntry {
|
|
53
|
-
/** Unique ID of the usage log */
|
|
54
|
-
id: string;
|
|
55
|
-
/** Type of operation */
|
|
56
|
-
operationType: string;
|
|
57
|
-
/** AI provider used */
|
|
58
|
-
provider: string;
|
|
59
|
-
/** Credits consumed */
|
|
60
|
-
creditsUsed: number;
|
|
61
|
-
/** Whether the operation was successful */
|
|
62
|
-
success: boolean;
|
|
63
|
-
/** Error message if unsuccessful */
|
|
64
|
-
errorMessage?: string;
|
|
65
|
-
/** ID of the related resource */
|
|
66
|
-
resourceId?: string;
|
|
67
|
-
/** Type of the related resource */
|
|
68
|
-
resourceType?: string;
|
|
69
|
-
/** When the operation occurred (ISO 8601) */
|
|
70
|
-
createdAt: string;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Response from usage history endpoint
|
|
74
|
-
*/
|
|
75
|
-
export interface UsageHistoryResponse {
|
|
76
|
-
/** List of usage entries */
|
|
77
|
-
entries: UsageHistoryEntry[];
|
|
78
|
-
/** Whether there are more results */
|
|
79
|
-
hasMore: boolean;
|
|
80
|
-
/** Total count (if available) */
|
|
81
|
-
total?: number;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Generic API response wrapper
|
|
85
|
-
*/
|
|
86
|
-
export interface ApiResponse<T> {
|
|
87
|
-
success: boolean;
|
|
88
|
-
data?: T;
|
|
89
|
-
error?: {
|
|
90
|
-
code: string;
|
|
91
|
-
message: string;
|
|
92
|
-
details?: unknown;
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* SDK error codes
|
|
97
|
-
*/
|
|
98
|
-
export declare const SDKErrorCode: {
|
|
99
|
-
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
100
|
-
readonly AUTHENTICATION_ERROR: "AUTHENTICATION_ERROR";
|
|
101
|
-
readonly AUTHORIZATION_ERROR: "AUTHORIZATION_ERROR";
|
|
102
|
-
readonly INSUFFICIENT_CREDITS: "INSUFFICIENT_CREDITS";
|
|
103
|
-
readonly RESERVATION_NOT_FOUND: "RESERVATION_NOT_FOUND";
|
|
104
|
-
readonly RESERVATION_EXPIRED: "RESERVATION_EXPIRED";
|
|
105
|
-
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
106
|
-
readonly SERVER_ERROR: "SERVER_ERROR";
|
|
107
|
-
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
108
|
-
};
|
|
109
|
-
export type SDKErrorCodeType = (typeof SDKErrorCode)[keyof typeof SDKErrorCode];
|
|
110
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/sdk/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sdk/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EACV,mBAAmB,IAAI,WAAW,EAClC,mBAAmB,IAAI,iBAAiB,EACxC,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IACrC,iDAAiD;IACjD,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,kCAAkC;IAClC,OAAO,EAAE,MAAM,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N,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;CACH;AAED;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;CAUf,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC"}
|
package/dist/sdk/types.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SDK types for the credits system
|
|
3
|
-
*
|
|
4
|
-
* These types are used by the client SDKs for REST API consumption.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* SDK error codes
|
|
8
|
-
*/
|
|
9
|
-
export const SDKErrorCode = {
|
|
10
|
-
NETWORK_ERROR: "NETWORK_ERROR",
|
|
11
|
-
AUTHENTICATION_ERROR: "AUTHENTICATION_ERROR",
|
|
12
|
-
AUTHORIZATION_ERROR: "AUTHORIZATION_ERROR",
|
|
13
|
-
INSUFFICIENT_CREDITS: "INSUFFICIENT_CREDITS",
|
|
14
|
-
RESERVATION_NOT_FOUND: "RESERVATION_NOT_FOUND",
|
|
15
|
-
RESERVATION_EXPIRED: "RESERVATION_EXPIRED",
|
|
16
|
-
VALIDATION_ERROR: "VALIDATION_ERROR",
|
|
17
|
-
SERVER_ERROR: "SERVER_ERROR",
|
|
18
|
-
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=types.js.map
|