@fystack/sdk 0.1.10 → 0.1.11

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.esm.js CHANGED
@@ -18,7 +18,7 @@ const getBaseURL = (env)=>{
18
18
  case "sandbox":
19
19
  return 'https://api-dev.fystack.io';
20
20
  case "production":
21
- return 'https://api.fystack.io';
21
+ return 'https://fystack.excelon.io';
22
22
  }
23
23
  };
24
24
  const createAPI = (env)=>{
@@ -44,7 +44,8 @@ const createAPI = (env)=>{
44
44
  getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`),
45
45
  rescanTransaction: ()=>withBaseURL('/networks/rescan-transaction'),
46
46
  requestWithdrawal: (walletId)=>withBaseURL(`/wallets/${walletId}/request-withdrawal`),
47
- getWebhookPublicKey: (workspaceId)=>withBaseURL(`/workspaces/${workspaceId}/webhook-verification-key`)
47
+ getWebhookPublicKey: (workspaceId)=>withBaseURL(`/workspaces/${workspaceId}/webhook-verification-key`),
48
+ createSweepTask: (workspaceId)=>withBaseURL(`/workspaces/${workspaceId}/automation/sweep-task`)
48
49
  }
49
50
  };
50
51
  };
@@ -185,6 +186,20 @@ var WithdrawalStatus;
185
186
  WithdrawalStatus["Completed"] = "completed";
186
187
  WithdrawalStatus["Failed"] = "failed";
187
188
  })(WithdrawalStatus || (WithdrawalStatus = {}));
189
+ var SweepStrategy;
190
+ (function(SweepStrategy) {
191
+ SweepStrategy["Periodic"] = "periodic";
192
+ })(SweepStrategy || (SweepStrategy = {}));
193
+ var SweepType;
194
+ (function(SweepType) {
195
+ SweepType["Default"] = "default";
196
+ SweepType["PaymentLink"] = "payment_link";
197
+ SweepType["Checkout"] = "checkout";
198
+ })(SweepType || (SweepType = {}));
199
+ var ReserveType;
200
+ (function(ReserveType) {
201
+ ReserveType["FixedUsd"] = "fixed_usd";
202
+ })(ReserveType || (ReserveType = {}));
188
203
 
189
204
  async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}, headers) {
190
205
  if (!credentials.apiSecret || credentials.apiSecret === '') {
@@ -326,6 +341,13 @@ class APIService {
326
341
  const response = await get(endpoint, headers);
327
342
  return response.data;
328
343
  }
344
+ async createSweepTask(workspaceId, params) {
345
+ const endpoint = this.API.endpoints.createSweepTask(workspaceId);
346
+ const transformedParams = transformCreateSweepTaskParams(params);
347
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams);
348
+ const response = await post(endpoint, transformedParams, headers);
349
+ return response.data;
350
+ }
329
351
  constructor(credentials, environment){
330
352
  this.credentials = credentials;
331
353
  this.Webhook = new WebhookService(credentials);
@@ -462,6 +484,37 @@ function transformRequestWithdrawalParams(data) {
462
484
  }
463
485
  };
464
486
  }
487
+ function transformCreateSweepTaskParams(data) {
488
+ return {
489
+ name: data.name,
490
+ strategy: data.strategy,
491
+ min_trigger_value_usd: data.minTriggerValueUsd,
492
+ destination_wallet_id: data.destinationWalletId,
493
+ frequency_in_seconds: data.frequencyInSeconds,
494
+ wallet_ids: data.walletIds,
495
+ ...data.sweepType !== undefined && {
496
+ sweep_type: data.sweepType
497
+ },
498
+ ...data.destinationType !== undefined && {
499
+ destination_type: data.destinationType
500
+ },
501
+ ...data.assetIds !== undefined && {
502
+ asset_ids: data.assetIds
503
+ },
504
+ ...data.reserveType !== undefined && {
505
+ reserve_type: data.reserveType
506
+ },
507
+ ...data.reserveAmountUsd !== undefined && {
508
+ reserve_amount_usd: data.reserveAmountUsd
509
+ },
510
+ ...data.reservePercentageUsd !== undefined && {
511
+ reserve_percentage_usd: data.reservePercentageUsd
512
+ },
513
+ ...data.enabled !== undefined && {
514
+ enabled: data.enabled
515
+ }
516
+ };
517
+ }
465
518
  BigInt.prototype.toJSON = function() {
466
519
  return this.toString();
467
520
  };
@@ -522,7 +575,7 @@ class StatusPoller {
522
575
 
523
576
  class FystackSDK {
524
577
  log(message) {
525
- if (this.enableLogging) {
578
+ if (this.debugEnabled) {
526
579
  console.log(`[FystackSDK] ${message}`);
527
580
  }
528
581
  }
@@ -657,11 +710,45 @@ class FystackSDK {
657
710
  const response = await this.apiService.getWebhookPublicKey(workspaceId);
658
711
  return response;
659
712
  }
713
+ /** @internal */ _getApiService() {
714
+ return this.apiService;
715
+ }
716
+ /** @internal */ _log(message) {
717
+ this.log(message);
718
+ }
719
+ /** @internal */ _getWorkspaceId() {
720
+ if (!this.workspaceId) {
721
+ throw new Error('Workspace ID is required. Please set workspaceId in the constructor.');
722
+ }
723
+ return this.workspaceId;
724
+ }
660
725
  constructor(options){
661
- const { credentials, workspaceId, environment = Environment.Production, logger = false } = options;
726
+ const { credentials, workspaceId, environment = Environment.Production, debug = false } = options;
662
727
  this.apiService = new APIService(credentials, environment);
663
- this.enableLogging = logger;
728
+ this.debugEnabled = debug;
664
729
  this.workspaceId = workspaceId;
730
+ this.automation = new AutomationNamespace(this);
731
+ }
732
+ }
733
+ class AutomationNamespace {
734
+ async createSweepTask(params) {
735
+ const workspaceId = this.sdk._getWorkspaceId();
736
+ validateUUID(params.destinationWalletId, 'destinationWalletId');
737
+ for (const walletId of params.walletIds){
738
+ validateUUID(walletId, 'walletIds');
739
+ }
740
+ if (params.assetIds) {
741
+ for (const assetId of params.assetIds){
742
+ validateUUID(assetId, 'assetIds');
743
+ }
744
+ }
745
+ this.sdk._log(`Creating sweep task "${params.name}" for workspace ${workspaceId}`);
746
+ const response = await this.sdk._getApiService().createSweepTask(workspaceId, params);
747
+ this.sdk._log(`Sweep task created with ID: ${response.id}`);
748
+ return response;
749
+ }
750
+ constructor(sdk){
751
+ this.sdk = sdk;
665
752
  }
666
753
  }
667
754
 
@@ -1115,4 +1202,4 @@ class SolanaSigner {
1115
1202
  }
1116
1203
  }
1117
1204
 
1118
- export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, DestinationType, Environment, EtherSigner, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus, WalletCreationStatus, WalletPurpose, WalletRole, WalletType, WebhookService, WithdrawalStatus, createAPI, get, post, transformCreateWalletPayload, transformRequestWithdrawalParams, transformRescanTransactionParams, transformWalletDetail };
1205
+ export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, DestinationType, Environment, EtherSigner, FystackSDK, PaymentService, ReserveType, SolanaSigner, StatusPoller, SweepStrategy, SweepType, TransactionError, TxApprovalStatus, TxStatus, WalletCreationStatus, WalletPurpose, WalletRole, WalletType, WebhookService, WithdrawalStatus, createAPI, get, post, transformCreateSweepTaskParams, transformCreateWalletPayload, transformRequestWithdrawalParams, transformRescanTransactionParams, transformWalletDetail };
package/dist/index.mjs CHANGED
@@ -18,7 +18,7 @@ const getBaseURL = (env)=>{
18
18
  case "sandbox":
19
19
  return 'https://api-dev.fystack.io';
20
20
  case "production":
21
- return 'https://api.fystack.io';
21
+ return 'https://fystack.excelon.io';
22
22
  }
23
23
  };
24
24
  const createAPI = (env)=>{
@@ -44,7 +44,8 @@ const createAPI = (env)=>{
44
44
  getDepositAddress: (walletId, addressType)=>withBaseURL(`/wallets/${walletId}/deposit-address?address_type=${addressType}`),
45
45
  rescanTransaction: ()=>withBaseURL('/networks/rescan-transaction'),
46
46
  requestWithdrawal: (walletId)=>withBaseURL(`/wallets/${walletId}/request-withdrawal`),
47
- getWebhookPublicKey: (workspaceId)=>withBaseURL(`/workspaces/${workspaceId}/webhook-verification-key`)
47
+ getWebhookPublicKey: (workspaceId)=>withBaseURL(`/workspaces/${workspaceId}/webhook-verification-key`),
48
+ createSweepTask: (workspaceId)=>withBaseURL(`/workspaces/${workspaceId}/automation/sweep-task`)
48
49
  }
49
50
  };
50
51
  };
@@ -185,6 +186,20 @@ var WithdrawalStatus;
185
186
  WithdrawalStatus["Completed"] = "completed";
186
187
  WithdrawalStatus["Failed"] = "failed";
187
188
  })(WithdrawalStatus || (WithdrawalStatus = {}));
189
+ var SweepStrategy;
190
+ (function(SweepStrategy) {
191
+ SweepStrategy["Periodic"] = "periodic";
192
+ })(SweepStrategy || (SweepStrategy = {}));
193
+ var SweepType;
194
+ (function(SweepType) {
195
+ SweepType["Default"] = "default";
196
+ SweepType["PaymentLink"] = "payment_link";
197
+ SweepType["Checkout"] = "checkout";
198
+ })(SweepType || (SweepType = {}));
199
+ var ReserveType;
200
+ (function(ReserveType) {
201
+ ReserveType["FixedUsd"] = "fixed_usd";
202
+ })(ReserveType || (ReserveType = {}));
188
203
 
189
204
  async function composeAPIHeaders(credentials, httpMethod, apiEndpoint, body = {}, headers) {
190
205
  if (!credentials.apiSecret || credentials.apiSecret === '') {
@@ -326,6 +341,13 @@ class APIService {
326
341
  const response = await get(endpoint, headers);
327
342
  return response.data;
328
343
  }
344
+ async createSweepTask(workspaceId, params) {
345
+ const endpoint = this.API.endpoints.createSweepTask(workspaceId);
346
+ const transformedParams = transformCreateSweepTaskParams(params);
347
+ const headers = await composeAPIHeaders(this.credentials, 'POST', endpoint, transformedParams);
348
+ const response = await post(endpoint, transformedParams, headers);
349
+ return response.data;
350
+ }
329
351
  constructor(credentials, environment){
330
352
  this.credentials = credentials;
331
353
  this.Webhook = new WebhookService(credentials);
@@ -462,6 +484,37 @@ function transformRequestWithdrawalParams(data) {
462
484
  }
463
485
  };
464
486
  }
487
+ function transformCreateSweepTaskParams(data) {
488
+ return {
489
+ name: data.name,
490
+ strategy: data.strategy,
491
+ min_trigger_value_usd: data.minTriggerValueUsd,
492
+ destination_wallet_id: data.destinationWalletId,
493
+ frequency_in_seconds: data.frequencyInSeconds,
494
+ wallet_ids: data.walletIds,
495
+ ...data.sweepType !== undefined && {
496
+ sweep_type: data.sweepType
497
+ },
498
+ ...data.destinationType !== undefined && {
499
+ destination_type: data.destinationType
500
+ },
501
+ ...data.assetIds !== undefined && {
502
+ asset_ids: data.assetIds
503
+ },
504
+ ...data.reserveType !== undefined && {
505
+ reserve_type: data.reserveType
506
+ },
507
+ ...data.reserveAmountUsd !== undefined && {
508
+ reserve_amount_usd: data.reserveAmountUsd
509
+ },
510
+ ...data.reservePercentageUsd !== undefined && {
511
+ reserve_percentage_usd: data.reservePercentageUsd
512
+ },
513
+ ...data.enabled !== undefined && {
514
+ enabled: data.enabled
515
+ }
516
+ };
517
+ }
465
518
  BigInt.prototype.toJSON = function() {
466
519
  return this.toString();
467
520
  };
@@ -522,7 +575,7 @@ class StatusPoller {
522
575
 
523
576
  class FystackSDK {
524
577
  log(message) {
525
- if (this.enableLogging) {
578
+ if (this.debugEnabled) {
526
579
  console.log(`[FystackSDK] ${message}`);
527
580
  }
528
581
  }
@@ -657,11 +710,45 @@ class FystackSDK {
657
710
  const response = await this.apiService.getWebhookPublicKey(workspaceId);
658
711
  return response;
659
712
  }
713
+ /** @internal */ _getApiService() {
714
+ return this.apiService;
715
+ }
716
+ /** @internal */ _log(message) {
717
+ this.log(message);
718
+ }
719
+ /** @internal */ _getWorkspaceId() {
720
+ if (!this.workspaceId) {
721
+ throw new Error('Workspace ID is required. Please set workspaceId in the constructor.');
722
+ }
723
+ return this.workspaceId;
724
+ }
660
725
  constructor(options){
661
- const { credentials, workspaceId, environment = Environment.Production, logger = false } = options;
726
+ const { credentials, workspaceId, environment = Environment.Production, debug = false } = options;
662
727
  this.apiService = new APIService(credentials, environment);
663
- this.enableLogging = logger;
728
+ this.debugEnabled = debug;
664
729
  this.workspaceId = workspaceId;
730
+ this.automation = new AutomationNamespace(this);
731
+ }
732
+ }
733
+ class AutomationNamespace {
734
+ async createSweepTask(params) {
735
+ const workspaceId = this.sdk._getWorkspaceId();
736
+ validateUUID(params.destinationWalletId, 'destinationWalletId');
737
+ for (const walletId of params.walletIds){
738
+ validateUUID(walletId, 'walletIds');
739
+ }
740
+ if (params.assetIds) {
741
+ for (const assetId of params.assetIds){
742
+ validateUUID(assetId, 'assetIds');
743
+ }
744
+ }
745
+ this.sdk._log(`Creating sweep task "${params.name}" for workspace ${workspaceId}`);
746
+ const response = await this.sdk._getApiService().createSweepTask(workspaceId, params);
747
+ this.sdk._log(`Sweep task created with ID: ${response.id}`);
748
+ return response;
749
+ }
750
+ constructor(sdk){
751
+ this.sdk = sdk;
665
752
  }
666
753
  }
667
754
 
@@ -1115,4 +1202,4 @@ class SolanaSigner {
1115
1202
  }
1116
1203
  }
1117
1204
 
1118
- export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, DestinationType, Environment, EtherSigner, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus, WalletCreationStatus, WalletPurpose, WalletRole, WalletType, WebhookService, WithdrawalStatus, createAPI, get, post, transformCreateWalletPayload, transformRequestWithdrawalParams, transformRescanTransactionParams, transformWalletDetail };
1205
+ export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, DestinationType, Environment, EtherSigner, FystackSDK, PaymentService, ReserveType, SolanaSigner, StatusPoller, SweepStrategy, SweepType, TransactionError, TxApprovalStatus, TxStatus, WalletCreationStatus, WalletPurpose, WalletRole, WalletType, WebhookService, WithdrawalStatus, createAPI, get, post, transformCreateSweepTaskParams, transformCreateWalletPayload, transformRequestWithdrawalParams, transformRescanTransactionParams, transformWalletDetail };