@tuwaio/quasar-sdk 1.0.0-fix-pulsar-alpha.1.fc19e24

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 FOP Tkach Oleksandr
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # Quasar SDK
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/@tuwaio/quasar-sdk.svg)](https://www.npmjs.com/package/@tuwaio/quasar-sdk)
4
+ [![License](https://img.shields.io/npm/l/@tuwaio/quasar-sdk.svg)](./LICENSE)
5
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/TuwaIO/sdk/release.yml?branch=main)](https://github.com/TuwaIO/sdk/actions)
6
+
7
+ > The official server-side Node.js & Edge SDK for the **TUWA Quasar Cloud**.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pnpm add @tuwaio/quasar-sdk
13
+ ```
14
+
15
+ ### Peer Dependencies
16
+
17
+ | Package | Version |
18
+ | -------------------- | --------- |
19
+ | `@tuwaio/pulsar-core` | `>=0.5.1` |
20
+ | `ofetch` | `>=1.5.1` |
21
+
22
+ ## Quick Start
23
+
24
+ ```typescript
25
+ import { Quasar } from '@tuwaio/quasar-sdk';
26
+
27
+ const quasar = new Quasar({ secretKey: 'sk_live_your_secret_key' });
28
+
29
+ // Sync a pending transaction
30
+ const { txKey } = await quasar.pulsar.syncCreate(tx);
31
+
32
+ // Update status
33
+ await quasar.pulsar.syncUpdate(txKey, { status: 'confirmed' });
34
+
35
+ // Query history
36
+ const history = await quasar.pulsar.getHistory({ chainId: 1 });
37
+ ```
38
+
39
+ ## Modules
40
+
41
+ ### Pulsar — `quasar.pulsar`
42
+
43
+ | Method | Description |
44
+ | --- | --- |
45
+ | `syncCreate(tx)` | Sync a new pending transaction to the cloud |
46
+ | `syncUpdate(txKey, patches)` | Update an existing transaction's status or fields |
47
+ | `getHistory(query?)` | Retrieve paginated transaction history |
48
+
49
+ ## Error Handling
50
+
51
+ ```typescript
52
+ import { QuasarSDKError } from '@tuwaio/quasar-sdk';
53
+
54
+ try {
55
+ await quasar.pulsar.getHistory();
56
+ } catch (err) {
57
+ if (err instanceof QuasarSDKError) {
58
+ console.error(err.status); // HTTP status code
59
+ console.error(err.message); // Formatted error message
60
+ console.error(err.originalError); // Raw fetch error
61
+ }
62
+ }
63
+ ```
64
+
65
+ ## Configuration
66
+
67
+ | Property | Type | Required | Default | Description |
68
+ | ----------- | -------- | -------- | --------------------- | ----------- |
69
+ | `secretKey` | `string` | ✅ | — | Server-side API key (`sk_live_*`) |
70
+ | `baseUrl` | `string` | ❌ | `https://api.tuwa.io` | API base URL |
71
+ | `timeout` | `number` | ❌ | `10000` | Request timeout (ms) |
72
+
73
+ ## Documentation
74
+
75
+ Full API reference: [sdk.docs.tuwa.io](https://sdk.docs.tuwa.io/)
76
+
77
+ ---
78
+
79
+ ## 🤝 Contributing & Support
80
+
81
+ Contributions are welcome! Please read our main **[Contribution Guidelines](https://github.com/TuwaIO/workflows/blob/main/CONTRIBUTING.md)**.
82
+
83
+ If you find this library useful, please consider supporting its development. Every contribution helps!
84
+
85
+ [**➡️ View Support Options**](https://github.com/TuwaIO/workflows/blob/main/Donation.md)
86
+
87
+ ## 📄 License
88
+
89
+ This project is licensed under the **Apache-2.0 License** - see the [LICENSE](./LICENSE) file for details.
@@ -0,0 +1,380 @@
1
+ import { FetchOptions } from 'ofetch';
2
+ import { Transaction, UpdatableTransactionFields } from '@tuwaio/pulsar-core';
3
+ export { Transaction, UpdatableTransactionFields } from '@tuwaio/pulsar-core';
4
+
5
+ /**
6
+ * @module types
7
+ * @description Shared type definitions for the Quasar SDK.
8
+ * Contains configuration interfaces, query parameters, paginated result structure,
9
+ * and re-exports from `@tuwaio/pulsar-core`.
10
+ */
11
+
12
+ /**
13
+ * Configuration options for initializing the {@link Quasar} SDK client.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const config: QuasarConfig = {
18
+ * secretKey: 'sk_live_abc123...',
19
+ * baseUrl: 'https://api.tuwa.io',
20
+ * timeout: 15000,
21
+ * };
22
+ * ```
23
+ */
24
+ interface QuasarConfig {
25
+ /**
26
+ * Your secret API key starting with `sk_live_`.
27
+ *
28
+ * @remarks
29
+ * This key authenticates every request through the Iron Dome security perimeter.
30
+ * It **MUST** be kept secure on the server side — never expose it in client bundles.
31
+ */
32
+ secretKey: string;
33
+ /**
34
+ * The base URL of the Quasar Cloud API.
35
+ *
36
+ * @defaultValue `'https://api.tuwa.io'`
37
+ */
38
+ baseUrl?: string;
39
+ /**
40
+ * Request timeout in milliseconds.
41
+ *
42
+ * @defaultValue `10000`
43
+ */
44
+ timeout?: number;
45
+ }
46
+ /**
47
+ * Query parameters for filtering transaction history.
48
+ *
49
+ * All fields are optional — omitted fields apply no filter.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const query: HistoryQuery = {
54
+ * page: 2,
55
+ * limit: 25,
56
+ * chainId: 1,
57
+ * status: 'confirmed',
58
+ * };
59
+ * ```
60
+ */
61
+ interface HistoryQuery {
62
+ /**
63
+ * Page number for pagination (1-indexed).
64
+ *
65
+ * @defaultValue `1`
66
+ */
67
+ page?: number;
68
+ /**
69
+ * Maximum number of results per page.
70
+ *
71
+ * @defaultValue `10`
72
+ */
73
+ limit?: number;
74
+ /**
75
+ * Filter by blockchain chain ID (e.g. `1` for Ethereum Mainnet, `'solana'` for Solana).
76
+ */
77
+ chainId?: string | number;
78
+ /**
79
+ * Filter by transaction status (e.g. `'pending'`, `'confirmed'`, `'failed'`).
80
+ */
81
+ status?: string;
82
+ /**
83
+ * Filter by a specific transaction key (unique identifier assigned by Quasar).
84
+ */
85
+ txKey?: string;
86
+ }
87
+ /**
88
+ * Generic wrapper for paginated API responses.
89
+ *
90
+ * @typeParam T - The type of each document in the result set.
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const result: PaginatedResult<Transaction> = await quasar.pulsar.getHistory();
95
+ * console.log(result.docs); // Transaction[]
96
+ * console.log(result.totalPages); // number
97
+ * console.log(result.hasNextPage); // boolean
98
+ * ```
99
+ */
100
+ interface PaginatedResult<T> {
101
+ /** Array of documents for the current page. */
102
+ docs: T[];
103
+ /** Total number of documents matching the query across all pages. */
104
+ totalDocs: number;
105
+ /** Total number of available pages. */
106
+ totalPages: number;
107
+ /** Current page number (1-indexed). */
108
+ page: number;
109
+ /** Whether a subsequent page exists. */
110
+ hasNextPage: boolean;
111
+ /** Whether a previous page exists. */
112
+ hasPrevPage: boolean;
113
+ }
114
+
115
+ /**
116
+ * @module core/client
117
+ * @description Core HTTP client for the Quasar SDK.
118
+ * Handles authenticated requests through the Iron Dome security perimeter
119
+ * and provides structured error handling for all API interactions.
120
+ */
121
+
122
+ /**
123
+ * Custom error class for all Quasar SDK API failures.
124
+ *
125
+ * Wraps the underlying HTTP error with a structured format including
126
+ * status code, human-readable message, and the original error reference.
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * try {
131
+ * await quasar.pulsar.getHistory();
132
+ * } catch (err) {
133
+ * if (err instanceof QuasarSDKError) {
134
+ * console.error(err.status); // e.g. 401
135
+ * console.error(err.message); // "[Quasar SDK] Request Failed (401): Unauthorized"
136
+ * console.error(err.originalError); // Raw FetchError from ofetch
137
+ * }
138
+ * }
139
+ * ```
140
+ */
141
+ declare class QuasarSDKError extends Error {
142
+ /** HTTP status code returned by the API, if available. */
143
+ readonly status: number | undefined;
144
+ /** The original error thrown by the HTTP client. */
145
+ readonly originalError: Error;
146
+ /**
147
+ * Creates a new QuasarSDKError instance.
148
+ *
149
+ * @param message - Formatted error message with SDK prefix and status.
150
+ * @param status - HTTP status code, or `undefined` if unavailable.
151
+ * @param originalError - The raw error from the HTTP layer.
152
+ */
153
+ constructor(message: string, status: number | undefined, originalError: Error);
154
+ }
155
+ /**
156
+ * Internal HTTP client for the Quasar Cloud API.
157
+ *
158
+ * Manages authenticated requests by injecting the `x-tuwa-secret-key` header
159
+ * into every outgoing request. Uses `ofetch` as the transport layer.
160
+ *
161
+ * @remarks
162
+ * This class is not exported from the public API surface.
163
+ * Consumers interact with it indirectly through the {@link Quasar} entry point.
164
+ *
165
+ * @internal
166
+ */
167
+ declare class QuasarClient {
168
+ /** The secret API key used for authentication. */
169
+ private readonly secretKey;
170
+ /** The base URL for all API requests. */
171
+ private readonly baseUrl;
172
+ /** Request timeout in milliseconds. */
173
+ private readonly timeout;
174
+ /**
175
+ * Creates a new QuasarClient instance.
176
+ *
177
+ * @param config - SDK configuration containing the secret key and optional overrides.
178
+ * @throws {Error} If `config.secretKey` is missing or empty.
179
+ */
180
+ constructor(config: QuasarConfig);
181
+ /**
182
+ * Sends an authenticated request to the Quasar Cloud API.
183
+ *
184
+ * Automatically injects Iron Dome headers (`x-tuwa-secret-key`, `Content-Type`)
185
+ * and wraps all transport errors into {@link QuasarSDKError}.
186
+ *
187
+ * @typeParam T - Expected response body type.
188
+ * @param path - API endpoint path (e.g. `/api/v1/engine/tx-sync`).
189
+ * @param options - Fetch options (method, body, query, headers, etc.).
190
+ * `baseURL` and `timeout` are managed internally and cannot be overridden.
191
+ * @returns The parsed JSON response body typed as `T`.
192
+ * @throws {QuasarSDKError} On any HTTP or network error.
193
+ */
194
+ request<T>(path: string, options?: Omit<FetchOptions<'json'>, 'baseURL' | 'timeout'>): Promise<T>;
195
+ /**
196
+ * Transforms a raw fetch error into a structured {@link QuasarSDKError}.
197
+ *
198
+ * Extracts status code and error message from the response body or fallback fields.
199
+ * Logs a console warning for authentication failures (401/403).
200
+ *
201
+ * @param error - The raw error caught from `ofetch`.
202
+ * @returns A formatted QuasarSDKError instance.
203
+ */
204
+ private buildError;
205
+ }
206
+
207
+ /**
208
+ * @module modules/pulsar
209
+ * @description Pulsar Transaction Engine module.
210
+ * Provides methods for syncing transaction states to the Quasar Cloud
211
+ * and retrieving paginated transaction history.
212
+ */
213
+
214
+ /**
215
+ * Pulsar module — the transaction engine interface for Quasar Cloud.
216
+ *
217
+ * Handles all operations related to blockchain transaction lifecycle:
218
+ * creating, updating, and querying transactions through the API.
219
+ *
220
+ * @remarks
221
+ * Access this module via `quasar.pulsar` after initializing the SDK.
222
+ * All methods authenticate automatically using the configured secret key.
223
+ *
224
+ * @example
225
+ * ```typescript
226
+ * const quasar = new Quasar({ secretKey: 'sk_live_...' });
227
+ *
228
+ * // Create
229
+ * const { txKey } = await quasar.pulsar.syncCreate(transaction);
230
+ *
231
+ * // Update
232
+ * await quasar.pulsar.syncUpdate(txKey, { status: 'confirmed' });
233
+ *
234
+ * // Read
235
+ * const history = await quasar.pulsar.getHistory({ chainId: 1 });
236
+ * ```
237
+ */
238
+ declare class PulsarModule {
239
+ private readonly client;
240
+ /**
241
+ * Creates a new PulsarModule instance.
242
+ *
243
+ * @param client - The internal {@link QuasarClient} instance for making authenticated API calls.
244
+ * @internal
245
+ */
246
+ constructor(client: QuasarClient);
247
+ /**
248
+ * Syncs a newly created pending transaction to the Quasar Cloud.
249
+ *
250
+ * Sends the full transaction object to the `tx-sync` endpoint via POST.
251
+ * The server assigns a unique `txKey` that can be used for subsequent updates.
252
+ *
253
+ * @param tx - The complete transaction object to sync.
254
+ * @returns An object containing `success: true` and the assigned `txKey`.
255
+ * @throws {QuasarSDKError} On authentication failure, validation error, or network issue.
256
+ *
257
+ * @example
258
+ * ```typescript
259
+ * const { txKey } = await quasar.pulsar.syncCreate({
260
+ * hash: '0xabc...',
261
+ * chainId: 1,
262
+ * status: 'pending',
263
+ * from: '0x123...',
264
+ * to: '0x456...',
265
+ * });
266
+ * ```
267
+ */
268
+ syncCreate(tx: Transaction): Promise<{
269
+ success: true;
270
+ txKey: string;
271
+ }>;
272
+ /**
273
+ * Updates an existing transaction's status or mutable fields.
274
+ *
275
+ * Sends a PATCH request to the `tx-sync` endpoint with the transaction key
276
+ * and the fields to update.
277
+ *
278
+ * @param txKey - The unique transaction key assigned by Quasar during {@link syncCreate}.
279
+ * @param patches - An object containing the fields to update (e.g. `status`, `blockNumber`).
280
+ * @returns An object containing `success: true` on successful update.
281
+ * @throws {QuasarSDKError} On authentication failure, invalid txKey, or network issue.
282
+ *
283
+ * @example
284
+ * ```typescript
285
+ * await quasar.pulsar.syncUpdate('tx_abc123', {
286
+ * status: 'confirmed',
287
+ * });
288
+ * ```
289
+ */
290
+ syncUpdate(txKey: string, patches: UpdatableTransactionFields): Promise<{
291
+ success: true;
292
+ }>;
293
+ /**
294
+ * Retrieves paginated transaction history from the Quasar Cloud.
295
+ *
296
+ * Supports filtering by chain ID, status, and specific transaction key.
297
+ * Returns a typed {@link PaginatedResult} with navigation metadata.
298
+ *
299
+ * @param query - Optional query parameters for filtering and pagination.
300
+ * @returns A paginated result containing an array of {@link Transaction} documents.
301
+ * @throws {QuasarSDKError} On authentication failure or network issue.
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * const result = await quasar.pulsar.getHistory({
306
+ * page: 1,
307
+ * limit: 20,
308
+ * chainId: 1,
309
+ * status: 'confirmed',
310
+ * });
311
+ *
312
+ * for (const tx of result.docs) {
313
+ * console.log(tx.hash, tx.status);
314
+ * }
315
+ * ```
316
+ */
317
+ getHistory(query?: HistoryQuery): Promise<PaginatedResult<Transaction>>;
318
+ }
319
+
320
+ /**
321
+ * @module @tuwaio/quasar-sdk
322
+ * The official server-side Node.js & Edge SDK for the TUWA Quasar Cloud.
323
+ *
324
+ * Provides a type-safe client for interacting with the Quasar API,
325
+ * including transaction syncing, status tracking, and history retrieval
326
+ * through the Iron Dome security perimeter.
327
+ *
328
+ * @example
329
+ * ```typescript
330
+ * import { Quasar } from '@tuwaio/quasar-sdk';
331
+ *
332
+ * const quasar = new Quasar({ secretKey: 'sk_live_...' });
333
+ * const history = await quasar.pulsar.getHistory({ chainId: 1 });
334
+ * ```
335
+ *
336
+ * @packageDocumentation
337
+ */
338
+
339
+ /**
340
+ * Main entry point for the Quasar SDK.
341
+ *
342
+ * Initializes the internal HTTP client with your secret key
343
+ * and exposes domain-specific modules for interacting with the Quasar Cloud API.
344
+ *
345
+ * @example
346
+ * ```typescript
347
+ * import { Quasar } from '@tuwaio/quasar-sdk';
348
+ *
349
+ * const quasar = new Quasar({
350
+ * secretKey: 'sk_live_your_secret_key',
351
+ * baseUrl: 'https://api.tuwa.io',
352
+ * timeout: 15000,
353
+ * });
354
+ *
355
+ * // Access the Pulsar transaction engine
356
+ * const { txKey } = await quasar.pulsar.syncCreate(tx);
357
+ * ```
358
+ */
359
+ declare class Quasar {
360
+ /** @internal */
361
+ private readonly client;
362
+ /**
363
+ * The Pulsar Transaction Engine module.
364
+ *
365
+ * Use this to sync transaction states to the Quasar Cloud
366
+ * and retrieve paginated transaction history.
367
+ *
368
+ * @see {@link PulsarModule}
369
+ */
370
+ readonly pulsar: PulsarModule;
371
+ /**
372
+ * Creates a new Quasar SDK instance.
373
+ *
374
+ * @param config - SDK configuration. See {@link QuasarConfig} for available options.
375
+ * @throws {Error} If `config.secretKey` is missing.
376
+ */
377
+ constructor(config: QuasarConfig);
378
+ }
379
+
380
+ export { type HistoryQuery, type PaginatedResult, PulsarModule, Quasar, type QuasarConfig, QuasarSDKError };
@@ -0,0 +1,380 @@
1
+ import { FetchOptions } from 'ofetch';
2
+ import { Transaction, UpdatableTransactionFields } from '@tuwaio/pulsar-core';
3
+ export { Transaction, UpdatableTransactionFields } from '@tuwaio/pulsar-core';
4
+
5
+ /**
6
+ * @module types
7
+ * @description Shared type definitions for the Quasar SDK.
8
+ * Contains configuration interfaces, query parameters, paginated result structure,
9
+ * and re-exports from `@tuwaio/pulsar-core`.
10
+ */
11
+
12
+ /**
13
+ * Configuration options for initializing the {@link Quasar} SDK client.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const config: QuasarConfig = {
18
+ * secretKey: 'sk_live_abc123...',
19
+ * baseUrl: 'https://api.tuwa.io',
20
+ * timeout: 15000,
21
+ * };
22
+ * ```
23
+ */
24
+ interface QuasarConfig {
25
+ /**
26
+ * Your secret API key starting with `sk_live_`.
27
+ *
28
+ * @remarks
29
+ * This key authenticates every request through the Iron Dome security perimeter.
30
+ * It **MUST** be kept secure on the server side — never expose it in client bundles.
31
+ */
32
+ secretKey: string;
33
+ /**
34
+ * The base URL of the Quasar Cloud API.
35
+ *
36
+ * @defaultValue `'https://api.tuwa.io'`
37
+ */
38
+ baseUrl?: string;
39
+ /**
40
+ * Request timeout in milliseconds.
41
+ *
42
+ * @defaultValue `10000`
43
+ */
44
+ timeout?: number;
45
+ }
46
+ /**
47
+ * Query parameters for filtering transaction history.
48
+ *
49
+ * All fields are optional — omitted fields apply no filter.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const query: HistoryQuery = {
54
+ * page: 2,
55
+ * limit: 25,
56
+ * chainId: 1,
57
+ * status: 'confirmed',
58
+ * };
59
+ * ```
60
+ */
61
+ interface HistoryQuery {
62
+ /**
63
+ * Page number for pagination (1-indexed).
64
+ *
65
+ * @defaultValue `1`
66
+ */
67
+ page?: number;
68
+ /**
69
+ * Maximum number of results per page.
70
+ *
71
+ * @defaultValue `10`
72
+ */
73
+ limit?: number;
74
+ /**
75
+ * Filter by blockchain chain ID (e.g. `1` for Ethereum Mainnet, `'solana'` for Solana).
76
+ */
77
+ chainId?: string | number;
78
+ /**
79
+ * Filter by transaction status (e.g. `'pending'`, `'confirmed'`, `'failed'`).
80
+ */
81
+ status?: string;
82
+ /**
83
+ * Filter by a specific transaction key (unique identifier assigned by Quasar).
84
+ */
85
+ txKey?: string;
86
+ }
87
+ /**
88
+ * Generic wrapper for paginated API responses.
89
+ *
90
+ * @typeParam T - The type of each document in the result set.
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const result: PaginatedResult<Transaction> = await quasar.pulsar.getHistory();
95
+ * console.log(result.docs); // Transaction[]
96
+ * console.log(result.totalPages); // number
97
+ * console.log(result.hasNextPage); // boolean
98
+ * ```
99
+ */
100
+ interface PaginatedResult<T> {
101
+ /** Array of documents for the current page. */
102
+ docs: T[];
103
+ /** Total number of documents matching the query across all pages. */
104
+ totalDocs: number;
105
+ /** Total number of available pages. */
106
+ totalPages: number;
107
+ /** Current page number (1-indexed). */
108
+ page: number;
109
+ /** Whether a subsequent page exists. */
110
+ hasNextPage: boolean;
111
+ /** Whether a previous page exists. */
112
+ hasPrevPage: boolean;
113
+ }
114
+
115
+ /**
116
+ * @module core/client
117
+ * @description Core HTTP client for the Quasar SDK.
118
+ * Handles authenticated requests through the Iron Dome security perimeter
119
+ * and provides structured error handling for all API interactions.
120
+ */
121
+
122
+ /**
123
+ * Custom error class for all Quasar SDK API failures.
124
+ *
125
+ * Wraps the underlying HTTP error with a structured format including
126
+ * status code, human-readable message, and the original error reference.
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * try {
131
+ * await quasar.pulsar.getHistory();
132
+ * } catch (err) {
133
+ * if (err instanceof QuasarSDKError) {
134
+ * console.error(err.status); // e.g. 401
135
+ * console.error(err.message); // "[Quasar SDK] Request Failed (401): Unauthorized"
136
+ * console.error(err.originalError); // Raw FetchError from ofetch
137
+ * }
138
+ * }
139
+ * ```
140
+ */
141
+ declare class QuasarSDKError extends Error {
142
+ /** HTTP status code returned by the API, if available. */
143
+ readonly status: number | undefined;
144
+ /** The original error thrown by the HTTP client. */
145
+ readonly originalError: Error;
146
+ /**
147
+ * Creates a new QuasarSDKError instance.
148
+ *
149
+ * @param message - Formatted error message with SDK prefix and status.
150
+ * @param status - HTTP status code, or `undefined` if unavailable.
151
+ * @param originalError - The raw error from the HTTP layer.
152
+ */
153
+ constructor(message: string, status: number | undefined, originalError: Error);
154
+ }
155
+ /**
156
+ * Internal HTTP client for the Quasar Cloud API.
157
+ *
158
+ * Manages authenticated requests by injecting the `x-tuwa-secret-key` header
159
+ * into every outgoing request. Uses `ofetch` as the transport layer.
160
+ *
161
+ * @remarks
162
+ * This class is not exported from the public API surface.
163
+ * Consumers interact with it indirectly through the {@link Quasar} entry point.
164
+ *
165
+ * @internal
166
+ */
167
+ declare class QuasarClient {
168
+ /** The secret API key used for authentication. */
169
+ private readonly secretKey;
170
+ /** The base URL for all API requests. */
171
+ private readonly baseUrl;
172
+ /** Request timeout in milliseconds. */
173
+ private readonly timeout;
174
+ /**
175
+ * Creates a new QuasarClient instance.
176
+ *
177
+ * @param config - SDK configuration containing the secret key and optional overrides.
178
+ * @throws {Error} If `config.secretKey` is missing or empty.
179
+ */
180
+ constructor(config: QuasarConfig);
181
+ /**
182
+ * Sends an authenticated request to the Quasar Cloud API.
183
+ *
184
+ * Automatically injects Iron Dome headers (`x-tuwa-secret-key`, `Content-Type`)
185
+ * and wraps all transport errors into {@link QuasarSDKError}.
186
+ *
187
+ * @typeParam T - Expected response body type.
188
+ * @param path - API endpoint path (e.g. `/api/v1/engine/tx-sync`).
189
+ * @param options - Fetch options (method, body, query, headers, etc.).
190
+ * `baseURL` and `timeout` are managed internally and cannot be overridden.
191
+ * @returns The parsed JSON response body typed as `T`.
192
+ * @throws {QuasarSDKError} On any HTTP or network error.
193
+ */
194
+ request<T>(path: string, options?: Omit<FetchOptions<'json'>, 'baseURL' | 'timeout'>): Promise<T>;
195
+ /**
196
+ * Transforms a raw fetch error into a structured {@link QuasarSDKError}.
197
+ *
198
+ * Extracts status code and error message from the response body or fallback fields.
199
+ * Logs a console warning for authentication failures (401/403).
200
+ *
201
+ * @param error - The raw error caught from `ofetch`.
202
+ * @returns A formatted QuasarSDKError instance.
203
+ */
204
+ private buildError;
205
+ }
206
+
207
+ /**
208
+ * @module modules/pulsar
209
+ * @description Pulsar Transaction Engine module.
210
+ * Provides methods for syncing transaction states to the Quasar Cloud
211
+ * and retrieving paginated transaction history.
212
+ */
213
+
214
+ /**
215
+ * Pulsar module — the transaction engine interface for Quasar Cloud.
216
+ *
217
+ * Handles all operations related to blockchain transaction lifecycle:
218
+ * creating, updating, and querying transactions through the API.
219
+ *
220
+ * @remarks
221
+ * Access this module via `quasar.pulsar` after initializing the SDK.
222
+ * All methods authenticate automatically using the configured secret key.
223
+ *
224
+ * @example
225
+ * ```typescript
226
+ * const quasar = new Quasar({ secretKey: 'sk_live_...' });
227
+ *
228
+ * // Create
229
+ * const { txKey } = await quasar.pulsar.syncCreate(transaction);
230
+ *
231
+ * // Update
232
+ * await quasar.pulsar.syncUpdate(txKey, { status: 'confirmed' });
233
+ *
234
+ * // Read
235
+ * const history = await quasar.pulsar.getHistory({ chainId: 1 });
236
+ * ```
237
+ */
238
+ declare class PulsarModule {
239
+ private readonly client;
240
+ /**
241
+ * Creates a new PulsarModule instance.
242
+ *
243
+ * @param client - The internal {@link QuasarClient} instance for making authenticated API calls.
244
+ * @internal
245
+ */
246
+ constructor(client: QuasarClient);
247
+ /**
248
+ * Syncs a newly created pending transaction to the Quasar Cloud.
249
+ *
250
+ * Sends the full transaction object to the `tx-sync` endpoint via POST.
251
+ * The server assigns a unique `txKey` that can be used for subsequent updates.
252
+ *
253
+ * @param tx - The complete transaction object to sync.
254
+ * @returns An object containing `success: true` and the assigned `txKey`.
255
+ * @throws {QuasarSDKError} On authentication failure, validation error, or network issue.
256
+ *
257
+ * @example
258
+ * ```typescript
259
+ * const { txKey } = await quasar.pulsar.syncCreate({
260
+ * hash: '0xabc...',
261
+ * chainId: 1,
262
+ * status: 'pending',
263
+ * from: '0x123...',
264
+ * to: '0x456...',
265
+ * });
266
+ * ```
267
+ */
268
+ syncCreate(tx: Transaction): Promise<{
269
+ success: true;
270
+ txKey: string;
271
+ }>;
272
+ /**
273
+ * Updates an existing transaction's status or mutable fields.
274
+ *
275
+ * Sends a PATCH request to the `tx-sync` endpoint with the transaction key
276
+ * and the fields to update.
277
+ *
278
+ * @param txKey - The unique transaction key assigned by Quasar during {@link syncCreate}.
279
+ * @param patches - An object containing the fields to update (e.g. `status`, `blockNumber`).
280
+ * @returns An object containing `success: true` on successful update.
281
+ * @throws {QuasarSDKError} On authentication failure, invalid txKey, or network issue.
282
+ *
283
+ * @example
284
+ * ```typescript
285
+ * await quasar.pulsar.syncUpdate('tx_abc123', {
286
+ * status: 'confirmed',
287
+ * });
288
+ * ```
289
+ */
290
+ syncUpdate(txKey: string, patches: UpdatableTransactionFields): Promise<{
291
+ success: true;
292
+ }>;
293
+ /**
294
+ * Retrieves paginated transaction history from the Quasar Cloud.
295
+ *
296
+ * Supports filtering by chain ID, status, and specific transaction key.
297
+ * Returns a typed {@link PaginatedResult} with navigation metadata.
298
+ *
299
+ * @param query - Optional query parameters for filtering and pagination.
300
+ * @returns A paginated result containing an array of {@link Transaction} documents.
301
+ * @throws {QuasarSDKError} On authentication failure or network issue.
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * const result = await quasar.pulsar.getHistory({
306
+ * page: 1,
307
+ * limit: 20,
308
+ * chainId: 1,
309
+ * status: 'confirmed',
310
+ * });
311
+ *
312
+ * for (const tx of result.docs) {
313
+ * console.log(tx.hash, tx.status);
314
+ * }
315
+ * ```
316
+ */
317
+ getHistory(query?: HistoryQuery): Promise<PaginatedResult<Transaction>>;
318
+ }
319
+
320
+ /**
321
+ * @module @tuwaio/quasar-sdk
322
+ * The official server-side Node.js & Edge SDK for the TUWA Quasar Cloud.
323
+ *
324
+ * Provides a type-safe client for interacting with the Quasar API,
325
+ * including transaction syncing, status tracking, and history retrieval
326
+ * through the Iron Dome security perimeter.
327
+ *
328
+ * @example
329
+ * ```typescript
330
+ * import { Quasar } from '@tuwaio/quasar-sdk';
331
+ *
332
+ * const quasar = new Quasar({ secretKey: 'sk_live_...' });
333
+ * const history = await quasar.pulsar.getHistory({ chainId: 1 });
334
+ * ```
335
+ *
336
+ * @packageDocumentation
337
+ */
338
+
339
+ /**
340
+ * Main entry point for the Quasar SDK.
341
+ *
342
+ * Initializes the internal HTTP client with your secret key
343
+ * and exposes domain-specific modules for interacting with the Quasar Cloud API.
344
+ *
345
+ * @example
346
+ * ```typescript
347
+ * import { Quasar } from '@tuwaio/quasar-sdk';
348
+ *
349
+ * const quasar = new Quasar({
350
+ * secretKey: 'sk_live_your_secret_key',
351
+ * baseUrl: 'https://api.tuwa.io',
352
+ * timeout: 15000,
353
+ * });
354
+ *
355
+ * // Access the Pulsar transaction engine
356
+ * const { txKey } = await quasar.pulsar.syncCreate(tx);
357
+ * ```
358
+ */
359
+ declare class Quasar {
360
+ /** @internal */
361
+ private readonly client;
362
+ /**
363
+ * The Pulsar Transaction Engine module.
364
+ *
365
+ * Use this to sync transaction states to the Quasar Cloud
366
+ * and retrieve paginated transaction history.
367
+ *
368
+ * @see {@link PulsarModule}
369
+ */
370
+ readonly pulsar: PulsarModule;
371
+ /**
372
+ * Creates a new Quasar SDK instance.
373
+ *
374
+ * @param config - SDK configuration. See {@link QuasarConfig} for available options.
375
+ * @throws {Error} If `config.secretKey` is missing.
376
+ */
377
+ constructor(config: QuasarConfig);
378
+ }
379
+
380
+ export { type HistoryQuery, type PaginatedResult, PulsarModule, Quasar, type QuasarConfig, QuasarSDKError };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';var ofetch=require('ofetch');var a=class extends Error{status;originalError;constructor(r,t,e){super(r),this.name="QuasarSDKError",this.status=t,this.originalError=e;}},i=class{secretKey;baseUrl;timeout;constructor(r){if(!r.secretKey)throw new Error("[Quasar SDK] Missing API Key. Provide a secretKey starting with sk_live_.");this.secretKey=r.secretKey,this.baseUrl=r.baseUrl||"https://api.tuwa.io",this.timeout=r.timeout||1e4;}async request(r,t={}){try{return await ofetch.ofetch(r,{baseURL:this.baseUrl,timeout:this.timeout,...t,headers:{"Content-Type":"application/json","x-tuwa-secret-key":this.secretKey,...t.headers}})}catch(e){throw this.buildError(e)}}buildError(r){let t=r,e=t.statusCode??t.response?.status,u=(t.data??t.response?._data)?.error??t.message??"Unknown Error";return (e===401||e===403)&&console.error("\u{1F6A8} [Quasar SDK] Auth Error. Check your Secret Key and scopes."),new a(`[Quasar SDK] Request Failed (${e}): ${u}`,e,t)}};var s=class{constructor(r){this.client=r;}async syncCreate(r){return this.client.request("/api/v1/engine/tx-sync",{method:"POST",body:r})}async syncUpdate(r,t){return this.client.request("/api/v1/engine/tx-sync",{method:"PATCH",body:{txKey:r,...t}})}async getHistory(r={}){return this.client.request("/api/v1/engine/txs-history",{method:"GET",query:{page:r.page??1,limit:r.limit??10,chainId:r.chainId,status:r.status,txKey:r.txKey}})}};var n=class{client;pulsar;constructor(r){this.client=new i(r),this.pulsar=new s(this.client);}};
2
+ exports.PulsarModule=s;exports.Quasar=n;exports.QuasarSDKError=a;
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import {ofetch}from'ofetch';var a=class extends Error{status;originalError;constructor(r,t,e){super(r),this.name="QuasarSDKError",this.status=t,this.originalError=e;}},i=class{secretKey;baseUrl;timeout;constructor(r){if(!r.secretKey)throw new Error("[Quasar SDK] Missing API Key. Provide a secretKey starting with sk_live_.");this.secretKey=r.secretKey,this.baseUrl=r.baseUrl||"https://api.tuwa.io",this.timeout=r.timeout||1e4;}async request(r,t={}){try{return await ofetch(r,{baseURL:this.baseUrl,timeout:this.timeout,...t,headers:{"Content-Type":"application/json","x-tuwa-secret-key":this.secretKey,...t.headers}})}catch(e){throw this.buildError(e)}}buildError(r){let t=r,e=t.statusCode??t.response?.status,u=(t.data??t.response?._data)?.error??t.message??"Unknown Error";return (e===401||e===403)&&console.error("\u{1F6A8} [Quasar SDK] Auth Error. Check your Secret Key and scopes."),new a(`[Quasar SDK] Request Failed (${e}): ${u}`,e,t)}};var s=class{constructor(r){this.client=r;}async syncCreate(r){return this.client.request("/api/v1/engine/tx-sync",{method:"POST",body:r})}async syncUpdate(r,t){return this.client.request("/api/v1/engine/tx-sync",{method:"PATCH",body:{txKey:r,...t}})}async getHistory(r={}){return this.client.request("/api/v1/engine/txs-history",{method:"GET",query:{page:r.page??1,limit:r.limit??10,chainId:r.chainId,status:r.status,txKey:r.txKey}})}};var n=class{client;pulsar;constructor(r){this.client=new i(r),this.pulsar=new s(this.client);}};
2
+ export{s as PulsarModule,n as Quasar,a as QuasarSDKError};
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@tuwaio/quasar-sdk",
3
+ "version": "1.0.0-fix-pulsar-alpha.1.fc19e24",
4
+ "private": false,
5
+ "author": "Oleksandr Tkach",
6
+ "license": "Apache-2.0",
7
+ "description": "The official server-side Node.js & Edge SDK for the TUWA Quasar Cloud.",
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts",
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "keywords": [
18
+ "web3",
19
+ "transaction",
20
+ "tracking",
21
+ "sdk"
22
+ ],
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/TuwaIO/sdk.git",
26
+ "directory": "packages/quasar-sdk"
27
+ },
28
+ "homepage": "https://github.com/TuwaIO/sdk",
29
+ "bugs": {
30
+ "url": "https://github.com/TuwaIO/sdk/issues"
31
+ },
32
+ "contributors": [
33
+ {
34
+ "name": "Oleksandr Tkach",
35
+ "url": "https://github.com/Argeare5"
36
+ }
37
+ ],
38
+ "peerDependencies": {
39
+ "@tuwaio/pulsar-core": ">=0.5.1",
40
+ "ofetch": ">=1.5.1"
41
+ },
42
+ "devDependencies": {
43
+ "@tuwaio/pulsar-core": "1.0.0-fix-remote-alpha.2.3ed5f1e",
44
+ "ofetch": "^1.5.1",
45
+ "tsup": "^8.5.1",
46
+ "typescript": "^5.9.3"
47
+ },
48
+ "scripts": {
49
+ "start": "tsup src/index.ts --watch",
50
+ "build": "tsup"
51
+ }
52
+ }