@aura-payments/sdk 2.1.0 → 2.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/dist/index.d.mts +471 -2
- package/dist/index.d.ts +471 -2
- package/dist/index.js +181 -21
- package/dist/index.mjs +177 -20
- package/package.json +14 -2
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var crypto
|
|
3
|
+
var crypto = require('crypto');
|
|
4
4
|
|
|
5
5
|
// src/errors.ts
|
|
6
6
|
var AuraError = class _AuraError extends Error {
|
|
@@ -238,12 +238,17 @@ async function retryWithBackoff(fn, maxRetries = 3, shouldRetry = isRetryableErr
|
|
|
238
238
|
throw lastError;
|
|
239
239
|
}
|
|
240
240
|
async function withTimeout(promise, timeoutMs, timeoutMessage) {
|
|
241
|
+
let timer;
|
|
241
242
|
const timeoutPromise = new Promise((_, reject) => {
|
|
242
|
-
setTimeout(() => {
|
|
243
|
+
timer = setTimeout(() => {
|
|
243
244
|
reject(new AuraTimeoutError(timeoutMessage || `Request timeout after ${timeoutMs}ms`));
|
|
244
245
|
}, timeoutMs);
|
|
245
246
|
});
|
|
246
|
-
|
|
247
|
+
try {
|
|
248
|
+
return await Promise.race([promise, timeoutPromise]);
|
|
249
|
+
} finally {
|
|
250
|
+
if (timer) clearTimeout(timer);
|
|
251
|
+
}
|
|
247
252
|
}
|
|
248
253
|
|
|
249
254
|
// src/resources/escrows.ts
|
|
@@ -474,6 +479,74 @@ var Escrows = class {
|
|
|
474
479
|
);
|
|
475
480
|
}
|
|
476
481
|
};
|
|
482
|
+
|
|
483
|
+
// src/resources/insights.ts
|
|
484
|
+
var Insights = class {
|
|
485
|
+
constructor(client) {
|
|
486
|
+
this.client = client;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Revenue, transactions, active escrows and commissions for a period, each
|
|
490
|
+
* with its change against the prior period.
|
|
491
|
+
*
|
|
492
|
+
* The route defaults to `7d`. `start` and `end` are ISO 8601 datetimes and are
|
|
493
|
+
* both required when `period` is `'custom'`.
|
|
494
|
+
*/
|
|
495
|
+
async overview(period, start, end) {
|
|
496
|
+
const query = new URLSearchParams();
|
|
497
|
+
if (period !== void 0) query.set("period", period);
|
|
498
|
+
if (start !== void 0) query.set("start", start);
|
|
499
|
+
if (end !== void 0) query.set("end", end);
|
|
500
|
+
const qs = query.toString();
|
|
501
|
+
return this.client["request"](
|
|
502
|
+
"GET",
|
|
503
|
+
qs ? `/v1/insights/overview?${qs}` : "/v1/insights/overview"
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Forecast a metric over a horizon. Gated to Growth+ plans; lower tiers
|
|
508
|
+
* surface a 403 `AuraAPIError`.
|
|
509
|
+
*/
|
|
510
|
+
async forecast(params) {
|
|
511
|
+
const query = new URLSearchParams();
|
|
512
|
+
query.set("metric", params.metric);
|
|
513
|
+
if (params.algorithm !== void 0) query.set("algorithm", params.algorithm);
|
|
514
|
+
if (params.period !== void 0) query.set("period", params.period);
|
|
515
|
+
if (params.horizon !== void 0) query.set("horizon", params.horizon.toString());
|
|
516
|
+
if (params.includeHistory !== void 0) {
|
|
517
|
+
query.set("includeHistory", String(params.includeHistory));
|
|
518
|
+
}
|
|
519
|
+
if (params.historyPeriods !== void 0) {
|
|
520
|
+
query.set("historyPeriods", params.historyPeriods.toString());
|
|
521
|
+
}
|
|
522
|
+
return this.client["request"](
|
|
523
|
+
"GET",
|
|
524
|
+
`/v1/insights/forecast?${query.toString()}`
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Query the account audit log by action, actor, resource and date range.
|
|
529
|
+
*
|
|
530
|
+
* The route defaults to `range: '30d'`, `page: 1`, `limit: 50`.
|
|
531
|
+
*/
|
|
532
|
+
async audit(params) {
|
|
533
|
+
const query = new URLSearchParams();
|
|
534
|
+
if (params?.action !== void 0) query.set("action", params.action);
|
|
535
|
+
if (params?.actor !== void 0) query.set("actor", params.actor);
|
|
536
|
+
if (params?.resourceType !== void 0) query.set("resourceType", params.resourceType);
|
|
537
|
+
if (params?.resourceId !== void 0) query.set("resourceId", params.resourceId);
|
|
538
|
+
if (params?.range !== void 0) query.set("range", params.range);
|
|
539
|
+
if (params?.start !== void 0) query.set("start", params.start);
|
|
540
|
+
if (params?.end !== void 0) query.set("end", params.end);
|
|
541
|
+
if (params?.page !== void 0) query.set("page", params.page.toString());
|
|
542
|
+
if (params?.limit !== void 0) query.set("limit", params.limit.toString());
|
|
543
|
+
const qs = query.toString();
|
|
544
|
+
return this.client["request"](
|
|
545
|
+
"GET",
|
|
546
|
+
qs ? `/v1/insights/audit?${qs}` : "/v1/insights/audit"
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
};
|
|
477
550
|
var Mandates = class {
|
|
478
551
|
constructor(client) {
|
|
479
552
|
this.client = client;
|
|
@@ -543,7 +616,7 @@ var Mandates = class {
|
|
|
543
616
|
var MandateSignature = {
|
|
544
617
|
compute(input) {
|
|
545
618
|
const payload = `${input.mandateId}:${input.decision}:${input.decidedAt}`;
|
|
546
|
-
return crypto
|
|
619
|
+
return crypto.createHmac("sha256", input.secret).update(payload).digest("hex");
|
|
547
620
|
},
|
|
548
621
|
verify(input) {
|
|
549
622
|
const expected = MandateSignature.compute({
|
|
@@ -599,6 +672,24 @@ var Policies = class {
|
|
|
599
672
|
}
|
|
600
673
|
};
|
|
601
674
|
|
|
675
|
+
// src/resources/treasury.ts
|
|
676
|
+
var Treasury = class {
|
|
677
|
+
constructor(client) {
|
|
678
|
+
this.client = client;
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Analyze treasury balances, escrow exposure and pending payouts, and return
|
|
682
|
+
* an AI recommendation. Moves no funds.
|
|
683
|
+
*
|
|
684
|
+
* A POST with no body — the platform derives everything from the authenticated
|
|
685
|
+
* account. Gated to Growth+ plans; lower tiers surface a 403 `AuraAPIError`
|
|
686
|
+
* with code `feature_not_available`.
|
|
687
|
+
*/
|
|
688
|
+
async optimize() {
|
|
689
|
+
return this.client["request"]("POST", "/v1/treasury/optimize");
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
|
|
602
693
|
// src/resources/wallets.ts
|
|
603
694
|
var Wallets = class {
|
|
604
695
|
constructor(client) {
|
|
@@ -782,23 +873,89 @@ var Webhooks = class {
|
|
|
782
873
|
* Compute HMAC-SHA256 signature
|
|
783
874
|
*/
|
|
784
875
|
static computeHmacSignature(payload, secret) {
|
|
785
|
-
|
|
786
|
-
throw new Error("Web Crypto implementation needed for browser");
|
|
787
|
-
}
|
|
788
|
-
return crypto$1.createHmac("sha256", secret).update(payload).digest("hex");
|
|
876
|
+
return crypto.createHmac("sha256", secret).update(payload).digest("hex");
|
|
789
877
|
}
|
|
790
878
|
/**
|
|
791
|
-
* Constant-time
|
|
879
|
+
* Constant-time comparison of two hex signatures.
|
|
880
|
+
*
|
|
881
|
+
* Length is compared first because `timingSafeEqual` throws on mismatched
|
|
882
|
+
* buffers; that only reveals the length of an attacker-supplied signature,
|
|
883
|
+
* never the contents of the expected one.
|
|
792
884
|
*/
|
|
793
885
|
static secureCompare(a, b) {
|
|
794
|
-
|
|
886
|
+
const left = Buffer.from(a, "utf8");
|
|
887
|
+
const right = Buffer.from(b, "utf8");
|
|
888
|
+
if (left.length !== right.length) {
|
|
795
889
|
return false;
|
|
796
890
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
891
|
+
return crypto.timingSafeEqual(left, right);
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
// src/resources/withdrawals.ts
|
|
896
|
+
var Withdrawals = class {
|
|
897
|
+
constructor(client) {
|
|
898
|
+
this.client = client;
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* Get a single withdrawal, including status, fees, destination and tx hash.
|
|
902
|
+
*/
|
|
903
|
+
async get(withdrawalId) {
|
|
904
|
+
return this.client["request"](
|
|
905
|
+
"GET",
|
|
906
|
+
`/v1/withdrawals/${encodeURIComponent(withdrawalId)}`
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* List withdrawals for the account, most recent first.
|
|
911
|
+
*
|
|
912
|
+
* Returns the whole `{withdrawals, pagination}` envelope — this route does not
|
|
913
|
+
* use the `{success,data}` wrapper, so pagination metadata is preserved.
|
|
914
|
+
*/
|
|
915
|
+
async list(params) {
|
|
916
|
+
const query = new URLSearchParams();
|
|
917
|
+
if (params?.limit !== void 0) query.set("limit", params.limit.toString());
|
|
918
|
+
if (params?.offset !== void 0) query.set("offset", params.offset.toString());
|
|
919
|
+
if (params?.status !== void 0) query.set("status", params.status);
|
|
920
|
+
if (params?.chain !== void 0) query.set("chain", params.chain);
|
|
921
|
+
if (params?.fromDate !== void 0) query.set("fromDate", params.fromDate);
|
|
922
|
+
if (params?.toDate !== void 0) query.set("toDate", params.toDate);
|
|
923
|
+
const qs = query.toString();
|
|
924
|
+
return this.client["request"](
|
|
925
|
+
"GET",
|
|
926
|
+
qs ? `/v1/withdrawals?${qs}` : "/v1/withdrawals"
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* Preview fees and net amount for a withdrawal WITHOUT creating it.
|
|
931
|
+
*
|
|
932
|
+
* `params.exchange` is required by the route when `destinationType` is
|
|
933
|
+
* `'exchange'`; cross-chain estimates (source ≠ destination) add a CCTP
|
|
934
|
+
* bridge fee and only the supported routes are accepted.
|
|
935
|
+
*/
|
|
936
|
+
async estimate(params) {
|
|
937
|
+
return this.client["request"](
|
|
938
|
+
"POST",
|
|
939
|
+
"/v1/withdrawals/estimate",
|
|
940
|
+
params
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Get the account's KYC-tier withdrawal limits and remaining allowance.
|
|
945
|
+
*/
|
|
946
|
+
async limits() {
|
|
947
|
+
return this.client["request"]("GET", "/v1/withdrawals/limits");
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Validate a destination address for a chain. Moves no funds; when `amount` is
|
|
951
|
+
* supplied the response also carries a fee preview.
|
|
952
|
+
*/
|
|
953
|
+
async validate(params) {
|
|
954
|
+
return this.client["request"](
|
|
955
|
+
"POST",
|
|
956
|
+
"/v1/withdrawals/validate",
|
|
957
|
+
params
|
|
958
|
+
);
|
|
802
959
|
}
|
|
803
960
|
};
|
|
804
961
|
|
|
@@ -819,6 +976,9 @@ var AuraClient = class _AuraClient {
|
|
|
819
976
|
this.agents = new Agents(this);
|
|
820
977
|
this.policies = new Policies(this);
|
|
821
978
|
this.mandates = new Mandates(this);
|
|
979
|
+
this.withdrawals = new Withdrawals(this);
|
|
980
|
+
this.treasury = new Treasury(this);
|
|
981
|
+
this.insights = new Insights(this);
|
|
822
982
|
}
|
|
823
983
|
/**
|
|
824
984
|
* Normalize the base URL so resource paths like `/v1/escrow` reach the
|
|
@@ -862,7 +1022,8 @@ var AuraClient = class _AuraClient {
|
|
|
862
1022
|
* Make an authenticated request to the API with automatic retry logic
|
|
863
1023
|
*/
|
|
864
1024
|
async request(method, path, body, options) {
|
|
865
|
-
const
|
|
1025
|
+
const idempotencyKey = options?.idempotencyKey ?? (this.autoIdempotency && (method === "POST" || method === "PUT") ? generateIdempotencyKey() : void 0);
|
|
1026
|
+
const requestFn = () => this.executeRequest(method, path, body, { ...options, idempotencyKey });
|
|
866
1027
|
if (options?.skipRetry || method === "GET") {
|
|
867
1028
|
return requestFn();
|
|
868
1029
|
}
|
|
@@ -876,12 +1037,10 @@ var AuraClient = class _AuraClient {
|
|
|
876
1037
|
const headers = {
|
|
877
1038
|
"Content-Type": "application/json",
|
|
878
1039
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
879
|
-
"User-Agent": "@aura-payments/sdk/2.1.
|
|
1040
|
+
"User-Agent": "@aura-payments/sdk/2.1.1"
|
|
880
1041
|
};
|
|
881
1042
|
if (options?.idempotencyKey) {
|
|
882
1043
|
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
883
|
-
} else if (this.autoIdempotency && (method === "POST" || method === "PUT")) {
|
|
884
|
-
headers["Idempotency-Key"] = generateIdempotencyKey();
|
|
885
1044
|
}
|
|
886
1045
|
try {
|
|
887
1046
|
const response = await withTimeout(
|
|
@@ -994,11 +1153,14 @@ exports.AuraRateLimitError = AuraRateLimitError;
|
|
|
994
1153
|
exports.AuraTimeoutError = AuraTimeoutError;
|
|
995
1154
|
exports.AuraValidationError = AuraValidationError;
|
|
996
1155
|
exports.Escrows = Escrows;
|
|
1156
|
+
exports.Insights = Insights;
|
|
997
1157
|
exports.MandateSignature = MandateSignature;
|
|
998
1158
|
exports.Mandates = Mandates;
|
|
999
1159
|
exports.Policies = Policies;
|
|
1160
|
+
exports.Treasury = Treasury;
|
|
1000
1161
|
exports.Wallets = Wallets;
|
|
1001
1162
|
exports.Webhooks = Webhooks;
|
|
1163
|
+
exports.Withdrawals = Withdrawals;
|
|
1002
1164
|
exports.calculateBackoff = calculateBackoff;
|
|
1003
1165
|
exports.generateIdempotencyKey = generateIdempotencyKey;
|
|
1004
1166
|
exports.isAuraAPIError = isAuraAPIError;
|
|
@@ -1009,5 +1171,3 @@ exports.isAuraTimeoutError = isAuraTimeoutError;
|
|
|
1009
1171
|
exports.isRetryableError = isRetryableError;
|
|
1010
1172
|
exports.retryWithBackoff = retryWithBackoff;
|
|
1011
1173
|
exports.withTimeout = withTimeout;
|
|
1012
|
-
//# sourceMappingURL=index.js.map
|
|
1013
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHmac } from 'crypto';
|
|
1
|
+
import { createHmac, timingSafeEqual } from 'crypto';
|
|
2
2
|
|
|
3
3
|
// src/errors.ts
|
|
4
4
|
var AuraError = class _AuraError extends Error {
|
|
@@ -236,12 +236,17 @@ async function retryWithBackoff(fn, maxRetries = 3, shouldRetry = isRetryableErr
|
|
|
236
236
|
throw lastError;
|
|
237
237
|
}
|
|
238
238
|
async function withTimeout(promise, timeoutMs, timeoutMessage) {
|
|
239
|
+
let timer;
|
|
239
240
|
const timeoutPromise = new Promise((_, reject) => {
|
|
240
|
-
setTimeout(() => {
|
|
241
|
+
timer = setTimeout(() => {
|
|
241
242
|
reject(new AuraTimeoutError(timeoutMessage || `Request timeout after ${timeoutMs}ms`));
|
|
242
243
|
}, timeoutMs);
|
|
243
244
|
});
|
|
244
|
-
|
|
245
|
+
try {
|
|
246
|
+
return await Promise.race([promise, timeoutPromise]);
|
|
247
|
+
} finally {
|
|
248
|
+
if (timer) clearTimeout(timer);
|
|
249
|
+
}
|
|
245
250
|
}
|
|
246
251
|
|
|
247
252
|
// src/resources/escrows.ts
|
|
@@ -472,6 +477,74 @@ var Escrows = class {
|
|
|
472
477
|
);
|
|
473
478
|
}
|
|
474
479
|
};
|
|
480
|
+
|
|
481
|
+
// src/resources/insights.ts
|
|
482
|
+
var Insights = class {
|
|
483
|
+
constructor(client) {
|
|
484
|
+
this.client = client;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Revenue, transactions, active escrows and commissions for a period, each
|
|
488
|
+
* with its change against the prior period.
|
|
489
|
+
*
|
|
490
|
+
* The route defaults to `7d`. `start` and `end` are ISO 8601 datetimes and are
|
|
491
|
+
* both required when `period` is `'custom'`.
|
|
492
|
+
*/
|
|
493
|
+
async overview(period, start, end) {
|
|
494
|
+
const query = new URLSearchParams();
|
|
495
|
+
if (period !== void 0) query.set("period", period);
|
|
496
|
+
if (start !== void 0) query.set("start", start);
|
|
497
|
+
if (end !== void 0) query.set("end", end);
|
|
498
|
+
const qs = query.toString();
|
|
499
|
+
return this.client["request"](
|
|
500
|
+
"GET",
|
|
501
|
+
qs ? `/v1/insights/overview?${qs}` : "/v1/insights/overview"
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Forecast a metric over a horizon. Gated to Growth+ plans; lower tiers
|
|
506
|
+
* surface a 403 `AuraAPIError`.
|
|
507
|
+
*/
|
|
508
|
+
async forecast(params) {
|
|
509
|
+
const query = new URLSearchParams();
|
|
510
|
+
query.set("metric", params.metric);
|
|
511
|
+
if (params.algorithm !== void 0) query.set("algorithm", params.algorithm);
|
|
512
|
+
if (params.period !== void 0) query.set("period", params.period);
|
|
513
|
+
if (params.horizon !== void 0) query.set("horizon", params.horizon.toString());
|
|
514
|
+
if (params.includeHistory !== void 0) {
|
|
515
|
+
query.set("includeHistory", String(params.includeHistory));
|
|
516
|
+
}
|
|
517
|
+
if (params.historyPeriods !== void 0) {
|
|
518
|
+
query.set("historyPeriods", params.historyPeriods.toString());
|
|
519
|
+
}
|
|
520
|
+
return this.client["request"](
|
|
521
|
+
"GET",
|
|
522
|
+
`/v1/insights/forecast?${query.toString()}`
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Query the account audit log by action, actor, resource and date range.
|
|
527
|
+
*
|
|
528
|
+
* The route defaults to `range: '30d'`, `page: 1`, `limit: 50`.
|
|
529
|
+
*/
|
|
530
|
+
async audit(params) {
|
|
531
|
+
const query = new URLSearchParams();
|
|
532
|
+
if (params?.action !== void 0) query.set("action", params.action);
|
|
533
|
+
if (params?.actor !== void 0) query.set("actor", params.actor);
|
|
534
|
+
if (params?.resourceType !== void 0) query.set("resourceType", params.resourceType);
|
|
535
|
+
if (params?.resourceId !== void 0) query.set("resourceId", params.resourceId);
|
|
536
|
+
if (params?.range !== void 0) query.set("range", params.range);
|
|
537
|
+
if (params?.start !== void 0) query.set("start", params.start);
|
|
538
|
+
if (params?.end !== void 0) query.set("end", params.end);
|
|
539
|
+
if (params?.page !== void 0) query.set("page", params.page.toString());
|
|
540
|
+
if (params?.limit !== void 0) query.set("limit", params.limit.toString());
|
|
541
|
+
const qs = query.toString();
|
|
542
|
+
return this.client["request"](
|
|
543
|
+
"GET",
|
|
544
|
+
qs ? `/v1/insights/audit?${qs}` : "/v1/insights/audit"
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
};
|
|
475
548
|
var Mandates = class {
|
|
476
549
|
constructor(client) {
|
|
477
550
|
this.client = client;
|
|
@@ -597,6 +670,24 @@ var Policies = class {
|
|
|
597
670
|
}
|
|
598
671
|
};
|
|
599
672
|
|
|
673
|
+
// src/resources/treasury.ts
|
|
674
|
+
var Treasury = class {
|
|
675
|
+
constructor(client) {
|
|
676
|
+
this.client = client;
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Analyze treasury balances, escrow exposure and pending payouts, and return
|
|
680
|
+
* an AI recommendation. Moves no funds.
|
|
681
|
+
*
|
|
682
|
+
* A POST with no body — the platform derives everything from the authenticated
|
|
683
|
+
* account. Gated to Growth+ plans; lower tiers surface a 403 `AuraAPIError`
|
|
684
|
+
* with code `feature_not_available`.
|
|
685
|
+
*/
|
|
686
|
+
async optimize() {
|
|
687
|
+
return this.client["request"]("POST", "/v1/treasury/optimize");
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
|
|
600
691
|
// src/resources/wallets.ts
|
|
601
692
|
var Wallets = class {
|
|
602
693
|
constructor(client) {
|
|
@@ -780,23 +871,89 @@ var Webhooks = class {
|
|
|
780
871
|
* Compute HMAC-SHA256 signature
|
|
781
872
|
*/
|
|
782
873
|
static computeHmacSignature(payload, secret) {
|
|
783
|
-
if (typeof crypto !== "undefined" && crypto.subtle) {
|
|
784
|
-
throw new Error("Web Crypto implementation needed for browser");
|
|
785
|
-
}
|
|
786
874
|
return createHmac("sha256", secret).update(payload).digest("hex");
|
|
787
875
|
}
|
|
788
876
|
/**
|
|
789
|
-
* Constant-time
|
|
877
|
+
* Constant-time comparison of two hex signatures.
|
|
878
|
+
*
|
|
879
|
+
* Length is compared first because `timingSafeEqual` throws on mismatched
|
|
880
|
+
* buffers; that only reveals the length of an attacker-supplied signature,
|
|
881
|
+
* never the contents of the expected one.
|
|
790
882
|
*/
|
|
791
883
|
static secureCompare(a, b) {
|
|
792
|
-
|
|
884
|
+
const left = Buffer.from(a, "utf8");
|
|
885
|
+
const right = Buffer.from(b, "utf8");
|
|
886
|
+
if (left.length !== right.length) {
|
|
793
887
|
return false;
|
|
794
888
|
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
889
|
+
return timingSafeEqual(left, right);
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
// src/resources/withdrawals.ts
|
|
894
|
+
var Withdrawals = class {
|
|
895
|
+
constructor(client) {
|
|
896
|
+
this.client = client;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Get a single withdrawal, including status, fees, destination and tx hash.
|
|
900
|
+
*/
|
|
901
|
+
async get(withdrawalId) {
|
|
902
|
+
return this.client["request"](
|
|
903
|
+
"GET",
|
|
904
|
+
`/v1/withdrawals/${encodeURIComponent(withdrawalId)}`
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* List withdrawals for the account, most recent first.
|
|
909
|
+
*
|
|
910
|
+
* Returns the whole `{withdrawals, pagination}` envelope — this route does not
|
|
911
|
+
* use the `{success,data}` wrapper, so pagination metadata is preserved.
|
|
912
|
+
*/
|
|
913
|
+
async list(params) {
|
|
914
|
+
const query = new URLSearchParams();
|
|
915
|
+
if (params?.limit !== void 0) query.set("limit", params.limit.toString());
|
|
916
|
+
if (params?.offset !== void 0) query.set("offset", params.offset.toString());
|
|
917
|
+
if (params?.status !== void 0) query.set("status", params.status);
|
|
918
|
+
if (params?.chain !== void 0) query.set("chain", params.chain);
|
|
919
|
+
if (params?.fromDate !== void 0) query.set("fromDate", params.fromDate);
|
|
920
|
+
if (params?.toDate !== void 0) query.set("toDate", params.toDate);
|
|
921
|
+
const qs = query.toString();
|
|
922
|
+
return this.client["request"](
|
|
923
|
+
"GET",
|
|
924
|
+
qs ? `/v1/withdrawals?${qs}` : "/v1/withdrawals"
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Preview fees and net amount for a withdrawal WITHOUT creating it.
|
|
929
|
+
*
|
|
930
|
+
* `params.exchange` is required by the route when `destinationType` is
|
|
931
|
+
* `'exchange'`; cross-chain estimates (source ≠ destination) add a CCTP
|
|
932
|
+
* bridge fee and only the supported routes are accepted.
|
|
933
|
+
*/
|
|
934
|
+
async estimate(params) {
|
|
935
|
+
return this.client["request"](
|
|
936
|
+
"POST",
|
|
937
|
+
"/v1/withdrawals/estimate",
|
|
938
|
+
params
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* Get the account's KYC-tier withdrawal limits and remaining allowance.
|
|
943
|
+
*/
|
|
944
|
+
async limits() {
|
|
945
|
+
return this.client["request"]("GET", "/v1/withdrawals/limits");
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Validate a destination address for a chain. Moves no funds; when `amount` is
|
|
949
|
+
* supplied the response also carries a fee preview.
|
|
950
|
+
*/
|
|
951
|
+
async validate(params) {
|
|
952
|
+
return this.client["request"](
|
|
953
|
+
"POST",
|
|
954
|
+
"/v1/withdrawals/validate",
|
|
955
|
+
params
|
|
956
|
+
);
|
|
800
957
|
}
|
|
801
958
|
};
|
|
802
959
|
|
|
@@ -817,6 +974,9 @@ var AuraClient = class _AuraClient {
|
|
|
817
974
|
this.agents = new Agents(this);
|
|
818
975
|
this.policies = new Policies(this);
|
|
819
976
|
this.mandates = new Mandates(this);
|
|
977
|
+
this.withdrawals = new Withdrawals(this);
|
|
978
|
+
this.treasury = new Treasury(this);
|
|
979
|
+
this.insights = new Insights(this);
|
|
820
980
|
}
|
|
821
981
|
/**
|
|
822
982
|
* Normalize the base URL so resource paths like `/v1/escrow` reach the
|
|
@@ -860,7 +1020,8 @@ var AuraClient = class _AuraClient {
|
|
|
860
1020
|
* Make an authenticated request to the API with automatic retry logic
|
|
861
1021
|
*/
|
|
862
1022
|
async request(method, path, body, options) {
|
|
863
|
-
const
|
|
1023
|
+
const idempotencyKey = options?.idempotencyKey ?? (this.autoIdempotency && (method === "POST" || method === "PUT") ? generateIdempotencyKey() : void 0);
|
|
1024
|
+
const requestFn = () => this.executeRequest(method, path, body, { ...options, idempotencyKey });
|
|
864
1025
|
if (options?.skipRetry || method === "GET") {
|
|
865
1026
|
return requestFn();
|
|
866
1027
|
}
|
|
@@ -874,12 +1035,10 @@ var AuraClient = class _AuraClient {
|
|
|
874
1035
|
const headers = {
|
|
875
1036
|
"Content-Type": "application/json",
|
|
876
1037
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
877
|
-
"User-Agent": "@aura-payments/sdk/2.1.
|
|
1038
|
+
"User-Agent": "@aura-payments/sdk/2.1.1"
|
|
878
1039
|
};
|
|
879
1040
|
if (options?.idempotencyKey) {
|
|
880
1041
|
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
881
|
-
} else if (this.autoIdempotency && (method === "POST" || method === "PUT")) {
|
|
882
|
-
headers["Idempotency-Key"] = generateIdempotencyKey();
|
|
883
1042
|
}
|
|
884
1043
|
try {
|
|
885
1044
|
const response = await withTimeout(
|
|
@@ -980,6 +1139,4 @@ var AuraClient = class _AuraClient {
|
|
|
980
1139
|
}
|
|
981
1140
|
};
|
|
982
1141
|
|
|
983
|
-
export { Agents, AuraAPIError, AuraAuthenticationError, AuraClient, AuraError, AuraFaucetUnavailableError, AuraNetworkError, AuraNotFoundError, AuraRateLimitError, AuraTimeoutError, AuraValidationError, Escrows, MandateSignature, Mandates, Policies, Wallets, Webhooks, calculateBackoff, generateIdempotencyKey, isAuraAPIError, isAuraError, isAuraFaucetUnavailableError, isAuraNetworkError, isAuraTimeoutError, isRetryableError, retryWithBackoff, withTimeout };
|
|
984
|
-
//# sourceMappingURL=index.mjs.map
|
|
985
|
-
//# sourceMappingURL=index.mjs.map
|
|
1142
|
+
export { Agents, AuraAPIError, AuraAuthenticationError, AuraClient, AuraError, AuraFaucetUnavailableError, AuraNetworkError, AuraNotFoundError, AuraRateLimitError, AuraTimeoutError, AuraValidationError, Escrows, Insights, MandateSignature, Mandates, Policies, Treasury, Wallets, Webhooks, Withdrawals, calculateBackoff, generateIdempotencyKey, isAuraAPIError, isAuraError, isAuraFaucetUnavailableError, isAuraNetworkError, isAuraTimeoutError, isRetryableError, retryWithBackoff, withTimeout };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aura-payments/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "TypeScript SDK for Aura Payments Platform",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -27,9 +27,21 @@
|
|
|
27
27
|
],
|
|
28
28
|
"author": "Aura Payments",
|
|
29
29
|
"license": "MIT",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/humancodex/ap.git",
|
|
33
|
+
"directory": "packages/sdk"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://getaura.sh",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/humancodex/ap/issues"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=20.0.0"
|
|
41
|
+
},
|
|
30
42
|
"dependencies": {
|
|
31
43
|
"zod": "^3.25.76",
|
|
32
|
-
"@aura-payments/shared": "2.0.
|
|
44
|
+
"@aura-payments/shared": "2.0.1"
|
|
33
45
|
},
|
|
34
46
|
"devDependencies": {
|
|
35
47
|
"@types/jest": "^29.5.0",
|