@tuwaio/quasar-sdk 0.1.12 → 0.2.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 +52 -459
- package/dist/chunk-NJH5FYLU.cjs +2 -0
- package/dist/chunk-YPUBFZPR.js +2 -0
- package/dist/cli.cjs +44 -68
- package/dist/index.cjs +1 -2
- package/dist/index.d.cts +113 -202
- package/dist/index.d.ts +113 -202
- package/dist/index.js +1 -2
- package/dist/react.cjs +1 -0
- package/dist/react.d.cts +28 -0
- package/dist/react.d.ts +28 -0
- package/dist/react.js +1 -0
- package/package.json +24 -57
package/dist/index.d.ts
CHANGED
|
@@ -3,79 +3,84 @@ import { Transaction } from '@tuwaio/pulsar-core';
|
|
|
3
3
|
export { Transaction, TransactionStatus, TransactionTracker, UpdatableTransactionFields } from '@tuwaio/pulsar-core';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @
|
|
7
|
-
* @description Shared type definitions for the Quasar SDK.
|
|
8
|
-
* Contains configuration interfaces, query parameters, and authentication structures.
|
|
6
|
+
* @file Default URL and endpoint paths of the Quasar API.
|
|
9
7
|
*/
|
|
8
|
+
/** Base URL of Quasar Cloud, the default `baseUrl` of the `Quasar` client. */
|
|
9
|
+
declare const BASE_API_URL = "https://api.tuwa.io";
|
|
10
|
+
/** Path of the endpoint that `PulsarModule.syncCreate` calls (`POST`). */
|
|
11
|
+
declare const PULSAR_SYNC_ENDPOINT = "/v1/engine/pulsar/sync";
|
|
12
|
+
/** Path of the endpoint that `PulsarModule.getHistory` calls (`GET`). */
|
|
13
|
+
declare const PULSAR_HISTORY_ENDPOINT = "/v1/engine/pulsar/history";
|
|
14
|
+
|
|
10
15
|
/**
|
|
11
|
-
* Configuration
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
* @file Configuration, query and response types of the Quasar client, and the Pulsar transaction types it syncs.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Options of the {@link Quasar} client.
|
|
14
20
|
*/
|
|
15
21
|
interface QuasarConfig {
|
|
16
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Secret key of your Quasar app (`sk_live_...` for a live app, `sk_test_...` for a test app), sent in the
|
|
24
|
+
* `x-tuwa-secret-key` header of every request. Keep it on the server.
|
|
25
|
+
*/
|
|
17
26
|
secretKey: string;
|
|
18
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Secret of the internal endpoints of a Quasar deployment, sent in the `x-internal-secret` header when set. The
|
|
29
|
+
* Quasar dashboard uses it to call its own server; apps leave it unset.
|
|
30
|
+
*/
|
|
19
31
|
internalSecret?: string;
|
|
20
|
-
/**
|
|
32
|
+
/** Base URL of the Quasar API: Quasar Cloud or your self-hosted server. Defaults to {@link BASE_API_URL}. */
|
|
21
33
|
baseUrl?: string;
|
|
22
|
-
/** Request timeout in milliseconds. Defaults to 10000
|
|
34
|
+
/** Request timeout in milliseconds. Defaults to `10000`. */
|
|
23
35
|
timeout?: number;
|
|
24
36
|
}
|
|
25
37
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @public
|
|
38
|
+
* Filters and pagination of {@link PulsarModule.getHistory}. Every filter is optional; the API returns the
|
|
39
|
+
* transactions of your app that match all given filters.
|
|
29
40
|
*/
|
|
30
41
|
interface HistoryQuery {
|
|
31
|
-
/** Page number
|
|
42
|
+
/** Page number, starting at 1. Defaults to `1`. */
|
|
32
43
|
page?: number;
|
|
33
|
-
/**
|
|
44
|
+
/** Number of transactions per page. Defaults to `10`. */
|
|
34
45
|
limit?: number;
|
|
35
|
-
/**
|
|
46
|
+
/** Chain of the transactions: an EVM chain ID (`1`) or a Solana cluster (`'mainnet'`). */
|
|
36
47
|
chainId?: string | number;
|
|
37
|
-
/**
|
|
48
|
+
/** Final status of the transactions (`'Success'`, `'Failed'` or `'Replaced'`, see `TransactionStatus`). */
|
|
38
49
|
status?: string;
|
|
39
|
-
/**
|
|
50
|
+
/** Key of one transaction (`txKey` of the Pulsar transaction). */
|
|
40
51
|
txKey?: string;
|
|
41
|
-
/**
|
|
52
|
+
/** Application name that was passed to {@link PulsarModule.syncCreate}. */
|
|
42
53
|
appName?: string;
|
|
43
|
-
/**
|
|
54
|
+
/** Address of the wallet that sent the transactions. */
|
|
44
55
|
walletAddress?: string;
|
|
45
56
|
}
|
|
46
57
|
/**
|
|
47
|
-
*
|
|
58
|
+
* One page of results.
|
|
48
59
|
*
|
|
49
|
-
* @typeParam T -
|
|
50
|
-
* @public
|
|
60
|
+
* @typeParam T - Type of the documents on the page.
|
|
51
61
|
*/
|
|
52
62
|
interface PaginatedResult<T> {
|
|
53
|
-
/**
|
|
63
|
+
/** Documents of the current page. */
|
|
54
64
|
docs: T[];
|
|
55
|
-
/**
|
|
65
|
+
/** Number of documents that match the query. */
|
|
56
66
|
totalDocs: number;
|
|
57
|
-
/**
|
|
67
|
+
/** Number of pages. */
|
|
58
68
|
totalPages: number;
|
|
59
|
-
/**
|
|
69
|
+
/** Current page number, starting at 1. */
|
|
60
70
|
page: number;
|
|
61
|
-
/**
|
|
71
|
+
/** Whether a next page exists. */
|
|
62
72
|
hasNextPage: boolean;
|
|
63
|
-
/**
|
|
73
|
+
/** Whether a previous page exists. */
|
|
64
74
|
hasPrevPage: boolean;
|
|
65
75
|
}
|
|
66
76
|
|
|
67
77
|
/**
|
|
68
|
-
* @
|
|
69
|
-
* @description Core HTTP client for the Quasar SDK.
|
|
70
|
-
* Handles authenticated requests through the Iron Dome security perimeter
|
|
71
|
-
* and provides structured error handling for all API interactions.
|
|
78
|
+
* @file HTTP client of the Quasar SDK: authentication headers, timeout and errors.
|
|
72
79
|
*/
|
|
73
80
|
|
|
74
81
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* Wraps the underlying HTTP error with a structured format including
|
|
78
|
-
* status code, human-readable message, and the original error reference.
|
|
82
|
+
* Error thrown by the methods of the {@link Quasar} client when a request fails: an HTTP error status, a timeout or a
|
|
83
|
+
* network error.
|
|
79
84
|
*
|
|
80
85
|
* @example
|
|
81
86
|
* ```typescript
|
|
@@ -84,36 +89,30 @@ interface PaginatedResult<T> {
|
|
|
84
89
|
* } catch (err) {
|
|
85
90
|
* if (err instanceof QuasarSDKError) {
|
|
86
91
|
* console.error(err.status); // e.g. 401
|
|
87
|
-
* console.error(err.message); // "[Quasar SDK] Request Failed (401):
|
|
88
|
-
* console.error(err.originalError); //
|
|
92
|
+
* console.error(err.message); // "[Quasar SDK] Request Failed (401): <error of the API>"
|
|
93
|
+
* console.error(err.originalError); // FetchError from ofetch
|
|
89
94
|
* }
|
|
90
95
|
* }
|
|
91
96
|
* ```
|
|
92
97
|
*/
|
|
93
98
|
declare class QuasarSDKError extends Error {
|
|
94
|
-
/** HTTP status code
|
|
99
|
+
/** HTTP status code of the response, or `undefined` when no response was received. */
|
|
95
100
|
readonly status: number | undefined;
|
|
96
|
-
/** The
|
|
101
|
+
/** The error thrown by `ofetch`. */
|
|
97
102
|
readonly originalError: Error;
|
|
98
103
|
/**
|
|
99
|
-
* Creates
|
|
104
|
+
* Creates the error.
|
|
100
105
|
*
|
|
101
|
-
* @param message -
|
|
102
|
-
*
|
|
103
|
-
* @param
|
|
106
|
+
* @param message - Message: `[Quasar SDK] Request Failed (<status>): <error>`, where `<error>` is the `error` field of
|
|
107
|
+
* the response body or the message of the fetch error.
|
|
108
|
+
* @param status - HTTP status code, or `undefined` when no response was received.
|
|
109
|
+
* @param originalError - The error thrown by `ofetch`.
|
|
104
110
|
*/
|
|
105
111
|
constructor(message: string, status: number | undefined, originalError: Error);
|
|
106
112
|
}
|
|
107
113
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* Manages authenticated requests by injecting the `x-tuwa-secret-key` header
|
|
111
|
-
* into every outgoing request. Optionally injects `x-internal-secret`
|
|
112
|
-
* when it is provided in the SDK config. Uses `ofetch` as the transport layer.
|
|
113
|
-
*
|
|
114
|
-
* @remarks
|
|
115
|
-
* This class is not exported from the public API surface.
|
|
116
|
-
* Consumers interact with it indirectly through the {@link Quasar} entry point.
|
|
114
|
+
* HTTP client shared by the modules of the {@link Quasar} client. Sends every request with the `x-tuwa-secret-key`
|
|
115
|
+
* header (and `x-internal-secret` when configured) through `ofetch`.
|
|
117
116
|
*
|
|
118
117
|
* @internal
|
|
119
118
|
*/
|
|
@@ -127,217 +126,129 @@ declare class QuasarClient {
|
|
|
127
126
|
/** Request timeout in milliseconds. */
|
|
128
127
|
private readonly timeout;
|
|
129
128
|
/**
|
|
130
|
-
* Creates
|
|
129
|
+
* Creates the client.
|
|
131
130
|
*
|
|
132
|
-
* @param config -
|
|
133
|
-
* @throws {Error} If `config.secretKey` is
|
|
131
|
+
* @param config - Secret key and optional overrides.
|
|
132
|
+
* @throws {Error} If `config.secretKey` is empty.
|
|
134
133
|
*/
|
|
135
134
|
constructor(config: QuasarConfig);
|
|
136
135
|
/**
|
|
137
|
-
* Sends
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* @
|
|
144
|
-
* @
|
|
145
|
-
* @param options - Fetch options (method, body, query, headers, etc.).
|
|
146
|
-
* `baseURL` and `timeout` are managed internally and cannot be overridden.
|
|
147
|
-
* @returns The parsed JSON response body typed as `T`.
|
|
148
|
-
* @throws {QuasarSDKError} On any HTTP or network error.
|
|
136
|
+
* Sends a request with the `Content-Type: application/json` and `x-tuwa-secret-key` headers (and
|
|
137
|
+
* `x-internal-secret` when configured).
|
|
138
|
+
*
|
|
139
|
+
* @typeParam T - Type of the response body.
|
|
140
|
+
* @param path - Endpoint path, for example `/v1/engine/pulsar/sync`.
|
|
141
|
+
* @param options - `ofetch` options (method, body, query, headers). `baseURL` and `timeout` come from the config.
|
|
142
|
+
* @returns The parsed JSON response body.
|
|
143
|
+
* @throws {QuasarSDKError} On an HTTP error status, a timeout or a network error.
|
|
149
144
|
*/
|
|
150
145
|
request<T>(path: string, options?: Omit<FetchOptions<'json'>, 'baseURL' | 'timeout'>): Promise<T>;
|
|
151
146
|
/**
|
|
152
|
-
*
|
|
147
|
+
* Wraps an `ofetch` error in a {@link QuasarSDKError}. Side effect: logs a `console.error` on a 401 or 403 status.
|
|
153
148
|
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* @param error - The raw error caught from `ofetch`.
|
|
158
|
-
* @returns A formatted QuasarSDKError instance.
|
|
149
|
+
* @param error - The error thrown by `ofetch`.
|
|
150
|
+
* @returns The wrapped error.
|
|
159
151
|
*/
|
|
160
152
|
private buildError;
|
|
161
153
|
}
|
|
162
154
|
|
|
163
155
|
/**
|
|
164
|
-
* @module
|
|
165
|
-
* @description Pulsar Transaction Engine module.
|
|
166
|
-
* Provides methods for syncing transaction states to the Quasar Cloud
|
|
167
|
-
* and retrieving paginated transaction history.
|
|
156
|
+
* @file Pulsar module of the Quasar client: transaction sync and history.
|
|
168
157
|
*/
|
|
169
158
|
|
|
170
159
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* It allows developers to sync transaction states (EVM, Solana, Starknet) to the cloud for
|
|
175
|
-
* persistent tracking and to retrieve comprehensive transaction histories.
|
|
176
|
-
*
|
|
177
|
-
* @remarks
|
|
178
|
-
* Access this module via `quasar.pulsar` after initializing the {@link Quasar} SDK.
|
|
179
|
-
* All methods are authenticated automatically using the configured secret key.
|
|
160
|
+
* Transaction sync and history of the Quasar API, available as `quasar.pulsar` on a {@link Quasar} client. Quasar
|
|
161
|
+
* tracks every synced transaction on the server until it reaches a final status, so the status survives a closed tab,
|
|
162
|
+
* and returns the history of your app for any device.
|
|
180
163
|
*
|
|
181
164
|
* @example
|
|
182
|
-
* ```
|
|
183
|
-
*
|
|
165
|
+
* ```ts
|
|
166
|
+
* import { Quasar, type Transaction } from '@tuwaio/quasar-sdk';
|
|
184
167
|
*
|
|
185
|
-
*
|
|
186
|
-
* const { txKey } = await quasar.pulsar.syncCreate(transaction);
|
|
168
|
+
* const quasar = new Quasar({ secretKey: process.env.QUASAR_SECRET_KEY ?? '' });
|
|
187
169
|
*
|
|
188
|
-
* //
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* }
|
|
170
|
+
* // Called by the `onRemoteCreate` callback of the Pulsar store (through a Server Action) with the new transaction.
|
|
171
|
+
* export async function syncTransaction(tx: Transaction) {
|
|
172
|
+
* const { txKey } = await quasar.pulsar.syncCreate(tx, 'my-app');
|
|
173
|
+
* return txKey;
|
|
174
|
+
* }
|
|
193
175
|
* ```
|
|
194
176
|
*/
|
|
195
177
|
declare class PulsarModule {
|
|
196
178
|
private readonly client;
|
|
197
179
|
/**
|
|
198
|
-
* Creates
|
|
180
|
+
* Creates the module. The {@link Quasar} client creates it for you.
|
|
199
181
|
*
|
|
200
|
-
* @param client - The
|
|
182
|
+
* @param client - The HTTP client of the Quasar client.
|
|
201
183
|
* @internal
|
|
202
184
|
*/
|
|
203
185
|
constructor(client: QuasarClient);
|
|
204
186
|
/**
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
* @param
|
|
211
|
-
* @
|
|
212
|
-
*
|
|
213
|
-
* @throws {QuasarSDKError}
|
|
214
|
-
*
|
|
215
|
-
* @example
|
|
216
|
-
* ```typescript
|
|
217
|
-
* const result = await quasar.pulsar.syncCreate({
|
|
218
|
-
* hash: '0xabc...',
|
|
219
|
-
* chainId: 1,
|
|
220
|
-
* status: 'pending',
|
|
221
|
-
* from: '0x123...',
|
|
222
|
-
* to: '0x456...',
|
|
223
|
-
* // ... other transaction fields
|
|
224
|
-
* }, 'My Dashboard');
|
|
225
|
-
*
|
|
226
|
-
* console.log(result.txKey); // The unique key for this transaction
|
|
227
|
-
* ```
|
|
187
|
+
* Sends a new Pulsar transaction to Quasar, which starts tracking it on the server (`POST /v1/engine/pulsar/sync`).
|
|
188
|
+
* Sending a transaction with a `txKey` that Quasar already has does not create a second record: the response has
|
|
189
|
+
* `duplicate: true`.
|
|
190
|
+
*
|
|
191
|
+
* @param tx - The transaction created by Pulsar, as passed to `onRemoteCreate` of `createPulsarStore`.
|
|
192
|
+
* @param appName - Application name saved with the transaction; filter the history by it with `appName`.
|
|
193
|
+
* @returns `txKey` of the transaction and the tracking `mode`: `fast` (tracked right away) or `lazy` (queued, for
|
|
194
|
+
* example when the quota of the organization is used up).
|
|
195
|
+
* @throws {QuasarSDKError} On an invalid transaction (400), an invalid key (401, 403), a timeout or a network error.
|
|
228
196
|
*/
|
|
229
197
|
syncCreate(tx: Transaction, appName?: string): Promise<{
|
|
230
198
|
success: true;
|
|
231
199
|
txKey: string;
|
|
200
|
+
mode: 'fast' | 'lazy';
|
|
201
|
+
duplicate?: true;
|
|
232
202
|
}>;
|
|
233
203
|
/**
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
* Supports advanced filtering by chain, status, wallet address, and more.
|
|
237
|
-
* Results are returned in a typed {@link PaginatedResult} wrapper.
|
|
204
|
+
* Reads the transactions of your app, newest first (`GET /v1/engine/pulsar/history`).
|
|
238
205
|
*
|
|
239
|
-
* @param query -
|
|
240
|
-
*
|
|
241
|
-
* @
|
|
206
|
+
* @param query - Filters and pagination. `walletAddress` is compared with the sender address exactly as it was
|
|
207
|
+
* synced; the API returns at most 100 transactions per page.
|
|
208
|
+
* @returns One page of transactions.
|
|
209
|
+
* @throws {QuasarSDKError} On an invalid key (401, 403), a timeout or a network error.
|
|
242
210
|
*
|
|
243
211
|
* @example
|
|
244
|
-
* ```
|
|
245
|
-
* const
|
|
246
|
-
*
|
|
247
|
-
* limit: 20,
|
|
248
|
-
* walletAddress: '6x...',
|
|
249
|
-
* });
|
|
250
|
-
*
|
|
251
|
-
* result.docs.forEach(tx => console.log(tx.txKey, tx.status));
|
|
212
|
+
* ```ts
|
|
213
|
+
* const page = await quasar.pulsar.getHistory({ walletAddress: '0x...', page: 1, limit: 20 });
|
|
214
|
+
* page.docs.forEach((tx) => console.log(tx.txKey, tx.status));
|
|
252
215
|
* ```
|
|
253
216
|
*/
|
|
254
217
|
getHistory(query?: HistoryQuery): Promise<PaginatedResult<Transaction>>;
|
|
255
218
|
}
|
|
256
219
|
|
|
257
|
-
declare const BASE_API_URL = "https://api.tuwa.io";
|
|
258
|
-
declare const PULSAR_SYNC_ENDPOINT = "/v1/engine/pulsar/sync";
|
|
259
|
-
declare const PULSAR_HISTORY_ENDPOINT = "/v1/engine/pulsar/history";
|
|
260
|
-
|
|
261
220
|
/**
|
|
262
|
-
* @
|
|
263
|
-
* The official server-side Node.js & Edge SDK for the TUWA Quasar Cloud.
|
|
264
|
-
*
|
|
265
|
-
* Provides a type-safe client for interacting with the Quasar API,
|
|
266
|
-
* including transaction syncing, status tracking, and history retrieval
|
|
267
|
-
* through the Iron Dome security perimeter.
|
|
268
|
-
*
|
|
269
|
-
* @example
|
|
270
|
-
* ```typescript
|
|
271
|
-
* import { Quasar } from '@tuwaio/quasar-sdk';
|
|
272
|
-
*
|
|
273
|
-
* const quasar = new Quasar({ secretKey: 'sk_live_...' });
|
|
274
|
-
* const history = await quasar.pulsar.getHistory({ chainId: 1 });
|
|
275
|
-
* ```
|
|
276
|
-
*
|
|
277
|
-
* @packageDocumentation
|
|
221
|
+
* @file The `Quasar` client, the entry point of the Quasar API.
|
|
278
222
|
*/
|
|
279
223
|
|
|
280
224
|
/**
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
* @param customApiUrl - Optional custom API URL to override the default.
|
|
285
|
-
* @throws {Error} If the session check fails or Quasar is unreachable.
|
|
286
|
-
*
|
|
287
|
-
* @public
|
|
288
|
-
*/
|
|
289
|
-
declare function preFlightTxCheck(customApiUrl?: string): Promise<void>;
|
|
290
|
-
/**
|
|
291
|
-
* Main entry point for the Quasar SDK.
|
|
292
|
-
*
|
|
293
|
-
* The `Quasar` class provides a unified interface for interacting with the Quasar Cloud API.
|
|
294
|
-
* It handles authentication, base URL configuration, and exposes domain-specific modules
|
|
295
|
-
* like {@link PulsarModule} for transaction management.
|
|
225
|
+
* Client of the Quasar API (Quasar Cloud at `https://api.tuwa.io`, or a self-hosted Quasar server). Create it on the
|
|
226
|
+
* server: it sends the secret key of your Quasar app with every request.
|
|
296
227
|
*
|
|
297
228
|
* @example
|
|
298
|
-
* ```
|
|
229
|
+
* ```ts
|
|
299
230
|
* import { Quasar } from '@tuwaio/quasar-sdk';
|
|
300
231
|
*
|
|
301
|
-
*
|
|
302
|
-
* const
|
|
303
|
-
* secretKey: 'sk_live_your_secret_key',
|
|
304
|
-
* baseUrl: 'https://api.tuwa.io', // Optional
|
|
305
|
-
* timeout: 10000, // Optional, default is 10s
|
|
306
|
-
* });
|
|
307
|
-
*
|
|
308
|
-
* // Access domain-specific modules
|
|
309
|
-
* const history = await quasar.pulsar.getHistory({ chainId: 1 });
|
|
232
|
+
* const quasar = new Quasar({ secretKey: process.env.QUASAR_SECRET_KEY ?? '' });
|
|
233
|
+
* const history = await quasar.pulsar.getHistory({ walletAddress: '0x...', limit: 20 });
|
|
310
234
|
* ```
|
|
311
|
-
*
|
|
312
|
-
* @public
|
|
313
235
|
*/
|
|
314
236
|
declare class Quasar {
|
|
315
237
|
/**
|
|
316
|
-
* The
|
|
238
|
+
* The HTTP client shared by the modules.
|
|
239
|
+
*
|
|
317
240
|
* @internal
|
|
318
241
|
*/
|
|
319
242
|
private readonly client;
|
|
320
|
-
/**
|
|
321
|
-
* The Pulsar Transaction Engine module.
|
|
322
|
-
*
|
|
323
|
-
* This module provides methods to sync transaction states to the Quasar Cloud
|
|
324
|
-
* and retrieve indexed transaction history across multiple blockchain networks.
|
|
325
|
-
*
|
|
326
|
-
* @see {@link PulsarModule}
|
|
327
|
-
*/
|
|
243
|
+
/** Syncs Pulsar transactions to Quasar and reads their history. */
|
|
328
244
|
readonly pulsar: PulsarModule;
|
|
329
245
|
/**
|
|
330
|
-
* Creates
|
|
246
|
+
* Creates the client. Sends no request.
|
|
331
247
|
*
|
|
332
|
-
* @param config -
|
|
333
|
-
* @throws {Error} If
|
|
334
|
-
*
|
|
335
|
-
* @example
|
|
336
|
-
* ```typescript
|
|
337
|
-
* const quasar = new Quasar({ secretKey: process.env.QUASAR_SECRET_KEY! });
|
|
338
|
-
* ```
|
|
248
|
+
* @param config - The secret key of the Quasar app and optional overrides.
|
|
249
|
+
* @throws {Error} If `config.secretKey` is empty.
|
|
339
250
|
*/
|
|
340
251
|
constructor(config: QuasarConfig);
|
|
341
252
|
}
|
|
342
253
|
|
|
343
|
-
export { BASE_API_URL, type HistoryQuery, PULSAR_HISTORY_ENDPOINT, PULSAR_SYNC_ENDPOINT, type PaginatedResult, PulsarModule, Quasar, type QuasarConfig, QuasarSDKError
|
|
254
|
+
export { BASE_API_URL, type HistoryQuery, PULSAR_HISTORY_ENDPOINT, PULSAR_SYNC_ENDPOINT, type PaginatedResult, PulsarModule, Quasar, type QuasarConfig, QuasarSDKError };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export{o as BASE_API_URL,u as PULSAR_HISTORY_ENDPOINT,c as PULSAR_SYNC_ENDPOINT,a as PulsarModule,l as Quasar,n as QuasarSDKError,A as preFlightTxCheck};
|
|
1
|
+
import {b,c,a as a$1}from'./chunk-YPUBFZPR.js';export{a as BASE_API_URL,c as PULSAR_HISTORY_ENDPOINT,b as PULSAR_SYNC_ENDPOINT}from'./chunk-YPUBFZPR.js';import {ofetch}from'ofetch';export{TransactionStatus,TransactionTracker}from'@tuwaio/pulsar-core';var a=class extends Error{status;originalError;constructor(r,e,t){super(r),this.name="QuasarSDKError",this.status=e,this.originalError=t;}},o=class{secretKey;internalSecret;baseUrl;timeout;constructor(r){if(!r.secretKey)throw new Error("[Quasar SDK] Missing API Key. Provide the secretKey of your Quasar app (sk_live_ or sk_test_).");this.secretKey=r.secretKey,this.internalSecret=r.internalSecret,this.baseUrl=r.baseUrl||a$1,this.timeout=r.timeout||1e4;}async request(r,e={}){try{return await ofetch(r,{baseURL:this.baseUrl,timeout:this.timeout,...e,headers:{"Content-Type":"application/json","x-tuwa-secret-key":this.secretKey,...this.internalSecret?{"x-internal-secret":this.internalSecret}:{},...e.headers}})}catch(t){throw this.buildError(t)}}buildError(r){let e=r,t=e.statusCode??e.response?.status,p=(e.data??e.response?._data)?.error??e.message??"Unknown Error";return (t===401||t===403)&&console.error("\u{1F6A8} [Quasar SDK] Auth Error. Check your Secret Key and scopes."),new a(`[Quasar SDK] Request Failed (${t}): ${p}`,t,e)}};var s=class{constructor(r){this.client=r;}async syncCreate(r,e){return this.client.request(b,{method:"POST",body:{...r,appName:e}})}async getHistory(r={}){return this.client.request(c,{method:"GET",query:{page:r.page??1,limit:r.limit??10,chainId:r.chainId,status:r.status,txKey:r.txKey,appName:r.appName,walletAddress:r.walletAddress}})}};var n=class{client;pulsar;constructor(r){this.client=new o(r),this.pulsar=new s(this.client);}};export{s as PulsarModule,n as Quasar,a as QuasarSDKError};
|
package/dist/react.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkNJH5FYLU_cjs=require('./chunk-NJH5FYLU.cjs'),siwxReact=require('@tuwaio/siwx-react');var i="/v1/engine/monitoring/health";async function u(s){if(!siwxReact.useSiwxSessionStore.getState().session)throw new Error("[QuasarSDK] No SIWX Session found. User must be signed in.");let o=(s||chunkNJH5FYLU_cjs.a).replace(/\/+$/,""),e;try{e=await fetch(`${o}${i}`,{method:"GET",cache:"no-store"});}catch(t){throw new Error("[QuasarSDK] Quasar Cloud Engine is currently unreachable.",{cause:t})}if(!e.ok)throw new Error(`[QuasarSDK] API Health check failed with status: ${e.status}`)}exports.preFlightTxCheck=u;
|
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser helper for React apps that sign users in with SIWX, imported from `@tuwaio/quasar-sdk/react`. This entry
|
|
3
|
+
* point needs `@tuwaio/siwx-react` (an optional peer dependency of the package); the root entry point does not.
|
|
4
|
+
*
|
|
5
|
+
* @module react
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Checks, before a transaction starts, that the user is signed in with SIWX and that the Quasar API responds. Use it
|
|
9
|
+
* as the `beforeTxProcess` callback of `createPulsarStore` from `@tuwaio/pulsar-core`: with the default
|
|
10
|
+
* `abortOnTxError: true`, an error aborts the transaction before the wallet is asked to sign it.
|
|
11
|
+
*
|
|
12
|
+
* The session check reads the client state of `useSiwxSessionStore` from `@tuwaio/siwx-react`. It is not proof of
|
|
13
|
+
* identity: the server that syncs the transaction must verify the session itself (for example with
|
|
14
|
+
* `getSiwxServerSession` from `@tuwaio/siwx-server`).
|
|
15
|
+
*
|
|
16
|
+
* Side effects: reads `useSiwxSessionStore` and sends `GET <apiUrl>/v1/engine/monitoring/health` without credentials
|
|
17
|
+
* and without the HTTP cache.
|
|
18
|
+
*
|
|
19
|
+
* @param customApiUrl - Base URL of the Quasar API. Defaults to {@link BASE_API_URL}.
|
|
20
|
+
* @returns Resolves when a session exists and the API answers with a 2xx status.
|
|
21
|
+
* @throws {Error} `[QuasarSDK] No SIWX Session found. User must be signed in.` when the store has no session.
|
|
22
|
+
* @throws {Error} `[QuasarSDK] Quasar Cloud Engine is currently unreachable.` when the request fails (network error,
|
|
23
|
+
* CORS); the original error is its `cause`.
|
|
24
|
+
* @throws {Error} `[QuasarSDK] API Health check failed with status: <status>` when the API answers with another status.
|
|
25
|
+
*/
|
|
26
|
+
declare function preFlightTxCheck(customApiUrl?: string): Promise<void>;
|
|
27
|
+
|
|
28
|
+
export { preFlightTxCheck };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser helper for React apps that sign users in with SIWX, imported from `@tuwaio/quasar-sdk/react`. This entry
|
|
3
|
+
* point needs `@tuwaio/siwx-react` (an optional peer dependency of the package); the root entry point does not.
|
|
4
|
+
*
|
|
5
|
+
* @module react
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Checks, before a transaction starts, that the user is signed in with SIWX and that the Quasar API responds. Use it
|
|
9
|
+
* as the `beforeTxProcess` callback of `createPulsarStore` from `@tuwaio/pulsar-core`: with the default
|
|
10
|
+
* `abortOnTxError: true`, an error aborts the transaction before the wallet is asked to sign it.
|
|
11
|
+
*
|
|
12
|
+
* The session check reads the client state of `useSiwxSessionStore` from `@tuwaio/siwx-react`. It is not proof of
|
|
13
|
+
* identity: the server that syncs the transaction must verify the session itself (for example with
|
|
14
|
+
* `getSiwxServerSession` from `@tuwaio/siwx-server`).
|
|
15
|
+
*
|
|
16
|
+
* Side effects: reads `useSiwxSessionStore` and sends `GET <apiUrl>/v1/engine/monitoring/health` without credentials
|
|
17
|
+
* and without the HTTP cache.
|
|
18
|
+
*
|
|
19
|
+
* @param customApiUrl - Base URL of the Quasar API. Defaults to {@link BASE_API_URL}.
|
|
20
|
+
* @returns Resolves when a session exists and the API answers with a 2xx status.
|
|
21
|
+
* @throws {Error} `[QuasarSDK] No SIWX Session found. User must be signed in.` when the store has no session.
|
|
22
|
+
* @throws {Error} `[QuasarSDK] Quasar Cloud Engine is currently unreachable.` when the request fails (network error,
|
|
23
|
+
* CORS); the original error is its `cause`.
|
|
24
|
+
* @throws {Error} `[QuasarSDK] API Health check failed with status: <status>` when the API answers with another status.
|
|
25
|
+
*/
|
|
26
|
+
declare function preFlightTxCheck(customApiUrl?: string): Promise<void>;
|
|
27
|
+
|
|
28
|
+
export { preFlightTxCheck };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {a}from'./chunk-YPUBFZPR.js';import {useSiwxSessionStore}from'@tuwaio/siwx-react';var i="/v1/engine/monitoring/health";async function u(s){if(!useSiwxSessionStore.getState().session)throw new Error("[QuasarSDK] No SIWX Session found. User must be signed in.");let o=(s||a).replace(/\/+$/,""),e;try{e=await fetch(`${o}${i}`,{method:"GET",cache:"no-store"});}catch(t){throw new Error("[QuasarSDK] Quasar Cloud Engine is currently unreachable.",{cause:t})}if(!e.ok)throw new Error(`[QuasarSDK] API Health check failed with status: ${e.status}`)}export{u as preFlightTxCheck};
|