velirapay 0.1.1 → 0.2.1

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 (117) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +700 -51
  3. package/dist/cjs/client.d.ts +1 -1
  4. package/dist/cjs/enums.d.ts +159 -27
  5. package/dist/cjs/enums.js +150 -25
  6. package/dist/cjs/errors.d.ts +10 -1
  7. package/dist/cjs/errors.js +12 -1
  8. package/dist/cjs/http/transport.js +18 -3
  9. package/dist/cjs/index.d.ts +3 -3
  10. package/dist/cjs/index.js +12 -2
  11. package/dist/cjs/page.d.ts +14 -2
  12. package/dist/cjs/page.js +19 -2
  13. package/dist/cjs/params.d.ts +21 -10
  14. package/dist/cjs/resources/account.d.ts +13 -13
  15. package/dist/cjs/resources/account.js +7 -7
  16. package/dist/cjs/resources/activity.d.ts +4 -3
  17. package/dist/cjs/resources/activity.js +1 -1
  18. package/dist/cjs/resources/api-key.d.ts +3 -2
  19. package/dist/cjs/resources/api-resource.d.ts +2 -0
  20. package/dist/cjs/resources/api-resource.js +5 -0
  21. package/dist/cjs/resources/charge.d.ts +7 -3
  22. package/dist/cjs/resources/charge.js +6 -0
  23. package/dist/cjs/resources/coupon.d.ts +2 -1
  24. package/dist/cjs/resources/event.d.ts +3 -3
  25. package/dist/cjs/resources/event.js +1 -1
  26. package/dist/cjs/resources/invoice.d.ts +8 -4
  27. package/dist/cjs/resources/invoice.js +6 -0
  28. package/dist/cjs/resources/member.d.ts +5 -4
  29. package/dist/cjs/resources/member.js +2 -2
  30. package/dist/cjs/resources/overview.d.ts +116 -4
  31. package/dist/cjs/resources/overview.js +76 -3
  32. package/dist/cjs/resources/payment-link.d.ts +3 -3
  33. package/dist/cjs/resources/payout.d.ts +5 -5
  34. package/dist/cjs/resources/payout.js +1 -1
  35. package/dist/cjs/resources/pro-payment.d.ts +3 -2
  36. package/dist/cjs/resources/supported-asset.d.ts +2 -2
  37. package/dist/cjs/resources/webhook-endpoint.d.ts +5 -4
  38. package/dist/cjs/resources/webhook-endpoint.js +3 -2
  39. package/dist/cjs/services/account.js +1 -1
  40. package/dist/cjs/services/api-keys.d.ts +7 -1
  41. package/dist/cjs/services/api-keys.js +7 -1
  42. package/dist/cjs/services/assets.d.ts +3 -4
  43. package/dist/cjs/services/assets.js +3 -2
  44. package/dist/cjs/services/charges.js +3 -3
  45. package/dist/cjs/services/coupons.js +1 -1
  46. package/dist/cjs/services/invoices.js +5 -1
  47. package/dist/cjs/services/members.d.ts +2 -2
  48. package/dist/cjs/services/members.js +2 -2
  49. package/dist/cjs/services/overview.d.ts +1 -1
  50. package/dist/cjs/services/overview.js +3 -2
  51. package/dist/cjs/services/payment-links.js +4 -2
  52. package/dist/cjs/services/payout-addresses.d.ts +9 -4
  53. package/dist/cjs/services/payout-addresses.js +6 -2
  54. package/dist/cjs/services/service.d.ts +8 -3
  55. package/dist/cjs/services/service.js +45 -10
  56. package/dist/cjs/services/webhook-endpoints.d.ts +15 -2
  57. package/dist/cjs/services/webhook-endpoints.js +15 -2
  58. package/dist/cjs/version.d.ts +1 -1
  59. package/dist/cjs/version.js +1 -1
  60. package/dist/esm/client.d.ts +1 -1
  61. package/dist/esm/enums.d.ts +159 -27
  62. package/dist/esm/enums.js +149 -24
  63. package/dist/esm/errors.d.ts +10 -1
  64. package/dist/esm/errors.js +12 -1
  65. package/dist/esm/http/transport.js +18 -3
  66. package/dist/esm/index.d.ts +3 -3
  67. package/dist/esm/index.js +3 -3
  68. package/dist/esm/page.d.ts +14 -2
  69. package/dist/esm/page.js +17 -1
  70. package/dist/esm/params.d.ts +21 -10
  71. package/dist/esm/resources/account.d.ts +13 -13
  72. package/dist/esm/resources/account.js +8 -8
  73. package/dist/esm/resources/activity.d.ts +4 -3
  74. package/dist/esm/resources/activity.js +1 -1
  75. package/dist/esm/resources/api-key.d.ts +3 -2
  76. package/dist/esm/resources/api-resource.d.ts +2 -0
  77. package/dist/esm/resources/api-resource.js +4 -0
  78. package/dist/esm/resources/charge.d.ts +7 -3
  79. package/dist/esm/resources/charge.js +6 -0
  80. package/dist/esm/resources/coupon.d.ts +2 -1
  81. package/dist/esm/resources/event.d.ts +3 -3
  82. package/dist/esm/resources/event.js +1 -1
  83. package/dist/esm/resources/invoice.d.ts +8 -4
  84. package/dist/esm/resources/invoice.js +6 -0
  85. package/dist/esm/resources/member.d.ts +5 -4
  86. package/dist/esm/resources/member.js +2 -2
  87. package/dist/esm/resources/overview.d.ts +116 -4
  88. package/dist/esm/resources/overview.js +77 -4
  89. package/dist/esm/resources/payment-link.d.ts +3 -3
  90. package/dist/esm/resources/payout.d.ts +5 -5
  91. package/dist/esm/resources/payout.js +1 -1
  92. package/dist/esm/resources/pro-payment.d.ts +3 -2
  93. package/dist/esm/resources/supported-asset.d.ts +2 -2
  94. package/dist/esm/resources/webhook-endpoint.d.ts +5 -4
  95. package/dist/esm/resources/webhook-endpoint.js +3 -2
  96. package/dist/esm/services/account.js +2 -2
  97. package/dist/esm/services/api-keys.d.ts +7 -1
  98. package/dist/esm/services/api-keys.js +7 -1
  99. package/dist/esm/services/assets.d.ts +3 -4
  100. package/dist/esm/services/assets.js +3 -2
  101. package/dist/esm/services/charges.js +4 -4
  102. package/dist/esm/services/coupons.js +2 -2
  103. package/dist/esm/services/invoices.js +6 -2
  104. package/dist/esm/services/members.d.ts +2 -2
  105. package/dist/esm/services/members.js +2 -2
  106. package/dist/esm/services/overview.d.ts +1 -1
  107. package/dist/esm/services/overview.js +4 -3
  108. package/dist/esm/services/payment-links.js +5 -3
  109. package/dist/esm/services/payout-addresses.d.ts +9 -4
  110. package/dist/esm/services/payout-addresses.js +6 -2
  111. package/dist/esm/services/service.d.ts +8 -3
  112. package/dist/esm/services/service.js +44 -10
  113. package/dist/esm/services/webhook-endpoints.d.ts +15 -2
  114. package/dist/esm/services/webhook-endpoints.js +15 -2
  115. package/dist/esm/version.d.ts +1 -1
  116. package/dist/esm/version.js +1 -1
  117. package/package.json +12 -2
package/dist/esm/enums.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /** A coin on one particular network, such as USDT on Ethereum or USDT_TRON on Tron. The account lists the ones it accepts right now. */
2
- export const Asset = {
2
+ export const Asset = Object.freeze({
3
3
  BTC: 'BTC',
4
4
  BTC_LIGHTNING: 'BTC_LIGHTNING',
5
5
  LTC: 'LTC',
@@ -23,41 +23,41 @@ export const Asset = {
23
23
  ETH_BASE: 'ETH_BASE',
24
24
  ETH_ARBITRUM: 'ETH_ARBITRUM',
25
25
  POL: 'POL',
26
- };
26
+ });
27
27
  /** The states a charge moves through. */
28
- export const ChargeStatus = {
28
+ export const ChargeStatus = Object.freeze({
29
29
  Pending: 'pending',
30
30
  Underpaid: 'underpaid',
31
31
  Paid: 'paid',
32
32
  Expired: 'expired',
33
33
  Canceled: 'canceled',
34
- };
34
+ });
35
35
  /** The states an invoice moves through. */
36
- export const InvoiceStatus = {
36
+ export const InvoiceStatus = Object.freeze({
37
37
  Open: 'open',
38
38
  Paid: 'paid',
39
39
  Void: 'void',
40
- };
40
+ });
41
41
  /** Where a payout has got to. */
42
- export const PayoutStatus = {
42
+ export const PayoutStatus = Object.freeze({
43
43
  Pending: 'pending',
44
44
  Sending: 'sending',
45
45
  Sent: 'sent',
46
46
  Failed: 'failed',
47
47
  Manual: 'manual',
48
- };
48
+ });
49
49
  /** Whether a payment link takes payments. */
50
- export const PaymentLinkStatus = {
50
+ export const PaymentLinkStatus = Object.freeze({
51
51
  Active: 'active',
52
52
  Archived: 'archived',
53
- };
53
+ });
54
54
  /** How a payment link is priced: at a set amount, or at one the customer names. */
55
- export const PricingType = {
55
+ export const PricingType = Object.freeze({
56
56
  Fixed: 'fixed',
57
57
  Open: 'open',
58
- };
58
+ });
59
59
  /** The events a charge, an invoice or a payout reports, through webhooks and the events API. */
60
- export const EventType = {
60
+ export const EventType = Object.freeze({
61
61
  ChargeCreated: 'charge.created',
62
62
  ChargePaymentDetected: 'charge.payment_detected',
63
63
  ChargePaid: 'charge.paid',
@@ -73,20 +73,20 @@ export const EventType = {
73
73
  InvoiceVoided: 'invoice.voided',
74
74
  PayoutSent: 'payout.sent',
75
75
  PayoutConfirmed: 'payout.confirmed',
76
- };
76
+ });
77
77
  /** The mode an API key, object or webhook belongs to. */
78
- export const Mode = {
78
+ export const Mode = Object.freeze({
79
79
  Live: 'live',
80
80
  Test: 'test',
81
- };
81
+ });
82
82
  /** What kind of legal entity runs an account. */
83
- export const BusinessType = {
83
+ export const BusinessType = Object.freeze({
84
84
  Individual: 'individual',
85
85
  Company: 'company',
86
86
  NonProfit: 'non_profit',
87
- };
87
+ });
88
88
  /** What an account sells, broadly. */
89
- export const Industry = {
89
+ export const Industry = Object.freeze({
90
90
  DigitalProducts: 'digital_products',
91
91
  Software: 'software',
92
92
  Hosting: 'hosting',
@@ -99,17 +99,17 @@ export const Industry = {
99
99
  Travel: 'travel',
100
100
  Donations: 'donations',
101
101
  Other: 'other',
102
- };
102
+ });
103
103
  /** How much an account expects to take in a month, in US dollars. */
104
- export const MonthlyVolume = {
104
+ export const MonthlyVolume = Object.freeze({
105
105
  Under1k: 'under_1k',
106
106
  Under10k: '1k_10k',
107
107
  Under50k: '10k_50k',
108
108
  Under250k: '50k_250k',
109
109
  Over250k: 'over_250k',
110
- };
110
+ });
111
111
  /** What a restricted API key may do. Full access gives every permission but the sensitive ones, which have to be ticked. */
112
- export const ApiKeyPermission = {
112
+ export const ApiKeyPermission = Object.freeze({
113
113
  ChargesRead: 'charges:read',
114
114
  ChargesWrite: 'charges:write',
115
115
  ChargesAccept: 'charges:accept',
@@ -135,4 +135,129 @@ export const ApiKeyPermission = {
135
135
  MembersRead: 'members:read',
136
136
  MembersWrite: 'members:write',
137
137
  BillingWrite: 'billing:write',
138
- };
138
+ });
139
+ /** The fiat currencies prices can be set in. */
140
+ export const Currency = Object.freeze({
141
+ USD: 'USD',
142
+ EUR: 'EUR',
143
+ GBP: 'GBP',
144
+ CAD: 'CAD',
145
+ AUD: 'AUD',
146
+ CHF: 'CHF',
147
+ TRY: 'TRY',
148
+ });
149
+ /** The roles people have in an account. Owner only appears in answers: invitations and role changes take the others. */
150
+ export const MemberRole = Object.freeze({
151
+ Owner: 'owner',
152
+ Admin: 'admin',
153
+ Finance: 'finance',
154
+ Support: 'support',
155
+ Viewer: 'viewer',
156
+ });
157
+ /** The network families that each have one payout address, as payoutAddresses.update() and delete() name them. */
158
+ export const AddressNetwork = Object.freeze({
159
+ Bitcoin: 'bitcoin',
160
+ Litecoin: 'litecoin',
161
+ Dogecoin: 'dogecoin',
162
+ BitcoinCash: 'bitcoincash',
163
+ Evm: 'evm',
164
+ Bsc: 'bsc',
165
+ Base: 'base',
166
+ Arbitrum: 'arbitrum',
167
+ Polygon: 'polygon',
168
+ Tron: 'tron',
169
+ Monero: 'monero',
170
+ Solana: 'solana',
171
+ Lightning: 'lightning',
172
+ });
173
+ /** How the checkout looks: following the customer's device, or always light or dark. */
174
+ export const CheckoutAppearance = Object.freeze({
175
+ Auto: 'auto',
176
+ Light: 'light',
177
+ Dark: 'dark',
178
+ });
179
+ /** Where a webhook delivery has got to. */
180
+ export const WebhookDeliveryStatus = Object.freeze({
181
+ Pending: 'pending',
182
+ Succeeded: 'succeeded',
183
+ Failed: 'failed',
184
+ });
185
+ /** The plans an account can be on: Free keeps a fee of every payment, Pro keeps none. */
186
+ export const PlanName = Object.freeze({
187
+ Free: 'free',
188
+ Pro: 'pro',
189
+ });
190
+ /** Whether an account is one person's or an organization's. */
191
+ export const AccountType = Object.freeze({
192
+ Personal: 'personal',
193
+ Organization: 'organization',
194
+ });
195
+ /** The languages the checkout can fall back on when the customer's browser asks for none of them. */
196
+ export const CheckoutLocale = Object.freeze({
197
+ English: 'en',
198
+ French: 'fr',
199
+ German: 'de',
200
+ Spanish: 'es',
201
+ Turkish: 'tr',
202
+ Portuguese: 'pt',
203
+ Russian: 'ru',
204
+ Arabic: 'ar',
205
+ });
206
+ /** What the activity log records. The API adds actions from time to time, so expect others too. */
207
+ export const ActivityAction = Object.freeze({
208
+ WalletsChanged: 'wallets.changed',
209
+ PayoutAddressAccessChanged: 'wallets.api_access_changed',
210
+ SecondFactorRequirementChanged: 'team.second_factor_requirement_changed',
211
+ PaymentSettingsUpdated: 'payment_settings.updated',
212
+ ProfileUpdated: 'profile.updated',
213
+ BusinessDetailsUpdated: 'business_details.updated',
214
+ ApiKeyCreated: 'api_key.created',
215
+ ApiKeyUpdated: 'api_key.updated',
216
+ ApiKeyRevoked: 'api_key.revoked',
217
+ WebhookCreated: 'webhook.created',
218
+ WebhookUpdated: 'webhook.updated',
219
+ WebhookDeleted: 'webhook.deleted',
220
+ WebhookSecretRotated: 'webhook.secret_rotated',
221
+ MemberInvited: 'member.invited',
222
+ MemberJoined: 'member.joined',
223
+ MemberRoleChanged: 'member.role_changed',
224
+ MemberRemoved: 'member.removed',
225
+ PaymentLinkCreated: 'payment_link.created',
226
+ PaymentLinkUpdated: 'payment_link.updated',
227
+ PaymentLinkArchived: 'payment_link.archived',
228
+ PaymentLinkRestored: 'payment_link.restored',
229
+ InvitationCanceled: 'member.invitation_canceled',
230
+ ChargePaymentRequested: 'charge.payment_requested',
231
+ WebhookDisabled: 'webhook.disabled',
232
+ ChargeCanceled: 'charge.canceled',
233
+ ChargeAccepted: 'charge.accepted',
234
+ RefundRecorded: 'refund.recorded',
235
+ InvoiceVoided: 'invoice.voided',
236
+ PlanPaymentStarted: 'plan.payment_started',
237
+ SubscriptionCanceled: 'plan.subscription_canceled',
238
+ SubscriptionResumed: 'plan.subscription_resumed',
239
+ SignedIn: 'auth.signed_in',
240
+ SignInFailed: 'auth.sign_in_failed',
241
+ PasswordChanged: 'auth.password_changed',
242
+ TwoFactorEnabled: 'auth.two_factor_enabled',
243
+ TwoFactorDisabled: 'auth.two_factor_disabled',
244
+ SignedOutElsewhere: 'auth.signed_out_elsewhere',
245
+ TwoFactorFailed: 'auth.two_factor_failed',
246
+ EmailChanged: 'auth.email_changed',
247
+ PasskeyAdded: 'auth.passkey_added',
248
+ PasskeyRemoved: 'auth.passkey_removed',
249
+ CouponCreated: 'coupon.created',
250
+ CouponUpdated: 'coupon.updated',
251
+ CouponDeleted: 'coupon.deleted',
252
+ AppConnected: 'auth.app_connected',
253
+ AppDisconnected: 'auth.app_disconnected',
254
+ ChatConnected: 'chat.connected',
255
+ ChatUpdated: 'chat.updated',
256
+ ChatRemoved: 'chat.removed',
257
+ ChatDisabled: 'chat.disabled',
258
+ SanctionsMatched: 'sanctions.matched',
259
+ SanctionsAccepted: 'sanctions.accepted',
260
+ SanctionsReturnRequested: 'sanctions.return_requested',
261
+ SocialAccountConnected: 'auth.social_connected',
262
+ SocialAccountDisconnected: 'auth.social_disconnected',
263
+ });
@@ -28,8 +28,17 @@ export declare class PermissionError extends ApiError {
28
28
  /** The object does not exist for this account and mode (404). */
29
29
  export declare class NotFoundError extends ApiError {
30
30
  }
31
- /** The object's state does not allow the action, or an idempotency key was reused for a different request or is held by one still being processed (409). */
31
+ /**
32
+ * The object's state does not allow the action, or an idempotency key was reused for a different request, is held by one
33
+ * still being processed, or belongs to a request that succeeded but whose answer carried a secret, which wasReplayed() tells (409).
34
+ */
32
35
  export declare class ConflictError extends ApiError {
36
+ /**
37
+ * Whether the API answered from an earlier request with the same idempotency key that succeeded: one that made an API key or
38
+ * a webhook endpoint, or rotated an endpoint's signing secret, whose answer is never kept because it carried the key or
39
+ * secret. The library's own retry after a lost answer gets this too. The write was carried out, but its key or secret cannot be shown again.
40
+ */
41
+ wasReplayed(): boolean;
33
42
  }
34
43
  /** The request failed validation (422). */
35
44
  export declare class ValidationError extends ApiError {
@@ -58,8 +58,19 @@ export class PermissionError extends ApiError {
58
58
  /** The object does not exist for this account and mode (404). */
59
59
  export class NotFoundError extends ApiError {
60
60
  }
61
- /** The object's state does not allow the action, or an idempotency key was reused for a different request or is held by one still being processed (409). */
61
+ /**
62
+ * The object's state does not allow the action, or an idempotency key was reused for a different request, is held by one
63
+ * still being processed, or belongs to a request that succeeded but whose answer carried a secret, which wasReplayed() tells (409).
64
+ */
62
65
  export class ConflictError extends ApiError {
66
+ /**
67
+ * Whether the API answered from an earlier request with the same idempotency key that succeeded: one that made an API key or
68
+ * a webhook endpoint, or rotated an endpoint's signing secret, whose answer is never kept because it carried the key or
69
+ * secret. The library's own retry after a lost answer gets this too. The write was carried out, but its key or secret cannot be shown again.
70
+ */
71
+ wasReplayed() {
72
+ return this.response.wasReplayed();
73
+ }
63
74
  }
64
75
  /** The request failed validation (422). */
65
76
  export class ValidationError extends ApiError {
@@ -1,8 +1,10 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { ApiError, ConnectionError, InvalidArgumentError } from '../errors.js';
3
3
  import { ApiResponse } from './api-response.js';
4
- /** The statuses worth another attempt for any request. */
5
- const RETRYABLE_STATUSES = [429, 502, 503, 504];
4
+ /** The statuses worth another attempt for any request, Cloudflare's 520 to 524 for an origin it got no answer from included. */
5
+ const RETRYABLE_STATUSES = [429, 502, 503, 504, 520, 521, 522, 523, 524];
6
+ /** The codes Node gives a connection that could not be made or was cut off, which a fetch implementation may throw as they are. */
7
+ const NETWORK_ERROR_CODES = ['ECONNRESET', 'ECONNREFUSED', 'ETIMEDOUT', 'EPIPE', 'EAI_AGAIN', 'ENOTFOUND', 'EHOSTUNREACH', 'ENETUNREACH'];
6
8
  /** Sends requests to the VeliraPay API and turns its answers into responses or errors. */
7
9
  export class HttpTransport {
8
10
  #options;
@@ -15,6 +17,9 @@ export class HttpTransport {
15
17
  /** Send a request and return the successful response. */
16
18
  async request(method, path, query = {}, body, idempotencyKey) {
17
19
  method = method.toUpperCase();
20
+ if (typeof idempotencyKey === 'string' && idempotencyKey.trim() === '') {
21
+ throw new InvalidArgumentError('An idempotency key cannot be blank: give one such as order-1042-attempt-1, or leave it out.');
22
+ }
18
23
  // A retried write must not be carried out twice, so every attempt carries the same key.
19
24
  if (method !== 'GET' && idempotencyKey === undefined && this.#options.maxRetries > 0) {
20
25
  idempotencyKey = randomUUID();
@@ -128,7 +133,17 @@ export class HttpTransport {
128
133
  }
129
134
  /** Whether fetch failed to reach the API, or to read its answer, rather than the code calling it failing. */
130
135
  function isNetworkError(error) {
131
- return error instanceof TypeError || (error instanceof Error && (error.name === 'TimeoutError' || error.name === 'AbortError'));
136
+ if (error instanceof TypeError) {
137
+ return true;
138
+ }
139
+ if (!(error instanceof Error)) {
140
+ return false;
141
+ }
142
+ // node-fetch reports a connection or a body read that failed as a FetchError of the "system" type.
143
+ if (error.name === 'TimeoutError' || error.name === 'AbortError' || (error.name === 'FetchError' && 'type' in error && error.type === 'system')) {
144
+ return true;
145
+ }
146
+ return 'code' in error && typeof error.code === 'string' && NETWORK_ERROR_CODES.includes(error.code);
132
147
  }
133
148
  /** The wait before an attempt, in seconds: half a second, doubling each time, with some jitter. */
134
149
  function backoff(attempt) {
@@ -1,10 +1,10 @@
1
1
  export { VeliraPayClient, type ClientOptions } from './client.ts';
2
2
  export { VERSION } from './version.ts';
3
- export { ApiKeyPermission, Asset, BusinessType, ChargeStatus, EventType, Industry, InvoiceStatus, Mode, MonthlyVolume, PaymentLinkStatus, PayoutStatus, PricingType, type Currency, type MemberRole, type OrString, } from './enums.ts';
3
+ export { AccountType, ActivityAction, AddressNetwork, ApiKeyPermission, Asset, BusinessType, ChargeStatus, CheckoutAppearance, CheckoutLocale, Currency, EventType, Industry, InvoiceStatus, MemberRole, Mode, MonthlyVolume, PaymentLinkStatus, PayoutStatus, PlanName, PricingType, WebhookDeliveryStatus, type AssignableMemberRole, type OrString, } from './enums.ts';
4
4
  export { ApiError, AuthenticationError, ConflictError, ConnectionError, InvalidArgumentError, InvalidRequestError, NotFoundError, PermissionError, RateLimitError, ServerError, SignatureVerificationError, UnexpectedResponseError, ValidationError, VeliraPayError, } from './errors.ts';
5
5
  export { ApiResponse } from './http/api-response.ts';
6
6
  export type { Fetch } from './http/transport.ts';
7
- export { Page, type PagePosition } from './page.ts';
7
+ export { AssetPage, Page, type PagePosition } from './page.ts';
8
8
  export type * from './params.ts';
9
9
  export { Account, AccountBusiness, Address, type AccountCheckout, type AccountInvoices } from './resources/account.ts';
10
10
  export { Activity } from './resources/activity.ts';
@@ -15,7 +15,7 @@ export { Coupon } from './resources/coupon.ts';
15
15
  export { Event } from './resources/event.ts';
16
16
  export { Invoice, InvoiceItem, type InvoiceCharge } from './resources/invoice.ts';
17
17
  export { Invitation, Member } from './resources/member.ts';
18
- export { Overview } from './resources/overview.ts';
18
+ export { Overview, type OverviewAsset, type OverviewAttention, type OverviewChargeAmount, type OverviewDay, type OverviewFunnel, type OverviewFunnelAsset, type OverviewPaymentLink, type OverviewPeriod, type OverviewSetup, type OverviewWaitingPayouts, } from './resources/overview.ts';
19
19
  export { PaymentLink, type CheckoutQuestion } from './resources/payment-link.ts';
20
20
  export { Payout, PayoutAddress, PayoutSummary } from './resources/payout.ts';
21
21
  export { ProPayment } from './resources/pro-payment.ts';
package/dist/esm/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  export { VeliraPayClient } from './client.js';
2
2
  export { VERSION } from './version.js';
3
- export { ApiKeyPermission, Asset, BusinessType, ChargeStatus, EventType, Industry, InvoiceStatus, Mode, MonthlyVolume, PaymentLinkStatus, PayoutStatus, PricingType, } from './enums.js';
3
+ export { AccountType, ActivityAction, AddressNetwork, ApiKeyPermission, Asset, BusinessType, ChargeStatus, CheckoutAppearance, CheckoutLocale, Currency, EventType, Industry, InvoiceStatus, MemberRole, Mode, MonthlyVolume, PaymentLinkStatus, PayoutStatus, PlanName, PricingType, WebhookDeliveryStatus, } from './enums.js';
4
4
  export { ApiError, AuthenticationError, ConflictError, ConnectionError, InvalidArgumentError, InvalidRequestError, NotFoundError, PermissionError, RateLimitError, ServerError, SignatureVerificationError, UnexpectedResponseError, ValidationError, VeliraPayError, } from './errors.js';
5
5
  export { ApiResponse } from './http/api-response.js';
6
- export { Page } from './page.js';
6
+ export { AssetPage, Page } from './page.js';
7
7
  export { Account, AccountBusiness, Address } from './resources/account.js';
8
8
  export { Activity } from './resources/activity.js';
9
9
  export { ApiKey } from './resources/api-key.js';
@@ -13,7 +13,7 @@ export { Coupon } from './resources/coupon.js';
13
13
  export { Event } from './resources/event.js';
14
14
  export { Invoice, InvoiceItem } from './resources/invoice.js';
15
15
  export { Invitation, Member } from './resources/member.js';
16
- export { Overview } from './resources/overview.js';
16
+ export { Overview, } from './resources/overview.js';
17
17
  export { PaymentLink } from './resources/payment-link.js';
18
18
  export { Payout, PayoutAddress, PayoutSummary } from './resources/payout.js';
19
19
  export { ProPayment } from './resources/pro-payment.js';
@@ -1,4 +1,6 @@
1
- import type { ApiResource } from './resources/api-resource.ts';
1
+ import type { Currency, Mode, OrString } from './enums.ts';
2
+ import { type ApiResource, type Attributes } from './resources/api-resource.ts';
3
+ import type { SupportedAsset } from './resources/supported-asset.ts';
2
4
  /** Where a page sits in its list. */
3
5
  export interface PagePosition {
4
6
  currentPage: number;
@@ -19,7 +21,11 @@ export declare class Page<T extends ApiResource> implements Iterable<T> {
19
21
  readonly perPage: number;
20
22
  /** How many objects the whole list holds. */
21
23
  readonly total: number;
22
- constructor(data: T[], position: PagePosition, fetch: (page: number) => Promise<Page<T>>);
24
+ /** What the answer said about the list besides its objects, as the API sent it: its position, and anything else, such as its mode. */
25
+ readonly meta: Attributes;
26
+ /** The mode the list is in, for the lists whose answer says it, such as the coins on offer and the activity log; null for the others. */
27
+ readonly mode: OrString<Mode> | null;
28
+ constructor(data: T[], position: PagePosition, fetch: (page: number) => Promise<Page<T>>, meta?: Attributes);
23
29
  /** Whether there are pages after this one. */
24
30
  hasMore(): boolean;
25
31
  /** Fetch the next page, or null when this is the last. */
@@ -31,3 +37,9 @@ export declare class Page<T extends ApiResource> implements Iterable<T> {
31
37
  /** Whether this page holds no objects. */
32
38
  isEmpty(): boolean;
33
39
  }
40
+ /** The coins on offer, which assets.list() answers with in a single page, with the currencies their prices can be asked in. */
41
+ export declare class AssetPage extends Page<SupportedAsset> {
42
+ /** The currencies assets.list() can give prices in, which its currency parameter takes. */
43
+ readonly currencies: OrString<Currency>[];
44
+ constructor(data: SupportedAsset[], position: PagePosition, fetch: (page: number) => Promise<Page<SupportedAsset>>, meta?: Attributes);
45
+ }
package/dist/esm/page.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { nullableString, strings } from './resources/api-resource.js';
1
2
  /** One page of a list, able to fetch the pages after it. */
2
3
  export class Page {
3
4
  /** The objects on this page. */
@@ -10,13 +11,19 @@ export class Page {
10
11
  perPage;
11
12
  /** How many objects the whole list holds. */
12
13
  total;
14
+ /** What the answer said about the list besides its objects, as the API sent it: its position, and anything else, such as its mode. */
15
+ meta;
16
+ /** The mode the list is in, for the lists whose answer says it, such as the coins on offer and the activity log; null for the others. */
17
+ mode;
13
18
  #fetch;
14
- constructor(data, position, fetch) {
19
+ constructor(data, position, fetch, meta = {}) {
15
20
  this.data = data;
16
21
  this.currentPage = position.currentPage;
17
22
  this.lastPage = position.lastPage;
18
23
  this.perPage = position.perPage;
19
24
  this.total = position.total;
25
+ this.meta = meta;
26
+ this.mode = nullableString(meta, 'mode');
20
27
  this.#fetch = fetch;
21
28
  }
22
29
  /** Whether there are pages after this one. */
@@ -59,3 +66,12 @@ export class Page {
59
66
  return this.data.length === 0;
60
67
  }
61
68
  }
69
+ /** The coins on offer, which assets.list() answers with in a single page, with the currencies their prices can be asked in. */
70
+ export class AssetPage extends Page {
71
+ /** The currencies assets.list() can give prices in, which its currency parameter takes. */
72
+ currencies;
73
+ constructor(data, position, fetch, meta = {}) {
74
+ super(data, position, fetch, meta);
75
+ this.currencies = strings(meta, 'currencies');
76
+ }
77
+ }
@@ -1,11 +1,18 @@
1
- import type { ApiKeyPermission, Asset, BusinessType, ChargeStatus, Currency, EventType, Industry, InvoiceStatus, MemberRole, Mode, MonthlyVolume, OrString, PaymentLinkStatus, PayoutStatus, PricingType } from './enums.ts';
2
- /** An amount of money or of a coin. Pass a string, such as "49.90", to keep every decimal. */
1
+ import type { ActivityAction, ApiKeyPermission, Asset, AssignableMemberRole, BusinessType, ChargeStatus, CheckoutAppearance, CheckoutLocale, Currency, EventType, Industry, InvoiceStatus, Mode, MonthlyVolume, OrString, PaymentLinkStatus, PayoutStatus, PricingType, WebhookDeliveryStatus } from './enums.ts';
2
+ /** An amount of money or of a coin. Pass a string, such as "49.90", to keep every decimal: a number is rounded to 14 significant digits. */
3
3
  export type Amount = string | number;
4
4
  /** Your own key-value data: up to 20 keys of at most 40 characters, each a string of at most 500 characters, a number, a boolean or null. */
5
5
  export type Metadata = Record<string, string | number | boolean | null>;
6
6
  /** Options for a request that changes something. */
7
7
  export interface RequestOptions {
8
- /** Up to 255 characters, such as an order number. For 24 hours, a repeat with the same key gets the first successful response instead of being carried out again. */
8
+ /**
9
+ * Up to 255 characters and not blank, such as "order-1042-attempt-1". For 24 hours, a repeat with the same key gets the first successful response
10
+ * instead of being carried out again. Reuse a key only to retry the same request: a new attempt, such as a charge replacing one
11
+ * that expired, needs a new key, or it gets the old charge back, and a different body under the same key throws a ConflictError.
12
+ * The answers that carry a new API key or webhook signing secret are the exception: they are never kept, so a repeat of
13
+ * apiKeys.create(), webhookEndpoints.create() or rotateSecret() throws a ConflictError whose wasReplayed() is true, meaning the
14
+ * first one succeeded.
15
+ */
9
16
  idempotencyKey?: string;
10
17
  }
11
18
  /** Which page of a list to fetch. */
@@ -86,6 +93,10 @@ export interface InvoiceCreateParams {
86
93
  memo?: string | null;
87
94
  /** The day it is due, as YYYY-MM-DD. */
88
95
  due_at?: string | null;
96
+ /** A public https:// address the customer is offered a button back to once they have paid. */
97
+ success_url?: string | null;
98
+ /** A public https:// address the customer can go back to from the invoice without paying. */
99
+ cancel_url?: string | null;
89
100
  send_email?: boolean;
90
101
  }
91
102
  export interface InvoiceListParams extends PageParams {
@@ -172,7 +183,7 @@ export interface WebhookEndpointCreateParams {
172
183
  }
173
184
  export type WebhookEndpointUpdateParams = Partial<WebhookEndpointCreateParams>;
174
185
  export interface WebhookDeliveryListParams extends PageParams {
175
- status?: OrString<'pending' | 'succeeded' | 'failed'>;
186
+ status?: OrString<WebhookDeliveryStatus>;
176
187
  event?: OrString<EventType>;
177
188
  }
178
189
  export interface ApiKeyCreateParams {
@@ -184,15 +195,15 @@ export interface ApiKeyCreateParams {
184
195
  }
185
196
  export type ApiKeyUpdateParams = Partial<ApiKeyCreateParams>;
186
197
  export interface MemberUpdateParams {
187
- role: OrString<MemberRole>;
198
+ role: OrString<AssignableMemberRole>;
188
199
  }
189
200
  export interface InvitationCreateParams {
190
201
  email: string;
191
- role: OrString<MemberRole>;
202
+ role: OrString<AssignableMemberRole>;
192
203
  }
193
204
  export interface ActivityListParams extends PageParams {
194
- /** An action, or "sensitive". */
195
- action?: string;
205
+ /** An action, or "sensitive" for those that touch money or access. */
206
+ action?: OrString<ActivityAction | 'sensitive'>;
196
207
  person?: string;
197
208
  /** A subject or the start of an IP address. */
198
209
  q?: string;
@@ -223,7 +234,7 @@ export interface AccountUpdateParams {
223
234
  refund_policy_url?: string | null;
224
235
  brand_color?: string | null;
225
236
  checkout?: {
226
- appearance?: OrString<'auto' | 'light' | 'dark'>;
237
+ appearance?: OrString<CheckoutAppearance>;
227
238
  coin_order?: OrString<Asset>[];
228
239
  default_coin?: OrString<Asset> | null;
229
240
  success_url?: string | null;
@@ -259,6 +270,6 @@ export interface PaymentSettingsUpdateParams {
259
270
  default_currency?: OrString<Currency>;
260
271
  underpayment_tolerance?: Amount;
261
272
  overpayment_threshold?: Amount;
262
- checkout_locale?: OrString<'en' | 'fr' | 'de' | 'es' | 'tr' | 'pt' | 'ru' | 'ar'> | null;
273
+ checkout_locale?: OrString<CheckoutLocale> | null;
263
274
  invoice_reminders?: boolean;
264
275
  }
@@ -1,13 +1,13 @@
1
- import { BusinessType, Industry, Mode, MonthlyVolume, type OrString } from '../enums.ts';
1
+ import { AccountType, BusinessType, CheckoutAppearance, Industry, Mode, MonthlyVolume, PlanName, type Asset, type CheckoutLocale, type Currency, type OrString } from '../enums.ts';
2
2
  import { ApiResource, type Attributes } from './api-resource.ts';
3
3
  /** How the account's checkout looks and what it falls back on. */
4
4
  export interface AccountCheckout {
5
- /** "auto", "light" or "dark". */
6
- appearance: string;
5
+ /** One of the CheckoutAppearance values: auto, light or dark. */
6
+ appearance: OrString<CheckoutAppearance>;
7
7
  /** The order coins are listed in. */
8
- coinOrder: string[];
8
+ coinOrder: OrString<Asset>[];
9
9
  /** The coin the checkout starts on, or null when the merchant has not picked one. */
10
- defaultCoin: string | null;
10
+ defaultCoin: OrString<Asset> | null;
11
11
  successUrl: string | null;
12
12
  cancelUrl: string | null;
13
13
  successMessage: string | null;
@@ -23,8 +23,8 @@ export interface AccountInvoices {
23
23
  export declare class Account extends ApiResource {
24
24
  /** The account's slug. */
25
25
  readonly id: string;
26
- /** Either "personal" or "organization". */
27
- readonly type: string;
26
+ /** One of the AccountType values: personal or organization. */
27
+ readonly type: OrString<AccountType>;
28
28
  /** The account's name. */
29
29
  readonly name: string;
30
30
  /** The name customers see. */
@@ -48,13 +48,13 @@ export declare class Account extends ApiResource {
48
48
  /** Who runs the account and what it sells; every field is null until it is filled in, and for a key without the sensitive account:write permission. */
49
49
  readonly business: AccountBusiness;
50
50
  /** The currency new links and reports default to. */
51
- readonly defaultCurrency: string;
51
+ readonly defaultCurrency: OrString<Currency>;
52
52
  /** How far short of the amount due, in percent, still counts as paid. */
53
53
  readonly underpaymentTolerance: string;
54
54
  /** How much surplus, in percent, is ignored before a charge is flagged as overpaid. */
55
55
  readonly overpaymentThreshold: string;
56
- /** "free" or "pro". */
57
- readonly plan: string;
56
+ /** One of the PlanName values: free or pro. */
57
+ readonly plan: OrString<PlanName>;
58
58
  /** The share of each payment kept as the platform's fee, in percent. */
59
59
  readonly feePercent: string;
60
60
  /** When Pro ends, or null while it renews, has no end or the account is on the free plan. */
@@ -63,8 +63,8 @@ export declare class Account extends ApiResource {
63
63
  readonly checkout: AccountCheckout | null;
64
64
  /** The invoice numbering, footer and business details settings. */
65
65
  readonly invoices: AccountInvoices | null;
66
- /** The fallback checkout language, or null for English. */
67
- readonly checkoutLocale: string | null;
66
+ /** The checkout's fallback language, one of the CheckoutLocale values, or null for English. */
67
+ readonly checkoutLocale: OrString<CheckoutLocale> | null;
68
68
  /** Whether automatic invoice reminders are enabled. */
69
69
  readonly invoiceReminders: boolean;
70
70
  /** Whether the owner allows API keys and AI apps to change payout addresses. */
@@ -74,7 +74,7 @@ export declare class Account extends ApiResource {
74
74
  /** The mode of the API key that fetched the account: "live" or "test". */
75
75
  readonly mode: OrString<Mode> | null;
76
76
  /** The coins the account can be paid in right now, in that mode. */
77
- readonly acceptedAssets: string[];
77
+ readonly acceptedAssets: OrString<Asset>[];
78
78
  constructor(attributes: Attributes, meta?: Attributes);
79
79
  /** Whether the account is on Pro, which keeps no fee. */
80
80
  isPro(): boolean;
@@ -1,10 +1,10 @@
1
- import { BusinessType, Industry, Mode, MonthlyVolume } from '../enums.js';
1
+ import { AccountType, BusinessType, CheckoutAppearance, Industry, Mode, MonthlyVolume, PlanName, } from '../enums.js';
2
2
  import { ApiResource, bool, date, isRecord, map, nullableString, oneOf, string, strings } from './api-resource.js';
3
3
  /** The account an API key belongs to: a personal account or an organization. */
4
4
  export class Account extends ApiResource {
5
5
  /** The account's slug. */
6
6
  id;
7
- /** Either "personal" or "organization". */
7
+ /** One of the AccountType values: personal or organization. */
8
8
  type;
9
9
  /** The account's name. */
10
10
  name;
@@ -34,7 +34,7 @@ export class Account extends ApiResource {
34
34
  underpaymentTolerance;
35
35
  /** How much surplus, in percent, is ignored before a charge is flagged as overpaid. */
36
36
  overpaymentThreshold;
37
- /** "free" or "pro". */
37
+ /** One of the PlanName values: free or pro. */
38
38
  plan;
39
39
  /** The share of each payment kept as the platform's fee, in percent. */
40
40
  feePercent;
@@ -44,7 +44,7 @@ export class Account extends ApiResource {
44
44
  checkout;
45
45
  /** The invoice numbering, footer and business details settings. */
46
46
  invoices;
47
- /** The fallback checkout language, or null for English. */
47
+ /** The checkout's fallback language, one of the CheckoutLocale values, or null for English. */
48
48
  checkoutLocale;
49
49
  /** Whether automatic invoice reminders are enabled. */
50
50
  invoiceReminders;
@@ -77,11 +77,11 @@ export class Account extends ApiResource {
77
77
  this.defaultCurrency = string(attributes, 'default_currency');
78
78
  this.underpaymentTolerance = string(attributes, 'underpayment_tolerance', '0');
79
79
  this.overpaymentThreshold = string(attributes, 'overpayment_threshold', '0');
80
- this.plan = string(plan, 'name', 'free');
80
+ this.plan = string(plan, 'name', PlanName.Free);
81
81
  this.feePercent = string(plan, 'fee_percent', '0');
82
82
  this.proEndsAt = date(plan, 'pro_ends_at');
83
83
  this.checkout = isRecord(checkout) ? {
84
- appearance: string(checkout, 'appearance', 'auto'),
84
+ appearance: string(checkout, 'appearance', CheckoutAppearance.Auto),
85
85
  coinOrder: strings(checkout, 'coin_order'),
86
86
  defaultCoin: nullableString(checkout, 'default_coin'),
87
87
  successUrl: nullableString(checkout, 'success_url'),
@@ -103,11 +103,11 @@ export class Account extends ApiResource {
103
103
  }
104
104
  /** Whether the account is on Pro, which keeps no fee. */
105
105
  isPro() {
106
- return this.plan === 'pro';
106
+ return this.plan === PlanName.Pro;
107
107
  }
108
108
  /** Whether this is an organization rather than a personal account. */
109
109
  isOrganization() {
110
- return this.type === 'organization';
110
+ return this.type === AccountType.Organization;
111
111
  }
112
112
  /** Whether the key that fetched the account works in test mode. */
113
113
  isTestMode() {