zyropai 1.0.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.
Files changed (110) hide show
  1. package/.eslintrc.json +16 -0
  2. package/.github/workflows/ci.yml +26 -0
  3. package/.github/workflows/publish.yml +52 -0
  4. package/.prettierrc +7 -0
  5. package/LICENSE +0 -0
  6. package/README.md +0 -0
  7. package/dist/client.d.ts +42 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +175 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/errors.d.ts +32 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +71 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/index.d.ts +7 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +24 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/resources/base.d.ts +14 -0
  20. package/dist/resources/base.d.ts.map +1 -0
  21. package/dist/resources/base.js +29 -0
  22. package/dist/resources/base.js.map +1 -0
  23. package/dist/resources/currencies.d.ts +16 -0
  24. package/dist/resources/currencies.d.ts.map +1 -0
  25. package/dist/resources/currencies.js +38 -0
  26. package/dist/resources/currencies.js.map +1 -0
  27. package/dist/resources/custody.d.ts +50 -0
  28. package/dist/resources/custody.d.ts.map +1 -0
  29. package/dist/resources/custody.js +42 -0
  30. package/dist/resources/custody.js.map +1 -0
  31. package/dist/resources/donations.d.ts +44 -0
  32. package/dist/resources/donations.d.ts.map +1 -0
  33. package/dist/resources/donations.js +50 -0
  34. package/dist/resources/donations.js.map +1 -0
  35. package/dist/resources/index.d.ts +2 -0
  36. package/dist/resources/index.d.ts.map +1 -0
  37. package/dist/resources/index.js +3 -0
  38. package/dist/resources/index.js.map +1 -0
  39. package/dist/resources/invoices.d.ts +15 -0
  40. package/dist/resources/invoices.d.ts.map +1 -0
  41. package/dist/resources/invoices.js +34 -0
  42. package/dist/resources/invoices.js.map +1 -0
  43. package/dist/resources/network.d.ts +21 -0
  44. package/dist/resources/network.d.ts.map +1 -0
  45. package/dist/resources/network.js +18 -0
  46. package/dist/resources/network.js.map +1 -0
  47. package/dist/resources/payments.d.ts +24 -0
  48. package/dist/resources/payments.d.ts.map +1 -0
  49. package/dist/resources/payments.js +50 -0
  50. package/dist/resources/payments.js.map +1 -0
  51. package/dist/resources/payouts.d.ts +102 -0
  52. package/dist/resources/payouts.d.ts.map +1 -0
  53. package/dist/resources/payouts.js +52 -0
  54. package/dist/resources/payouts.js.map +1 -0
  55. package/dist/resources/pos.d.ts +71 -0
  56. package/dist/resources/pos.d.ts.map +1 -0
  57. package/dist/resources/pos.js +26 -0
  58. package/dist/resources/pos.js.map +1 -0
  59. package/dist/resources/rates.d.ts +26 -0
  60. package/dist/resources/rates.d.ts.map +1 -0
  61. package/dist/resources/rates.js +29 -0
  62. package/dist/resources/rates.js.map +1 -0
  63. package/dist/resources/status.d.ts +22 -0
  64. package/dist/resources/status.d.ts.map +1 -0
  65. package/dist/resources/status.js +17 -0
  66. package/dist/resources/status.js.map +1 -0
  67. package/dist/resources/timezones.d.ts +26 -0
  68. package/dist/resources/timezones.d.ts.map +1 -0
  69. package/dist/resources/timezones.js +20 -0
  70. package/dist/resources/timezones.js.map +1 -0
  71. package/dist/resources/webhooks.d.ts +8 -0
  72. package/dist/resources/webhooks.d.ts.map +1 -0
  73. package/dist/resources/webhooks.js +30 -0
  74. package/dist/resources/webhooks.js.map +1 -0
  75. package/dist/types.d.ts +72 -0
  76. package/dist/types.d.ts.map +1 -0
  77. package/dist/types.js +6 -0
  78. package/dist/types.js.map +1 -0
  79. package/dist/utils/helpers.d.ts +2 -0
  80. package/dist/utils/helpers.d.ts.map +1 -0
  81. package/dist/utils/helpers.js +3 -0
  82. package/dist/utils/helpers.js.map +1 -0
  83. package/examples/mass-payout.js +0 -0
  84. package/examples/quickstart.js +0 -0
  85. package/examples/webhook-server.js +0 -0
  86. package/jest.config.js +19 -0
  87. package/package.json +55 -0
  88. package/src/client.ts +167 -0
  89. package/src/errors.ts +74 -0
  90. package/src/index.ts +8 -0
  91. package/src/resources/base.ts +33 -0
  92. package/src/resources/currencies.ts +39 -0
  93. package/src/resources/custody.ts +82 -0
  94. package/src/resources/donations.ts +84 -0
  95. package/src/resources/index.ts +0 -0
  96. package/src/resources/invoices.ts +35 -0
  97. package/src/resources/network.ts +26 -0
  98. package/src/resources/payments.ts +50 -0
  99. package/src/resources/payouts.ts +136 -0
  100. package/src/resources/pos.ts +90 -0
  101. package/src/resources/rates.ts +36 -0
  102. package/src/resources/status.ts +30 -0
  103. package/src/resources/timezones.ts +38 -0
  104. package/src/resources/webhooks.ts +28 -0
  105. package/src/types.ts +79 -0
  106. package/src/utils/helpers.ts +0 -0
  107. package/tests/unit/client.test.ts +0 -0
  108. package/tests/unit/payments.test.ts +0 -0
  109. package/tests/unit/webhooks.test.ts +0 -0
  110. package/tsconfig.json +21 -0
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Mass Payouts resource
3
+ */
4
+
5
+ import { APIResource } from './base';
6
+
7
+ export interface BatchPayoutParams {
8
+ withdrawals: Array<{
9
+ address: string;
10
+ amount: number;
11
+ currency: string;
12
+ extra_id?: string;
13
+ payout_description?: string;
14
+ }>;
15
+ verification_code?: string;
16
+ schedule_for?: string;
17
+ schedule_timezone?: string;
18
+ is_recurring?: boolean;
19
+ recurring_config?: {
20
+ type: 'daily' | 'weekly' | 'monthly' | 'yearly' | 'custom';
21
+ interval_days?: number;
22
+ day_of_week?: number;
23
+ day_of_month?: number;
24
+ end_date?: string;
25
+ max_occurrences?: number;
26
+ };
27
+ ipn_callback_url?: string;
28
+ }
29
+
30
+ export interface BatchResponse {
31
+ id: string;
32
+ batch_id: string;
33
+ total_amount: number;
34
+ total_withdrawals: number;
35
+ currency: string;
36
+ status: string;
37
+ requires_verification: boolean;
38
+ verification_attempts_remaining: number;
39
+ expires_at: string;
40
+ created_at: string;
41
+ scheduled_for: string | null;
42
+ }
43
+
44
+ export interface BatchStatusResponse {
45
+ batch_id: string;
46
+ batch_withdrawal_id: string;
47
+ status: string;
48
+ total_amount: string;
49
+ currency: string;
50
+ total_withdrawals: number;
51
+ processed: number;
52
+ successful: number;
53
+ failed: number;
54
+ pending: number;
55
+ created_at: string;
56
+ updated_at: string;
57
+ scheduled_for: string | null;
58
+ payouts: Array<{
59
+ id: string;
60
+ address: string;
61
+ currency: string;
62
+ amount: string;
63
+ status: string;
64
+ hash?: string;
65
+ error?: string;
66
+ created_at: string;
67
+ }>;
68
+ }
69
+
70
+ export class PayoutsResource extends APIResource {
71
+ async createBatch(params: BatchPayoutParams): Promise<BatchResponse> {
72
+ const data: Record<string, any> = {
73
+ withdrawals: params.withdrawals,
74
+ };
75
+
76
+ if (params.verification_code) data.verification_code = params.verification_code;
77
+ if (params.schedule_for) data.schedule_for = params.schedule_for;
78
+ if (params.schedule_timezone) data.schedule_timezone = params.schedule_timezone;
79
+ if (params.is_recurring) data.is_recurring = params.is_recurring;
80
+ if (params.recurring_config) data.recurring_config = params.recurring_config;
81
+ if (params.ipn_callback_url) data.ipn_callback_url = params.ipn_callback_url;
82
+
83
+ return this.request('POST', '/payout/batch', data);
84
+ }
85
+
86
+ async getBatchStatus(batchId: string): Promise<BatchStatusResponse> {
87
+ return this.request('GET', `/payout/batch/${batchId}/status`);
88
+ }
89
+
90
+ async listBatchPayouts(
91
+ batchId: string,
92
+ params?: { limit?: number; offset?: number }
93
+ ): Promise<{
94
+ batch_id: string;
95
+ total: number;
96
+ limit: number;
97
+ offset: number;
98
+ payouts: Array<{
99
+ id: string;
100
+ address: string;
101
+ amount: string;
102
+ currency: string;
103
+ status: string;
104
+ tx_hash?: string;
105
+ created_at: string;
106
+ }>;
107
+ }> {
108
+ const queryParams = new URLSearchParams();
109
+ if (params?.limit) queryParams.append('limit', String(params.limit));
110
+ if (params?.offset) queryParams.append('offset', String(params.offset));
111
+
112
+ const path = `/payout/batch/${batchId}/payouts${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
113
+ return this.request('GET', path);
114
+ }
115
+
116
+ async verifyBatch(batchId: string, verificationCode: string): Promise<{
117
+ success: boolean;
118
+ message: string;
119
+ batch_id: string;
120
+ status: string;
121
+ scheduled_for?: string;
122
+ }> {
123
+ return this.request('POST', `/payout/batch/${batchId}/verify`, {
124
+ verification_code: verificationCode,
125
+ });
126
+ }
127
+
128
+ async cancelBatch(batchId: string): Promise<{ success: boolean; message: string }> {
129
+ return this.request('POST', `/payout/batch/${batchId}/cancel`);
130
+ }
131
+
132
+ async cancelPayout(payoutId: string): Promise<{ success: boolean; message: string }> {
133
+ return this.request('POST', `/payout/${payoutId}/cancel`);
134
+ }
135
+ }
136
+
@@ -0,0 +1,90 @@
1
+ /**
2
+ * POS Terminal resource
3
+ */
4
+
5
+ import { APIResource } from './base';
6
+
7
+ export interface POSMerchantResponse {
8
+ success: boolean;
9
+ merchant: {
10
+ username: string;
11
+ business_name: string;
12
+ name: string;
13
+ avatar?: string;
14
+ description?: string;
15
+ };
16
+ settings: {
17
+ theme: string;
18
+ enabled_currencies: string[];
19
+ };
20
+ currencies: Array<{
21
+ id: string;
22
+ symbol: string;
23
+ name: string;
24
+ network: string;
25
+ icon: string;
26
+ min_amount: number;
27
+ is_enabled: boolean;
28
+ decimals: number;
29
+ }>;
30
+ default_currency: string;
31
+ }
32
+
33
+ export interface POSPaymentResponse {
34
+ payment_id: string;
35
+ payment_status: string;
36
+ pay_address: string;
37
+ price_amount: number;
38
+ price_currency: string;
39
+ pay_amount: number | null;
40
+ pay_currency: string;
41
+ created_at: string;
42
+ expires_at: string;
43
+ invoice_url: string;
44
+ platform_fee_amount: number;
45
+ platform_fee_currency: string;
46
+ net_amount: number | null;
47
+ }
48
+
49
+ export interface POSPaymentStatusResponse {
50
+ payment_id: string;
51
+ payment_status: string;
52
+ pay_address: string;
53
+ price_amount: number;
54
+ price_currency: string;
55
+ pay_amount: number | null;
56
+ pay_currency: string;
57
+ actually_paid: number;
58
+ tx_signature?: string;
59
+ created_at: string;
60
+ confirmed_at?: string;
61
+ expires_at: string;
62
+ platform_fee_amount: number;
63
+ platform_fee_currency: string;
64
+ }
65
+
66
+ export class POSResource extends APIResource {
67
+ async getMerchant(username: string): Promise<POSMerchantResponse> {
68
+ return this.request('GET', `/pos-terminal/${username}`);
69
+ }
70
+
71
+ async createPayment(params: {
72
+ username: string;
73
+ price_amount: number;
74
+ price_currency?: string;
75
+ pay_currency?: string;
76
+ }): Promise<POSPaymentResponse> {
77
+ const data = {
78
+ username: params.username,
79
+ price_amount: params.price_amount,
80
+ price_currency: params.price_currency || 'USD',
81
+ pay_currency: params.pay_currency || 'SOL',
82
+ };
83
+ return this.request('POST', '/pos-terminal/payment', data);
84
+ }
85
+
86
+ async getPaymentStatus(paymentId: string): Promise<POSPaymentStatusResponse> {
87
+ return this.request('GET', `/pos-terminal/payment/${paymentId}/status`);
88
+ }
89
+ }
90
+
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Rates resource
3
+ */
4
+
5
+ import { APIResource } from './base';
6
+
7
+ export class RatesResource extends APIResource {
8
+ async getAll(): Promise<Record<string, number>> {
9
+ return this.request('GET', '/rates');
10
+ }
11
+
12
+ async getEstimate(params: {
13
+ amount: number;
14
+ currency_from?: string;
15
+ currency_to?: string;
16
+ }): Promise<{ estimated_amount: number; currency_from: string; currency_to: string }> {
17
+ const queryParams = new URLSearchParams({
18
+ amount: String(params.amount),
19
+ currency_from: params.currency_from || 'USD',
20
+ currency_to: params.currency_to || 'USDT',
21
+ });
22
+ return this.request('GET', `/estimate?${queryParams.toString()}`);
23
+ }
24
+
25
+ async getMinimumAmount(params?: {
26
+ currency_from?: string;
27
+ currency_to?: string;
28
+ }): Promise<{ currency_from: string; currency_to: string; min_amount: number; fiat_equivalent: number }> {
29
+ const queryParams = new URLSearchParams({
30
+ currency_from: params?.currency_from || 'USD',
31
+ currency_to: params?.currency_to || 'USDT',
32
+ });
33
+ return this.request('GET', `/estimate/min-amount?${queryParams.toString()}`);
34
+ }
35
+ }
36
+
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Status resource
3
+ */
4
+
5
+ import { APIResource } from './base';
6
+
7
+ export interface APIStatusResponse {
8
+ message: string;
9
+ }
10
+
11
+ export interface RabbitMQStatusResponse {
12
+ connected: boolean;
13
+ channel: boolean;
14
+ consumer_tag: string | null;
15
+ rabbitmq_url: string;
16
+ queue_exists?: boolean;
17
+ queue_messages?: number;
18
+ queue_consumers?: number;
19
+ queue_error?: string;
20
+ }
21
+
22
+ export class StatusResource extends APIResource {
23
+ async getAPIStatus(): Promise<APIStatusResponse> {
24
+ return this.request('GET', '/status');
25
+ }
26
+
27
+ async getRabbitMQStatus(): Promise<RabbitMQStatusResponse> {
28
+ return this.request('GET', '/status/rabbitmq/status');
29
+ }
30
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Timezones resource
3
+ */
4
+
5
+ import { APIResource } from './base';
6
+
7
+ export interface Timezone {
8
+ value: string;
9
+ label: string;
10
+ offset: string;
11
+ full_name: string;
12
+ }
13
+
14
+ export interface TimezonesResponse {
15
+ timezones: Timezone[];
16
+ total: number;
17
+ default: string;
18
+ }
19
+
20
+ export interface SearchTimezonesResponse {
21
+ timezones: Timezone[];
22
+ total: number;
23
+ query: string;
24
+ }
25
+
26
+ export class TimezonesResource extends APIResource {
27
+ async getCommon(): Promise<TimezonesResponse> {
28
+ return this.request('GET', '/timezones/common');
29
+ }
30
+
31
+ async getAll(): Promise<TimezonesResponse> {
32
+ return this.request('GET', '/timezones/all');
33
+ }
34
+
35
+ async search(query: string): Promise<SearchTimezonesResponse> {
36
+ return this.request('GET', `/timezones/search?q=${encodeURIComponent(query)}`);
37
+ }
38
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Webhooks resource
3
+ */
4
+
5
+ import crypto from 'crypto';
6
+ import { APIResource } from './base';
7
+ import { WebhookSignatureError } from '../errors';
8
+
9
+ export class WebhooksResource extends APIResource {
10
+ verify(payload: any, signature: string, secret: string): any {
11
+ // Sort keys alphabetically
12
+ const sortedPayload = JSON.stringify(payload, Object.keys(payload).sort());
13
+
14
+ // Generate expected signature
15
+ const expected = crypto
16
+ .createHmac('sha256', secret)
17
+ .update(sortedPayload)
18
+ .digest('hex');
19
+
20
+ // Constant-time comparison
21
+ if (!crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature))) {
22
+ throw new WebhookSignatureError('Invalid webhook signature');
23
+ }
24
+
25
+ return payload;
26
+ }
27
+ }
28
+
package/src/types.ts ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Type definitions for ZyroPAI SDK
3
+ */
4
+
5
+ export interface ZyroPAIConfig {
6
+ apiKey?: string;
7
+ mode?: 'test' | 'live';
8
+ baseUrl?: string;
9
+ timeout?: number;
10
+ maxRetries?: number;
11
+ }
12
+
13
+ export interface PaymentCreateParams {
14
+ price_amount: number;
15
+ price_currency?: string;
16
+ pay_currency?: string;
17
+ order_id?: string;
18
+ order_description?: string;
19
+ customer_email?: string;
20
+ ipn_callback_url?: string;
21
+ success_url?: string;
22
+ cancel_url?: string;
23
+ metadata?: Record<string, any>;
24
+ }
25
+
26
+ export interface PaymentResponse {
27
+ payment_id: string;
28
+ payment_status: string;
29
+ pay_address: string;
30
+ price_amount: number;
31
+ price_currency: string;
32
+ pay_amount: number | null;
33
+ pay_currency: string;
34
+ created_at: string;
35
+ expires_at: string;
36
+ invoice_url: string;
37
+ platform_fee_amount?: number;
38
+ platform_fee_currency?: string;
39
+ net_amount?: number;
40
+ platform_fee_percentage?: number;
41
+ }
42
+
43
+ export interface InvoiceCreateParams {
44
+ price_amount: number;
45
+ price_currency?: string;
46
+ pay_currency?: string;
47
+ order_id?: string;
48
+ order_description?: string;
49
+ customer_email?: string;
50
+ success_url?: string;
51
+ cancel_url?: string;
52
+ metadata?: Record<string, any>;
53
+ }
54
+
55
+ export interface InvoiceResponse {
56
+ invoice_id: string;
57
+ invoice_url: string;
58
+ payment_id: string;
59
+ payment_status: string;
60
+ price_amount: number;
61
+ price_currency: string;
62
+ pay_amount: number | null;
63
+ pay_currency: string;
64
+ created_at: string;
65
+ expires_at: string;
66
+ }
67
+
68
+ export interface CurrenciesListParams {
69
+ include_rates?: boolean;
70
+ include_networks?: boolean;
71
+ }
72
+
73
+ export interface WithdrawalCreateParams {
74
+ amount: number;
75
+ currency: string;
76
+ address: string;
77
+ network?: string;
78
+ }
79
+
File without changes
File without changes
File without changes
File without changes
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "nodenext",
5
+ "moduleResolution": "nodenext",
6
+ "lib": ["ES2022"],
7
+ "declaration": true,
8
+ "declarationMap": true,
9
+ "sourceMap": true,
10
+ "outDir": "./dist",
11
+ "rootDir": "./src",
12
+ "strict": true,
13
+ "esModuleInterop": true,
14
+ "skipLibCheck": true,
15
+ "forceConsistentCasingInFileNames": true,
16
+ "resolveJsonModule": true,
17
+ "types": ["node", "jest"]
18
+ },
19
+ "include": ["src/**/*"],
20
+ "exclude": ["node_modules", "tests", "dist", "examples"]
21
+ }