mmn-client-js 1.0.14 → 1.0.16

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/index.js CHANGED
@@ -8095,6 +8095,9 @@ class MmnClient {
8095
8095
  const address = this.getAddressFromUserId(userId);
8096
8096
  return this.makeRequest('account.getcurrentnonce', { address, tag });
8097
8097
  }
8098
+ async getCurrentNonceByAddress(address, tag = 'latest') {
8099
+ return this.makeRequest('account.getcurrentnonce', { address, tag });
8100
+ }
8098
8101
  async getAccountByUserId(userId) {
8099
8102
  const address = this.getAddressFromUserId(userId);
8100
8103
  return this.makeRequest('account.getaccount', {
@@ -8206,6 +8209,81 @@ class ZkClient {
8206
8209
  }
8207
8210
  }
8208
8211
 
8212
+ class DongClient {
8213
+ constructor(config) {
8214
+ this.endpoint = config.endpoint;
8215
+ this.timeout = config.timeout || 30000;
8216
+ this.headers = {
8217
+ Accept: 'application/json',
8218
+ 'Content-Type': 'application/json',
8219
+ ...(config.headers || {}),
8220
+ };
8221
+ }
8222
+ async makeRequest(method, path, params, body) {
8223
+ let url = `${this.endpoint}/${path}`;
8224
+ if (params && Object.keys(params).length > 0) {
8225
+ const searchParams = new URLSearchParams();
8226
+ Object.entries(params).forEach(([key, value]) => {
8227
+ searchParams.append(key, String(value));
8228
+ });
8229
+ url += `?${searchParams.toString()}`;
8230
+ }
8231
+ const controller = new AbortController();
8232
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
8233
+ try {
8234
+ const requestOptions = {
8235
+ method,
8236
+ mode: 'cors',
8237
+ credentials: 'omit',
8238
+ signal: controller.signal,
8239
+ headers: {
8240
+ Accept: 'application/json',
8241
+ ...this.headers,
8242
+ },
8243
+ };
8244
+ if (method === 'POST' && body) {
8245
+ requestOptions.body = JSON.stringify(body);
8246
+ requestOptions.headers['Content-Type'] =
8247
+ 'application/json';
8248
+ }
8249
+ const response = await fetch(url, requestOptions);
8250
+ clearTimeout(timeoutId);
8251
+ if (!response.ok) {
8252
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
8253
+ }
8254
+ const json = await response.json();
8255
+ return json.data;
8256
+ }
8257
+ catch (error) {
8258
+ clearTimeout(timeoutId);
8259
+ if (error instanceof Error) {
8260
+ if (error.name === 'AbortError') {
8261
+ throw new Error(`Request timeout after ${this.timeout}ms`);
8262
+ }
8263
+ throw error;
8264
+ }
8265
+ throw new Error('Request failed');
8266
+ }
8267
+ }
8268
+ // --- Red Envelope QR APIs ---
8269
+ async claimAmountRedEnvelopeQR(params) {
8270
+ const path = `api/v1/red-envelopes/qr/claim-amount`;
8271
+ const body = {
8272
+ user_id: params.user_id,
8273
+ proof_b64: params.proof_b64,
8274
+ public_b64: params.public_b64,
8275
+ publickey: params.publickey,
8276
+ };
8277
+ const queryParams = { id: params.id };
8278
+ return this.makeRequest('POST', path, queryParams, body);
8279
+ }
8280
+ async claimRedEnvelopeQR(id, params) {
8281
+ const path = `api/v1/red-envelopes/qr/${id}/claim`;
8282
+ await this.makeRequest('POST', path, undefined, params);
8283
+ }
8284
+ }
8285
+
8286
+ exports.DongClient = DongClient;
8209
8287
  exports.IndexerClient = IndexerClient;
8210
8288
  exports.MmnClient = MmnClient;
8211
8289
  exports.ZkClient = ZkClient;