@fystack/sdk 0.1.10 → 0.1.12

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/api.sh ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # ── Configuration ──
5
+ API_KEY="0ae1f9dc-d645-4a63-84e3-6badfaaef424"
6
+ API_SECRET="2d604e677003ea15d61fdf7c0077d013bd6d99500a1b0b1604a5cd31ad5646c7"
7
+ WORKSPACE_ID="6b329161-7d36-47c7-926a-34ca9e2d0767"
8
+ BASE_URL="${BASE_URL:-https://fystack.excelon.io}"
9
+
10
+ METHOD="GET"
11
+ REQ_PATH="/api/v1/workspaces/${WORKSPACE_ID}/wallets"
12
+ BODY=""
13
+
14
+ # ── Sign ──
15
+ TS=$(date +%s)
16
+ CANONICAL="method=${METHOD}&path=${REQ_PATH}&timestamp=${TS}&body=${BODY}"
17
+
18
+ ACCESS_SIGN=$(printf '%s' "$CANONICAL" \
19
+ | openssl dgst -sha256 -hmac "$API_SECRET" -binary \
20
+ | xxd -p -c 256 \
21
+ | tr -d '\n' \
22
+ | base64 -w 0)
23
+
24
+ echo "CANONICAL: $CANONICAL"
25
+ echo "ACCESS-SIGN: $ACCESS_SIGN"
26
+ echo "TIMESTAMP: $TS"
27
+
28
+ # ── Request ──
29
+ CURL_ARGS=(
30
+ -sS --http1.1
31
+ -X "$METHOD"
32
+ -H "ACCESS-API-KEY: $API_KEY"
33
+ -H "ACCESS-TIMESTAMP: $TS"
34
+ -H "ACCESS-SIGN: $ACCESS_SIGN"
35
+ )
36
+
37
+ if [[ -n "$BODY" ]]; then
38
+ CURL_ARGS+=(-H "Content-Type: application/json" -d "$BODY")
39
+ fi
40
+
41
+ curl "${CURL_ARGS[@]}" "${BASE_URL}${REQ_PATH}"
42
+ echo
package/dist/index.cjs CHANGED
@@ -26,7 +26,7 @@ const getBaseURL = (env)=>{
26
26
  case "sandbox":
27
27
  return 'https://api-dev.fystack.io';
28
28
  case "production":
29
- return 'https://api.fystack.io';
29
+ return 'https://fystack.excelon.io';
30
30
  }
31
31
  };
32
32
  const createAPI = (env)=>{
@@ -52,7 +52,8 @@ const createAPI = (env)=>{
52
52
  getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`),
53
53
  rescanTransaction: ()=>withBaseURL('/networks/rescan-transaction'),
54
54
  requestWithdrawal: (walletId)=>withBaseURL(`/wallets/${walletId}/request-withdrawal`),
55
- getWebhookPublicKey: (workspaceId)=>withBaseURL(`/workspaces/${workspaceId}/webhook-verification-key`)
55
+ getWebhookPublicKey: (workspaceId)=>withBaseURL(`/workspaces/${workspaceId}/webhook-verification-key`),
56
+ createSweepTask: (workspaceId)=>withBaseURL(`/workspaces/${workspaceId}/automation/sweep-task`)
56
57
  }
57
58
  };
58
59
  };
@@ -193,6 +194,20 @@ exports.WithdrawalStatus = void 0;
193
194
  WithdrawalStatus["Completed"] = "completed";
194
195
  WithdrawalStatus["Failed"] = "failed";
195
196
  })(exports.WithdrawalStatus || (exports.WithdrawalStatus = {}));
197
+ exports.SweepStrategy = void 0;
198
+ (function(SweepStrategy) {
199
+ SweepStrategy["Periodic"] = "periodic";
200
+ })(exports.SweepStrategy || (exports.SweepStrategy = {}));
201
+ exports.SweepType = void 0;
202
+ (function(SweepType) {
203
+ SweepType["Default"] = "default";
204
+ SweepType["PaymentLink"] = "payment_link";
205
+ SweepType["Checkout"] = "checkout";
206
+ })(exports.SweepType || (exports.SweepType = {}));
207
+ exports.ReserveType = void 0;
208
+ (function(ReserveType) {
209
+ ReserveType["FixedUsd"] = "fixed_usd";
210
+ })(exports.ReserveType || (exports.ReserveType = {}));
196
211
 
197
212
  async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}, headers) {
198
213
  if (!credentials.apiSecret || credentials.apiSecret === '') {
@@ -334,6 +349,13 @@ class APIService {
334
349
  const response = await get(endpoint, headers);
335
350
  return response.data;
336
351
  }
352
+ async createSweepTask(workspaceId, params) {
353
+ const endpoint = this.API.endpoints.createSweepTask(workspaceId);
354
+ const transformedParams = transformCreateSweepTaskParams(params);
355
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams);
356
+ const response = await post(endpoint, transformedParams, headers);
357
+ return response.data;
358
+ }
337
359
  constructor(credentials, environment){
338
360
  this.credentials = credentials;
339
361
  this.Webhook = new WebhookService(credentials);
@@ -470,6 +492,37 @@ function transformRequestWithdrawalParams(data) {
470
492
  }
471
493
  };
472
494
  }
495
+ function transformCreateSweepTaskParams(data) {
496
+ return {
497
+ name: data.name,
498
+ strategy: data.strategy,
499
+ min_trigger_value_usd: data.minTriggerValueUsd,
500
+ destination_wallet_id: data.destinationWalletId,
501
+ frequency_in_seconds: data.frequencyInSeconds,
502
+ wallet_ids: data.walletIds,
503
+ ...data.sweepType !== undefined && {
504
+ sweep_type: data.sweepType
505
+ },
506
+ ...data.destinationType !== undefined && {
507
+ destination_type: data.destinationType
508
+ },
509
+ ...data.assetIds !== undefined && {
510
+ asset_ids: data.assetIds
511
+ },
512
+ ...data.reserveType !== undefined && {
513
+ reserve_type: data.reserveType
514
+ },
515
+ ...data.reserveAmountUsd !== undefined && {
516
+ reserve_amount_usd: data.reserveAmountUsd
517
+ },
518
+ ...data.reservePercentageUsd !== undefined && {
519
+ reserve_percentage_usd: data.reservePercentageUsd
520
+ },
521
+ ...data.enabled !== undefined && {
522
+ enabled: data.enabled
523
+ }
524
+ };
525
+ }
473
526
  BigInt.prototype.toJSON = function() {
474
527
  return this.toString();
475
528
  };
@@ -530,7 +583,7 @@ class StatusPoller {
530
583
 
531
584
  class FystackSDK {
532
585
  log(message) {
533
- if (this.enableLogging) {
586
+ if (this.debugEnabled) {
534
587
  console.log(`[FystackSDK] ${message}`);
535
588
  }
536
589
  }
@@ -665,11 +718,45 @@ class FystackSDK {
665
718
  const response = await this.apiService.getWebhookPublicKey(workspaceId);
666
719
  return response;
667
720
  }
721
+ /** @internal */ _getApiService() {
722
+ return this.apiService;
723
+ }
724
+ /** @internal */ _log(message) {
725
+ this.log(message);
726
+ }
727
+ /** @internal */ _getWorkspaceId() {
728
+ if (!this.workspaceId) {
729
+ throw new Error('Workspace ID is required. Please set workspaceId in the constructor.');
730
+ }
731
+ return this.workspaceId;
732
+ }
668
733
  constructor(options){
669
- const { credentials, workspaceId, environment = exports.Environment.Production, logger = false } = options;
734
+ const { credentials, workspaceId, environment = exports.Environment.Production, debug = false } = options;
670
735
  this.apiService = new APIService(credentials, environment);
671
- this.enableLogging = logger;
736
+ this.debugEnabled = debug;
672
737
  this.workspaceId = workspaceId;
738
+ this.automation = new AutomationNamespace(this);
739
+ }
740
+ }
741
+ class AutomationNamespace {
742
+ async createSweepTask(params) {
743
+ const workspaceId = this.sdk._getWorkspaceId();
744
+ validateUUID(params.destinationWalletId, 'destinationWalletId');
745
+ for (const walletId of params.walletIds){
746
+ validateUUID(walletId, 'walletIds');
747
+ }
748
+ if (params.assetIds) {
749
+ for (const assetId of params.assetIds){
750
+ validateUUID(assetId, 'assetIds');
751
+ }
752
+ }
753
+ this.sdk._log(`Creating sweep task "${params.name}" for workspace ${workspaceId}`);
754
+ const response = await this.sdk._getApiService().createSweepTask(workspaceId, params);
755
+ this.sdk._log(`Sweep task created with ID: ${response.id}`);
756
+ return response;
757
+ }
758
+ constructor(sdk){
759
+ this.sdk = sdk;
673
760
  }
674
761
  }
675
762
 
@@ -1135,6 +1222,7 @@ exports.WebhookService = WebhookService;
1135
1222
  exports.createAPI = createAPI;
1136
1223
  exports.get = get;
1137
1224
  exports.post = post;
1225
+ exports.transformCreateSweepTaskParams = transformCreateSweepTaskParams;
1138
1226
  exports.transformCreateWalletPayload = transformCreateWalletPayload;
1139
1227
  exports.transformRequestWithdrawalParams = transformRequestWithdrawalParams;
1140
1228
  exports.transformRescanTransactionParams = transformRescanTransactionParams;