@fystack/sdk 0.1.12 → 0.1.14

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.cjs CHANGED
@@ -26,11 +26,25 @@ const getBaseURL = (env)=>{
26
26
  case "sandbox":
27
27
  return 'https://api-dev.fystack.io';
28
28
  case "production":
29
- return 'https://fystack.excelon.io';
29
+ return 'https://api.fystack.io';
30
30
  }
31
31
  };
32
- const createAPI = (env)=>{
33
- const baseURL = `${getBaseURL(env)}/api/v1`;
32
+ function validateDomain(domain) {
33
+ const domainPattern = /^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
34
+ if (!domainPattern.test(domain)) {
35
+ throw new Error(`Invalid domain: "${domain}". Expected a valid domain like "api.example.com"`);
36
+ }
37
+ }
38
+ const createAPI = (env, domain)=>{
39
+ let baseURL;
40
+ if (domain) {
41
+ validateDomain(domain);
42
+ baseURL = `https://${domain}/api/v1`;
43
+ } else if (env) {
44
+ baseURL = `${getBaseURL(env)}/api/v1`;
45
+ } else {
46
+ baseURL = `${getBaseURL("production")}/api/v1`;
47
+ }
34
48
  const withBaseURL = (path)=>`${baseURL}${path}`;
35
49
  return {
36
50
  baseURL,
@@ -145,6 +159,7 @@ exports.WalletPurpose = void 0;
145
159
  WalletPurpose["Custody"] = "custody";
146
160
  WalletPurpose["User"] = "user";
147
161
  WalletPurpose["Payment"] = "payment";
162
+ WalletPurpose["OneTimeUse"] = "one_time_use";
148
163
  })(exports.WalletPurpose || (exports.WalletPurpose = {}));
149
164
  exports.WalletCreationStatus = void 0;
150
165
  (function(WalletCreationStatus) {
@@ -356,10 +371,10 @@ class APIService {
356
371
  const response = await post(endpoint, transformedParams, headers);
357
372
  return response.data;
358
373
  }
359
- constructor(credentials, environment){
374
+ constructor(credentials, environment, domain){
360
375
  this.credentials = credentials;
361
376
  this.Webhook = new WebhookService(credentials);
362
- this.API = createAPI(environment);
377
+ this.API = createAPI(environment, domain);
363
378
  }
364
379
  }
365
380
  class PaymentService {
@@ -388,7 +403,7 @@ class PaymentService {
388
403
  }
389
404
  constructor(params){
390
405
  this.apiKey = params.apiKey;
391
- this.API = createAPI(params.environment);
406
+ this.API = createAPI(params.environment, params.domain);
392
407
  }
393
408
  }
394
409
  class WebhookService {
@@ -481,7 +496,15 @@ function transformRescanTransactionParams(data) {
481
496
  }
482
497
  function transformRequestWithdrawalParams(data) {
483
498
  return {
484
- asset_id: data.assetId,
499
+ ...data.assetId !== undefined && {
500
+ asset_id: data.assetId
501
+ },
502
+ ...data.network !== undefined && {
503
+ network: data.network
504
+ },
505
+ ...data.asset !== undefined && {
506
+ asset: data.asset
507
+ },
485
508
  amount: data.amount,
486
509
  recipient_address: data.recipientAddress,
487
510
  ...data.notes !== undefined && {
@@ -690,7 +713,11 @@ class FystackSDK {
690
713
  * @returns Promise with withdrawal response including auto_approved status and withdrawal details
691
714
  */ async requestWithdrawal(walletId, params) {
692
715
  validateUUID(walletId, 'walletId');
693
- validateUUID(params.assetId, 'assetId');
716
+ if (params.assetId) {
717
+ validateUUID(params.assetId, 'assetId');
718
+ } else if (!params.asset || !params.network) {
719
+ throw new Error('Either assetId or both asset and network must be provided');
720
+ }
694
721
  if (!params.amount || params.amount.trim() === '') {
695
722
  throw new Error('Invalid amount provided');
696
723
  }
@@ -731,8 +758,8 @@ class FystackSDK {
731
758
  return this.workspaceId;
732
759
  }
733
760
  constructor(options){
734
- const { credentials, workspaceId, environment = exports.Environment.Production, debug = false } = options;
735
- this.apiService = new APIService(credentials, environment);
761
+ const { credentials, workspaceId, environment = exports.Environment.Production, domain, debug = false } = options;
762
+ this.apiService = new APIService(credentials, environment, domain);
736
763
  this.debugEnabled = debug;
737
764
  this.workspaceId = workspaceId;
738
765
  this.automation = new AutomationNamespace(this);
package/dist/index.d.cts CHANGED
@@ -11,7 +11,8 @@ declare enum WalletPurpose {
11
11
  Deployment = "deployment",
12
12
  Custody = "custody",
13
13
  User = "user",
14
- Payment = "payment"
14
+ Payment = "payment",
15
+ OneTimeUse = "one_time_use"
15
16
  }
16
17
  declare enum WalletCreationStatus {
17
18
  Pending = "pending",
@@ -95,7 +96,7 @@ interface APIConfig {
95
96
  baseURL: string;
96
97
  endpoints: APIEndpoints;
97
98
  }
98
- declare const createAPI: (env: Environment) => APIConfig;
99
+ declare const createAPI: (env?: Environment, domain?: string) => APIConfig;
99
100
 
100
101
  declare class TransactionError extends Error {
101
102
  readonly code: string;
@@ -237,7 +238,9 @@ interface WalletByWorkspaceResponse {
237
238
  wallet_purpose: string;
238
239
  }
239
240
  interface RequestWithdrawalParams {
240
- assetId: string;
241
+ assetId?: string;
242
+ network?: string;
243
+ asset?: string;
241
244
  amount: string;
242
245
  recipientAddress: string;
243
246
  notes?: string;
@@ -372,10 +375,15 @@ interface Asset {
372
375
  network_id: string;
373
376
  network?: Network;
374
377
  }
378
+ interface AcceptedAsset {
379
+ asset: string;
380
+ network: string;
381
+ }
375
382
  interface CreateCheckoutPayload {
376
383
  price: string;
377
384
  currency: string;
378
- supported_assets: string[];
385
+ supported_assets?: string[];
386
+ accepted_assets?: AcceptedAsset[];
379
387
  underpaid_cover_percent?: number;
380
388
  description?: string;
381
389
  success_url?: string;
@@ -616,13 +624,14 @@ interface CreateWalletPayload {
616
624
  }
617
625
  interface PaymentServiceParams {
618
626
  apiKey: string;
619
- environment: Environment;
627
+ environment?: Environment;
628
+ domain?: string;
620
629
  }
621
630
  declare class APIService {
622
631
  private credentials;
623
632
  Webhook: WebhookService;
624
633
  private API;
625
- constructor(credentials: APICredentials, environment: Environment);
634
+ constructor(credentials: APICredentials, environment?: Environment, domain?: string);
626
635
  getWallets(workspaceId: string): Promise<WalletByWorkspaceResponse[]>;
627
636
  getWalletDetail(addressType?: AddressType, walletId?: string): Promise<WalletDetail>;
628
637
  requestSign(walletId: string, params: SignRequestParams, options?: Record<string, string>): Promise<SignResponse>;
@@ -696,9 +705,11 @@ declare function transformRescanTransactionParams(data: RescanTransactionParams)
696
705
  declare function transformRequestWithdrawalParams(data: RequestWithdrawalParams): {
697
706
  skip_balance_check?: boolean | undefined;
698
707
  notes?: string | undefined;
699
- asset_id: string;
700
708
  amount: string;
701
709
  recipient_address: string;
710
+ asset?: string | undefined;
711
+ network?: string | undefined;
712
+ asset_id?: string | undefined;
702
713
  };
703
714
  declare function transformCreateSweepTaskParams(data: CreateSweepTaskParams): {
704
715
  enabled?: boolean | undefined;
@@ -720,6 +731,7 @@ interface SDKOptions {
720
731
  credentials: APICredentials;
721
732
  workspaceId?: string;
722
733
  environment?: Environment;
734
+ domain?: string;
723
735
  /** Enable debug logging. Defaults to false */
724
736
  debug?: boolean;
725
737
  }
package/dist/index.d.mts CHANGED
@@ -11,7 +11,8 @@ declare enum WalletPurpose {
11
11
  Deployment = "deployment",
12
12
  Custody = "custody",
13
13
  User = "user",
14
- Payment = "payment"
14
+ Payment = "payment",
15
+ OneTimeUse = "one_time_use"
15
16
  }
16
17
  declare enum WalletCreationStatus {
17
18
  Pending = "pending",
@@ -95,7 +96,7 @@ interface APIConfig {
95
96
  baseURL: string;
96
97
  endpoints: APIEndpoints;
97
98
  }
98
- declare const createAPI: (env: Environment) => APIConfig;
99
+ declare const createAPI: (env?: Environment, domain?: string) => APIConfig;
99
100
 
100
101
  declare class TransactionError extends Error {
101
102
  readonly code: string;
@@ -237,7 +238,9 @@ interface WalletByWorkspaceResponse {
237
238
  wallet_purpose: string;
238
239
  }
239
240
  interface RequestWithdrawalParams {
240
- assetId: string;
241
+ assetId?: string;
242
+ network?: string;
243
+ asset?: string;
241
244
  amount: string;
242
245
  recipientAddress: string;
243
246
  notes?: string;
@@ -372,10 +375,15 @@ interface Asset {
372
375
  network_id: string;
373
376
  network?: Network;
374
377
  }
378
+ interface AcceptedAsset {
379
+ asset: string;
380
+ network: string;
381
+ }
375
382
  interface CreateCheckoutPayload {
376
383
  price: string;
377
384
  currency: string;
378
- supported_assets: string[];
385
+ supported_assets?: string[];
386
+ accepted_assets?: AcceptedAsset[];
379
387
  underpaid_cover_percent?: number;
380
388
  description?: string;
381
389
  success_url?: string;
@@ -616,13 +624,14 @@ interface CreateWalletPayload {
616
624
  }
617
625
  interface PaymentServiceParams {
618
626
  apiKey: string;
619
- environment: Environment;
627
+ environment?: Environment;
628
+ domain?: string;
620
629
  }
621
630
  declare class APIService {
622
631
  private credentials;
623
632
  Webhook: WebhookService;
624
633
  private API;
625
- constructor(credentials: APICredentials, environment: Environment);
634
+ constructor(credentials: APICredentials, environment?: Environment, domain?: string);
626
635
  getWallets(workspaceId: string): Promise<WalletByWorkspaceResponse[]>;
627
636
  getWalletDetail(addressType?: AddressType, walletId?: string): Promise<WalletDetail>;
628
637
  requestSign(walletId: string, params: SignRequestParams, options?: Record<string, string>): Promise<SignResponse>;
@@ -696,9 +705,11 @@ declare function transformRescanTransactionParams(data: RescanTransactionParams)
696
705
  declare function transformRequestWithdrawalParams(data: RequestWithdrawalParams): {
697
706
  skip_balance_check?: boolean | undefined;
698
707
  notes?: string | undefined;
699
- asset_id: string;
700
708
  amount: string;
701
709
  recipient_address: string;
710
+ asset?: string | undefined;
711
+ network?: string | undefined;
712
+ asset_id?: string | undefined;
702
713
  };
703
714
  declare function transformCreateSweepTaskParams(data: CreateSweepTaskParams): {
704
715
  enabled?: boolean | undefined;
@@ -720,6 +731,7 @@ interface SDKOptions {
720
731
  credentials: APICredentials;
721
732
  workspaceId?: string;
722
733
  environment?: Environment;
734
+ domain?: string;
723
735
  /** Enable debug logging. Defaults to false */
724
736
  debug?: boolean;
725
737
  }
@@ -11,7 +11,8 @@ declare enum WalletPurpose {
11
11
  Deployment = "deployment",
12
12
  Custody = "custody",
13
13
  User = "user",
14
- Payment = "payment"
14
+ Payment = "payment",
15
+ OneTimeUse = "one_time_use"
15
16
  }
16
17
  declare enum WalletCreationStatus {
17
18
  Pending = "pending",
@@ -95,7 +96,7 @@ interface APIConfig {
95
96
  baseURL: string;
96
97
  endpoints: APIEndpoints;
97
98
  }
98
- declare const createAPI: (env: Environment) => APIConfig;
99
+ declare const createAPI: (env?: Environment, domain?: string) => APIConfig;
99
100
 
100
101
  declare class TransactionError extends Error {
101
102
  readonly code: string;
@@ -237,7 +238,9 @@ interface WalletByWorkspaceResponse {
237
238
  wallet_purpose: string;
238
239
  }
239
240
  interface RequestWithdrawalParams {
240
- assetId: string;
241
+ assetId?: string;
242
+ network?: string;
243
+ asset?: string;
241
244
  amount: string;
242
245
  recipientAddress: string;
243
246
  notes?: string;
@@ -372,10 +375,15 @@ interface Asset {
372
375
  network_id: string;
373
376
  network?: Network;
374
377
  }
378
+ interface AcceptedAsset {
379
+ asset: string;
380
+ network: string;
381
+ }
375
382
  interface CreateCheckoutPayload {
376
383
  price: string;
377
384
  currency: string;
378
- supported_assets: string[];
385
+ supported_assets?: string[];
386
+ accepted_assets?: AcceptedAsset[];
379
387
  underpaid_cover_percent?: number;
380
388
  description?: string;
381
389
  success_url?: string;
@@ -616,13 +624,14 @@ interface CreateWalletPayload {
616
624
  }
617
625
  interface PaymentServiceParams {
618
626
  apiKey: string;
619
- environment: Environment;
627
+ environment?: Environment;
628
+ domain?: string;
620
629
  }
621
630
  declare class APIService {
622
631
  private credentials;
623
632
  Webhook: WebhookService;
624
633
  private API;
625
- constructor(credentials: APICredentials, environment: Environment);
634
+ constructor(credentials: APICredentials, environment?: Environment, domain?: string);
626
635
  getWallets(workspaceId: string): Promise<WalletByWorkspaceResponse[]>;
627
636
  getWalletDetail(addressType?: AddressType, walletId?: string): Promise<WalletDetail>;
628
637
  requestSign(walletId: string, params: SignRequestParams, options?: Record<string, string>): Promise<SignResponse>;
@@ -696,9 +705,11 @@ declare function transformRescanTransactionParams(data: RescanTransactionParams)
696
705
  declare function transformRequestWithdrawalParams(data: RequestWithdrawalParams): {
697
706
  skip_balance_check?: boolean | undefined;
698
707
  notes?: string | undefined;
699
- asset_id: string;
700
708
  amount: string;
701
709
  recipient_address: string;
710
+ asset?: string | undefined;
711
+ network?: string | undefined;
712
+ asset_id?: string | undefined;
702
713
  };
703
714
  declare function transformCreateSweepTaskParams(data: CreateSweepTaskParams): {
704
715
  enabled?: boolean | undefined;
@@ -720,6 +731,7 @@ interface SDKOptions {
720
731
  credentials: APICredentials;
721
732
  workspaceId?: string;
722
733
  environment?: Environment;
734
+ domain?: string;
723
735
  /** Enable debug logging. Defaults to false */
724
736
  debug?: boolean;
725
737
  }
package/dist/index.esm.js CHANGED
@@ -18,11 +18,25 @@ const getBaseURL = (env)=>{
18
18
  case "sandbox":
19
19
  return 'https://api-dev.fystack.io';
20
20
  case "production":
21
- return 'https://fystack.excelon.io';
21
+ return 'https://api.fystack.io';
22
22
  }
23
23
  };
24
- const createAPI = (env)=>{
25
- const baseURL = `${getBaseURL(env)}/api/v1`;
24
+ function validateDomain(domain) {
25
+ const domainPattern = /^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
26
+ if (!domainPattern.test(domain)) {
27
+ throw new Error(`Invalid domain: "${domain}". Expected a valid domain like "api.example.com"`);
28
+ }
29
+ }
30
+ const createAPI = (env, domain)=>{
31
+ let baseURL;
32
+ if (domain) {
33
+ validateDomain(domain);
34
+ baseURL = `https://${domain}/api/v1`;
35
+ } else if (env) {
36
+ baseURL = `${getBaseURL(env)}/api/v1`;
37
+ } else {
38
+ baseURL = `${getBaseURL("production")}/api/v1`;
39
+ }
26
40
  const withBaseURL = (path)=>`${baseURL}${path}`;
27
41
  return {
28
42
  baseURL,
@@ -137,6 +151,7 @@ var WalletPurpose;
137
151
  WalletPurpose["Custody"] = "custody";
138
152
  WalletPurpose["User"] = "user";
139
153
  WalletPurpose["Payment"] = "payment";
154
+ WalletPurpose["OneTimeUse"] = "one_time_use";
140
155
  })(WalletPurpose || (WalletPurpose = {}));
141
156
  var WalletCreationStatus;
142
157
  (function(WalletCreationStatus) {
@@ -348,10 +363,10 @@ class APIService {
348
363
  const response = await post(endpoint, transformedParams, headers);
349
364
  return response.data;
350
365
  }
351
- constructor(credentials, environment){
366
+ constructor(credentials, environment, domain){
352
367
  this.credentials = credentials;
353
368
  this.Webhook = new WebhookService(credentials);
354
- this.API = createAPI(environment);
369
+ this.API = createAPI(environment, domain);
355
370
  }
356
371
  }
357
372
  class PaymentService {
@@ -380,7 +395,7 @@ class PaymentService {
380
395
  }
381
396
  constructor(params){
382
397
  this.apiKey = params.apiKey;
383
- this.API = createAPI(params.environment);
398
+ this.API = createAPI(params.environment, params.domain);
384
399
  }
385
400
  }
386
401
  class WebhookService {
@@ -473,7 +488,15 @@ function transformRescanTransactionParams(data) {
473
488
  }
474
489
  function transformRequestWithdrawalParams(data) {
475
490
  return {
476
- asset_id: data.assetId,
491
+ ...data.assetId !== undefined && {
492
+ asset_id: data.assetId
493
+ },
494
+ ...data.network !== undefined && {
495
+ network: data.network
496
+ },
497
+ ...data.asset !== undefined && {
498
+ asset: data.asset
499
+ },
477
500
  amount: data.amount,
478
501
  recipient_address: data.recipientAddress,
479
502
  ...data.notes !== undefined && {
@@ -682,7 +705,11 @@ class FystackSDK {
682
705
  * @returns Promise with withdrawal response including auto_approved status and withdrawal details
683
706
  */ async requestWithdrawal(walletId, params) {
684
707
  validateUUID(walletId, 'walletId');
685
- validateUUID(params.assetId, 'assetId');
708
+ if (params.assetId) {
709
+ validateUUID(params.assetId, 'assetId');
710
+ } else if (!params.asset || !params.network) {
711
+ throw new Error('Either assetId or both asset and network must be provided');
712
+ }
686
713
  if (!params.amount || params.amount.trim() === '') {
687
714
  throw new Error('Invalid amount provided');
688
715
  }
@@ -723,8 +750,8 @@ class FystackSDK {
723
750
  return this.workspaceId;
724
751
  }
725
752
  constructor(options){
726
- const { credentials, workspaceId, environment = Environment.Production, debug = false } = options;
727
- this.apiService = new APIService(credentials, environment);
753
+ const { credentials, workspaceId, environment = Environment.Production, domain, debug = false } = options;
754
+ this.apiService = new APIService(credentials, environment, domain);
728
755
  this.debugEnabled = debug;
729
756
  this.workspaceId = workspaceId;
730
757
  this.automation = new AutomationNamespace(this);
package/dist/index.mjs CHANGED
@@ -18,11 +18,25 @@ const getBaseURL = (env)=>{
18
18
  case "sandbox":
19
19
  return 'https://api-dev.fystack.io';
20
20
  case "production":
21
- return 'https://fystack.excelon.io';
21
+ return 'https://api.fystack.io';
22
22
  }
23
23
  };
24
- const createAPI = (env)=>{
25
- const baseURL = `${getBaseURL(env)}/api/v1`;
24
+ function validateDomain(domain) {
25
+ const domainPattern = /^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
26
+ if (!domainPattern.test(domain)) {
27
+ throw new Error(`Invalid domain: "${domain}". Expected a valid domain like "api.example.com"`);
28
+ }
29
+ }
30
+ const createAPI = (env, domain)=>{
31
+ let baseURL;
32
+ if (domain) {
33
+ validateDomain(domain);
34
+ baseURL = `https://${domain}/api/v1`;
35
+ } else if (env) {
36
+ baseURL = `${getBaseURL(env)}/api/v1`;
37
+ } else {
38
+ baseURL = `${getBaseURL("production")}/api/v1`;
39
+ }
26
40
  const withBaseURL = (path)=>`${baseURL}${path}`;
27
41
  return {
28
42
  baseURL,
@@ -137,6 +151,7 @@ var WalletPurpose;
137
151
  WalletPurpose["Custody"] = "custody";
138
152
  WalletPurpose["User"] = "user";
139
153
  WalletPurpose["Payment"] = "payment";
154
+ WalletPurpose["OneTimeUse"] = "one_time_use";
140
155
  })(WalletPurpose || (WalletPurpose = {}));
141
156
  var WalletCreationStatus;
142
157
  (function(WalletCreationStatus) {
@@ -348,10 +363,10 @@ class APIService {
348
363
  const response = await post(endpoint, transformedParams, headers);
349
364
  return response.data;
350
365
  }
351
- constructor(credentials, environment){
366
+ constructor(credentials, environment, domain){
352
367
  this.credentials = credentials;
353
368
  this.Webhook = new WebhookService(credentials);
354
- this.API = createAPI(environment);
369
+ this.API = createAPI(environment, domain);
355
370
  }
356
371
  }
357
372
  class PaymentService {
@@ -380,7 +395,7 @@ class PaymentService {
380
395
  }
381
396
  constructor(params){
382
397
  this.apiKey = params.apiKey;
383
- this.API = createAPI(params.environment);
398
+ this.API = createAPI(params.environment, params.domain);
384
399
  }
385
400
  }
386
401
  class WebhookService {
@@ -473,7 +488,15 @@ function transformRescanTransactionParams(data) {
473
488
  }
474
489
  function transformRequestWithdrawalParams(data) {
475
490
  return {
476
- asset_id: data.assetId,
491
+ ...data.assetId !== undefined && {
492
+ asset_id: data.assetId
493
+ },
494
+ ...data.network !== undefined && {
495
+ network: data.network
496
+ },
497
+ ...data.asset !== undefined && {
498
+ asset: data.asset
499
+ },
477
500
  amount: data.amount,
478
501
  recipient_address: data.recipientAddress,
479
502
  ...data.notes !== undefined && {
@@ -682,7 +705,11 @@ class FystackSDK {
682
705
  * @returns Promise with withdrawal response including auto_approved status and withdrawal details
683
706
  */ async requestWithdrawal(walletId, params) {
684
707
  validateUUID(walletId, 'walletId');
685
- validateUUID(params.assetId, 'assetId');
708
+ if (params.assetId) {
709
+ validateUUID(params.assetId, 'assetId');
710
+ } else if (!params.asset || !params.network) {
711
+ throw new Error('Either assetId or both asset and network must be provided');
712
+ }
686
713
  if (!params.amount || params.amount.trim() === '') {
687
714
  throw new Error('Invalid amount provided');
688
715
  }
@@ -723,8 +750,8 @@ class FystackSDK {
723
750
  return this.workspaceId;
724
751
  }
725
752
  constructor(options){
726
- const { credentials, workspaceId, environment = Environment.Production, debug = false } = options;
727
- this.apiService = new APIService(credentials, environment);
753
+ const { credentials, workspaceId, environment = Environment.Production, domain, debug = false } = options;
754
+ this.apiService = new APIService(credentials, environment, domain);
728
755
  this.debugEnabled = debug;
729
756
  this.workspaceId = workspaceId;
730
757
  this.automation = new AutomationNamespace(this);
@@ -11,7 +11,8 @@ declare enum WalletPurpose {
11
11
  Deployment = "deployment",
12
12
  Custody = "custody",
13
13
  User = "user",
14
- Payment = "payment"
14
+ Payment = "payment",
15
+ OneTimeUse = "one_time_use"
15
16
  }
16
17
  declare enum WalletCreationStatus {
17
18
  Pending = "pending",
@@ -95,7 +96,7 @@ interface APIConfig {
95
96
  baseURL: string;
96
97
  endpoints: APIEndpoints;
97
98
  }
98
- declare const createAPI: (env: Environment) => APIConfig;
99
+ declare const createAPI: (env?: Environment, domain?: string) => APIConfig;
99
100
 
100
101
  declare class TransactionError extends Error {
101
102
  readonly code: string;
@@ -237,7 +238,9 @@ interface WalletByWorkspaceResponse {
237
238
  wallet_purpose: string;
238
239
  }
239
240
  interface RequestWithdrawalParams {
240
- assetId: string;
241
+ assetId?: string;
242
+ network?: string;
243
+ asset?: string;
241
244
  amount: string;
242
245
  recipientAddress: string;
243
246
  notes?: string;
@@ -372,10 +375,15 @@ interface Asset {
372
375
  network_id: string;
373
376
  network?: Network;
374
377
  }
378
+ interface AcceptedAsset {
379
+ asset: string;
380
+ network: string;
381
+ }
375
382
  interface CreateCheckoutPayload {
376
383
  price: string;
377
384
  currency: string;
378
- supported_assets: string[];
385
+ supported_assets?: string[];
386
+ accepted_assets?: AcceptedAsset[];
379
387
  underpaid_cover_percent?: number;
380
388
  description?: string;
381
389
  success_url?: string;
@@ -616,13 +624,14 @@ interface CreateWalletPayload {
616
624
  }
617
625
  interface PaymentServiceParams {
618
626
  apiKey: string;
619
- environment: Environment;
627
+ environment?: Environment;
628
+ domain?: string;
620
629
  }
621
630
  declare class APIService {
622
631
  private credentials;
623
632
  Webhook: WebhookService;
624
633
  private API;
625
- constructor(credentials: APICredentials, environment: Environment);
634
+ constructor(credentials: APICredentials, environment?: Environment, domain?: string);
626
635
  getWallets(workspaceId: string): Promise<WalletByWorkspaceResponse[]>;
627
636
  getWalletDetail(addressType?: AddressType, walletId?: string): Promise<WalletDetail>;
628
637
  requestSign(walletId: string, params: SignRequestParams, options?: Record<string, string>): Promise<SignResponse>;
@@ -696,9 +705,11 @@ declare function transformRescanTransactionParams(data: RescanTransactionParams)
696
705
  declare function transformRequestWithdrawalParams(data: RequestWithdrawalParams): {
697
706
  skip_balance_check?: boolean | undefined;
698
707
  notes?: string | undefined;
699
- asset_id: string;
700
708
  amount: string;
701
709
  recipient_address: string;
710
+ asset?: string | undefined;
711
+ network?: string | undefined;
712
+ asset_id?: string | undefined;
702
713
  };
703
714
  declare function transformCreateSweepTaskParams(data: CreateSweepTaskParams): {
704
715
  enabled?: boolean | undefined;
@@ -720,6 +731,7 @@ interface SDKOptions {
720
731
  credentials: APICredentials;
721
732
  workspaceId?: string;
722
733
  environment?: Environment;
734
+ domain?: string;
723
735
  /** Enable debug logging. Defaults to false */
724
736
  debug?: boolean;
725
737
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fystack/sdk",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Wallet SDK",
5
5
  "main": "dist/index.cjs",
6
6
  "types": "dist/types/index.d.ts",
package/readme.md CHANGED
@@ -25,6 +25,26 @@ const sdk = new FystackSDK({
25
25
  })
26
26
  ```
27
27
 
28
+ ### Self-Hosted
29
+
30
+ For customers running their own Fystack instance, provide your custom domain instead of an environment:
31
+
32
+ ```typescript
33
+ import { FystackSDK } from '@fystack/sdk'
34
+
35
+ const sdk = new FystackSDK({
36
+ credentials: {
37
+ apiKey: 'YOUR_API_KEY',
38
+ apiSecret: 'YOUR_API_SECRET'
39
+ },
40
+ workspaceId: 'YOUR_WORKSPACE_ID',
41
+ domain: 'api.your-company.com',
42
+ debug: true
43
+ })
44
+ ```
45
+
46
+ > When `domain` is provided, it takes priority over `environment`. The SDK will connect to `https://<domain>/api/v1`.
47
+
28
48
  ## Create Wallet
29
49
 
30
50
  Fystack supports two wallet types:
@@ -102,11 +122,14 @@ console.log('Tron Address:', tron.address)
102
122
 
103
123
  ## Create Withdrawal
104
124
 
105
- Request a withdrawal from a wallet to an external address.
125
+ Request a withdrawal from a wallet to an external address. You can identify the asset either by `assetId` or by `asset` symbol + `network` code.
126
+
127
+ ### By asset and network (recommended)
106
128
 
107
129
  ```typescript
108
130
  const withdrawal = await sdk.requestWithdrawal('WALLET_ID', {
109
- assetId: 'ASSET_UUID',
131
+ asset: 'ETH',
132
+ network: 'ETHEREUM_MAINNET',
110
133
  amount: '10.5',
111
134
  recipientAddress: '0xRecipientAddress',
112
135
  notes: 'Monthly payout'
@@ -117,6 +140,17 @@ console.log('Withdrawal ID:', withdrawal.withdrawal.id)
117
140
  console.log('Status:', withdrawal.withdrawal.status)
118
141
  ```
119
142
 
143
+ ### By asset ID
144
+
145
+ ```typescript
146
+ const withdrawal = await sdk.requestWithdrawal('WALLET_ID', {
147
+ assetId: 'ASSET_UUID',
148
+ amount: '10.5',
149
+ recipientAddress: '0xRecipientAddress',
150
+ notes: 'Monthly payout'
151
+ })
152
+ ```
153
+
120
154
  ## Create Onchain Transaction
121
155
 
122
156
  Sign and broadcast transactions directly on EVM or Solana networks using the built-in signers.
@@ -226,7 +260,7 @@ const isValid = await apiService.Webhook.verifyEvent(event, signature)
226
260
 
227
261
  ## Payment Processing
228
262
 
229
- Create checkouts and process crypto payments.
263
+ Create checkouts and process crypto payments. You can specify accepted assets using `accepted_assets` (asset symbol + network code) or the legacy `supported_assets` format.
230
264
 
231
265
  ```typescript
232
266
  import { PaymentService, Environment } from '@fystack/sdk'
@@ -239,7 +273,11 @@ const paymentService = new PaymentService({
239
273
  const checkout = await paymentService.createCheckout({
240
274
  price: '10.50',
241
275
  currency: 'USD',
242
- supported_assets: ['SOL:1399811149', 'USDC:1399811149'],
276
+ accepted_assets: [
277
+ { asset: 'SOL', network: 'SOL_MAINNET' },
278
+ { asset: 'ETH', network: 'ETHEREUM_MAINNET' },
279
+ { asset: 'ETH', network: 'BASE_MAINNET' },
280
+ ],
243
281
  description: 'Premium subscription',
244
282
  success_url: 'https://yourapp.com/success',
245
283
  cancel_url: 'https://yourapp.com/cancel',
@@ -249,3 +287,14 @@ const checkout = await paymentService.createCheckout({
249
287
 
250
288
  console.log('Checkout URL:', checkout.id)
251
289
  ```
290
+
291
+ ### Self-Hosted
292
+
293
+ ```typescript
294
+ import { PaymentService } from '@fystack/sdk'
295
+
296
+ const paymentService = new PaymentService({
297
+ apiKey: 'YOUR_API_KEY',
298
+ domain: 'api.your-company.com'
299
+ })
300
+ ```
package/src/api.ts CHANGED
@@ -67,7 +67,8 @@ export interface CreateWalletPayload {
67
67
 
68
68
  export interface PaymentServiceParams {
69
69
  apiKey: string
70
- environment: Environment
70
+ environment?: Environment
71
+ domain?: string
71
72
  }
72
73
 
73
74
  async function composeAPIHeaders(
@@ -115,10 +116,10 @@ export class APIService {
115
116
  public Webhook: WebhookService
116
117
  private API: APIConfig
117
118
 
118
- constructor(credentials: APICredentials, environment: Environment) {
119
+ constructor(credentials: APICredentials, environment?: Environment, domain?: string) {
119
120
  this.credentials = credentials
120
121
  this.Webhook = new WebhookService(credentials)
121
- this.API = createAPI(environment)
122
+ this.API = createAPI(environment, domain)
122
123
  }
123
124
 
124
125
  async getWallets(workspaceId: string): Promise<WalletByWorkspaceResponse[]> {
@@ -285,7 +286,7 @@ export class PaymentService {
285
286
 
286
287
  constructor(params: PaymentServiceParams) {
287
288
  this.apiKey = params.apiKey
288
- this.API = createAPI(params.environment)
289
+ this.API = createAPI(params.environment, params.domain)
289
290
  }
290
291
 
291
292
  async createCheckout(payload: CreateCheckoutPayload): Promise<CreateCheckoutResponse> {
@@ -427,7 +428,9 @@ export function transformRescanTransactionParams(data: RescanTransactionParams)
427
428
 
428
429
  export function transformRequestWithdrawalParams(data: RequestWithdrawalParams) {
429
430
  return {
430
- asset_id: data.assetId,
431
+ ...(data.assetId !== undefined && { asset_id: data.assetId }),
432
+ ...(data.network !== undefined && { network: data.network }),
433
+ ...(data.asset !== undefined && { asset: data.asset }),
431
434
  amount: data.amount,
432
435
  recipient_address: data.recipientAddress,
433
436
  ...(data.notes !== undefined && { notes: data.notes }),
package/src/config.ts CHANGED
@@ -33,7 +33,7 @@ const getBaseURL = (env: Environment): string => {
33
33
  case Environment.Sandbox:
34
34
  return 'https://api-dev.fystack.io'
35
35
  case Environment.Production:
36
- return 'https://fystack.excelon.io'
36
+ return 'https://api.fystack.io'
37
37
  }
38
38
  }
39
39
 
@@ -42,8 +42,23 @@ export interface APIConfig {
42
42
  endpoints: APIEndpoints
43
43
  }
44
44
 
45
- const createAPI = (env: Environment): APIConfig => {
46
- const baseURL = `${getBaseURL(env)}/api/v1`
45
+ function validateDomain(domain: string): void {
46
+ const domainPattern = /^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/
47
+ if (!domainPattern.test(domain)) {
48
+ throw new Error(`Invalid domain: "${domain}". Expected a valid domain like "api.example.com"`)
49
+ }
50
+ }
51
+
52
+ const createAPI = (env?: Environment, domain?: string): APIConfig => {
53
+ let baseURL: string
54
+ if (domain) {
55
+ validateDomain(domain)
56
+ baseURL = `https://${domain}/api/v1`
57
+ } else if (env) {
58
+ baseURL = `${getBaseURL(env)}/api/v1`
59
+ } else {
60
+ baseURL = `${getBaseURL(Environment.Production)}/api/v1`
61
+ }
47
62
 
48
63
  const withBaseURL = (path: string) => `${baseURL}${path}`
49
64
 
package/src/payment.ts CHANGED
@@ -33,10 +33,16 @@ export interface Asset {
33
33
  network_id: string
34
34
  network?: Network
35
35
  }
36
+ export interface AcceptedAsset {
37
+ asset: string
38
+ network: string
39
+ }
40
+
36
41
  export interface CreateCheckoutPayload {
37
42
  price: string
38
43
  currency: string
39
- supported_assets: string[]
44
+ supported_assets?: string[]
45
+ accepted_assets?: AcceptedAsset[]
40
46
  underpaid_cover_percent?: number
41
47
  description?: string
42
48
  success_url?: string
package/src/sdk.ts CHANGED
@@ -23,6 +23,7 @@ export interface SDKOptions {
23
23
  credentials: APICredentials
24
24
  workspaceId?: string
25
25
  environment?: Environment
26
+ domain?: string
26
27
  /** Enable debug logging. Defaults to false */
27
28
  debug?: boolean
28
29
  }
@@ -39,9 +40,10 @@ export class FystackSDK {
39
40
  credentials,
40
41
  workspaceId,
41
42
  environment = Environment.Production,
43
+ domain,
42
44
  debug = false
43
45
  } = options
44
- this.apiService = new APIService(credentials, environment)
46
+ this.apiService = new APIService(credentials, environment, domain)
45
47
  this.debugEnabled = debug
46
48
  this.workspaceId = workspaceId
47
49
  this.automation = new AutomationNamespace(this)
@@ -204,7 +206,11 @@ export class FystackSDK {
204
206
  params: RequestWithdrawalParams
205
207
  ): Promise<RequestWithdrawalResponse> {
206
208
  validateUUID(walletId, 'walletId')
207
- validateUUID(params.assetId, 'assetId')
209
+ if (params.assetId) {
210
+ validateUUID(params.assetId, 'assetId')
211
+ } else if (!params.asset || !params.network) {
212
+ throw new Error('Either assetId or both asset and network must be provided')
213
+ }
208
214
 
209
215
  if (!params.amount || params.amount.trim() === '') {
210
216
  throw new Error('Invalid amount provided')
package/src/types.ts CHANGED
@@ -179,7 +179,9 @@ export interface WalletByWorkspaceResponse {
179
179
  }
180
180
 
181
181
  export interface RequestWithdrawalParams {
182
- assetId: string
182
+ assetId?: string
183
+ network?: string
184
+ asset?: string
183
185
  amount: string
184
186
  recipientAddress: string
185
187
  notes?: string