@dime-technology/dime-js-sdk 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dime Technology
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,252 @@
1
+ # Dime Payments JS SDK
2
+
3
+ A typed TypeScript/JavaScript client for the [Dime Payments](https://dimepayments.com) API.
4
+ Works in Node.js 18+ and any modern browser (React, Vue, Next.js, Nuxt, etc.).
5
+
6
+ ```ts
7
+ import { Client } from '@dime-technology/dime-js-sdk'
8
+
9
+ const dime = new Client('your-api-token')
10
+
11
+ const txn = await dime.transactions.chargeCard('000010', {
12
+ amount: '49.99',
13
+ token: 'tok_abc123',
14
+ })
15
+
16
+ console.log(txn.transactionStatus) // "Success"
17
+ ```
18
+
19
+ ## Requirements
20
+
21
+ - Node.js 18+ (native `fetch`) **or** any modern browser
22
+ - A Dime API token (a Laravel Sanctum personal access token). Tokens are minted inside the
23
+ Dime application, not via this SDK, and carry abilities (e.g. `transaction:charge-card-token`,
24
+ `customer:read`) that gate which calls succeed.
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install @dime-technology/dime-js-sdk
30
+ ```
31
+
32
+ ## Configuration
33
+
34
+ The simplest setup needs only a token:
35
+
36
+ ```ts
37
+ const dime = new Client('your-api-token')
38
+ ```
39
+
40
+ Point it at another environment, or use `Config` for full control:
41
+
42
+ ```ts
43
+ import { Client, Config } from '@dime-technology/dime-js-sdk'
44
+
45
+ // Staging environment
46
+ const dime = new Client('your-api-token', 'https://staging.dimepayments.com')
47
+
48
+ // Full control
49
+ const dime = new Client(new Config({
50
+ token: 'your-api-token',
51
+ baseUrl: 'https://app.dimepayments.com',
52
+ timeout: 30, // seconds
53
+ maxRetries: 2, // retries 429 / 5xx / network errors with backoff
54
+ retryBaseDelay: 0.5,
55
+ }))
56
+ ```
57
+
58
+ The SDK sends `Authorization: Bearer <token>` and JSON headers on every request. Transient
59
+ failures (HTTP 429 and 5xx, network errors) are retried with exponential backoff, honoring the
60
+ `Retry-After` header when present.
61
+
62
+ ## Resources
63
+
64
+ Every resource hangs off the client as a property. The merchant `sid` is always passed
65
+ explicitly; remaining fields go in an attributes object (and lookups, where the API expects
66
+ them, in a `filters` object). All amounts are returned as strings to avoid float rounding.
67
+
68
+ | Property | Endpoints |
69
+ | ---------------------------- | ---------------------------------------------------------------- |
70
+ | `dime.transactions` | chargeCard, chargeAch, tokenizeCard, refund, void, show, list |
71
+ | `dime.customers` | list, show, create, update, delete |
72
+ | `dime.paymentMethods` | list, show, create, update, delete |
73
+ | `dime.merchants` | list, show, create, update, getFormLink |
74
+ | `dime.addresses` | list, show, create, update, delete |
75
+ | `dime.deposits` | list, listWithTransactions, show |
76
+ | `dime.recurringPayments` | list, show, create, edit, pause, cancel, activate, delete |
77
+
78
+ ### Transactions
79
+
80
+ ```ts
81
+ // Charge a stored token
82
+ const txn = await dime.transactions.chargeCard('000010', {
83
+ amount: '100.00',
84
+ token: 'tok_abc123',
85
+ email: 'customer@example.com',
86
+ })
87
+
88
+ // Charge raw card details (merchant must be PCI compliant)
89
+ const txn = await dime.transactions.chargeCard('000010', {
90
+ amount: '100.00',
91
+ cardholder_name: 'John Doe',
92
+ card_number: '4111111111111111',
93
+ expiration_date: '01/2027',
94
+ cvv: '123',
95
+ billing_address: { zip: '30009' },
96
+ })
97
+
98
+ // ACH
99
+ const txn = await dime.transactions.chargeAch('000010', {
100
+ routing_number: '123456789',
101
+ account_number: '9876543210',
102
+ account_type: 'Checking',
103
+ account_name: 'John Doe',
104
+ amount: '75.00',
105
+ })
106
+
107
+ // Tokenize without charging
108
+ const { token } = await dime.transactions.tokenizeCard('000010', {
109
+ cardholder_name: 'John Doe',
110
+ card_number: '4111111111111111',
111
+ expiration_date: '01/2027',
112
+ })
113
+
114
+ // Refund / void
115
+ await dime.transactions.refund('000010', { amount: '25.00', transaction_info_id: 123456 })
116
+ await dime.transactions.void('000010', 'CC', 123456)
117
+
118
+ // Read
119
+ const txn = await dime.transactions.show('000010', { transaction_info_id: 123456 })
120
+ ```
121
+
122
+ ### Customers, payment methods, addresses
123
+
124
+ ```ts
125
+ const customer = await dime.customers.create('000010', {
126
+ first_name: 'Jane',
127
+ last_name: 'Doe',
128
+ email: 'jane@example.com',
129
+ })
130
+
131
+ const pm = await dime.paymentMethods.create('000010', {
132
+ uuid: customer.uuid,
133
+ type: 'cc',
134
+ cc_name_on_card: 'Jane Doe',
135
+ cc_number: '4111111111111111',
136
+ cc_expiration_date: '01/2027',
137
+ cc_brand: 'Visa',
138
+ default: true,
139
+ })
140
+
141
+ const address = await dime.addresses.create('000010', customer.uuid!, {
142
+ recipient: 'Jane Doe',
143
+ line_one: '123 Main St',
144
+ city: 'Atlanta',
145
+ state: 'GA',
146
+ zip: '30301',
147
+ })
148
+ ```
149
+
150
+ ### Recurring payments
151
+
152
+ ```ts
153
+ const rp = await dime.recurringPayments.create('000010', {
154
+ name: 'Monthly donation',
155
+ amount: '25.00',
156
+ start_date: '2026-07-01 00:00:00',
157
+ recurrence_schedule: 'Monthly',
158
+ payment_method: pm.id,
159
+ customer_uuid: customer.uuid,
160
+ })
161
+
162
+ await dime.recurringPayments.pause('000010', rp.id!, '2026-09-01 00:00:00')
163
+ await dime.recurringPayments.activate('000010', rp.id!)
164
+ await dime.recurringPayments.cancel('000010', rp.id!)
165
+ ```
166
+
167
+ ## Pagination
168
+
169
+ List endpoints return a `CursorPage`. Iterate one page, walk pages manually, or stream every
170
+ item across all pages with `autoPaging()`:
171
+
172
+ ```ts
173
+ const page = await dime.transactions.list('000010', {
174
+ start_date: '2026-01-01 00:00:00',
175
+ end_date: '2026-01-31 23:59:59',
176
+ })
177
+
178
+ // First page only
179
+ for (const txn of page) {
180
+ console.log(txn.amount)
181
+ }
182
+
183
+ // Next page
184
+ if (page.hasMore()) {
185
+ const next = await page.next()
186
+ }
187
+
188
+ // Every transaction across every page (fetches lazily as you iterate)
189
+ for await (const txn of page.autoPaging()) {
190
+ console.log(txn.transactionNumber)
191
+ }
192
+ ```
193
+
194
+ ## Error handling
195
+
196
+ Every failure throws a `DimeException` subclass. Catch the base type, or a specific one:
197
+
198
+ ```ts
199
+ import {
200
+ DimeException,
201
+ ValidationException,
202
+ RateLimitException,
203
+ } from '@dime-technology/dime-js-sdk'
204
+
205
+ try {
206
+ await dime.transactions.chargeCard('000010', { amount: '0' })
207
+ } catch (e) {
208
+ if (e instanceof ValidationException) {
209
+ e.getErrors() // { 'data.amount': ['must be greater than 0'] }
210
+ e.firstError()
211
+ } else if (e instanceof RateLimitException) {
212
+ const wait = e.getRetryAfter() ?? 1
213
+ await new Promise(r => setTimeout(r, wait * 1000))
214
+ } else if (e instanceof DimeException) {
215
+ e.getStatusCode() // HTTP status
216
+ e.getResponseBody() // decoded API body
217
+ }
218
+ }
219
+ ```
220
+
221
+ | Exception | When |
222
+ | ---------------------------- | ------------------------------------------------------------ |
223
+ | `ValidationException` | HTTP 400/422 with field errors |
224
+ | `AuthenticationException` | HTTP 401 (missing/invalid token) |
225
+ | `PermissionDeniedException` | HTTP 403 (belongs-to-company guard) |
226
+ | `NotFoundException` | HTTP 404 |
227
+ | `RateLimitException` | HTTP 429 (carries `Retry-After`) |
228
+ | `ServerException` | HTTP 5xx |
229
+ | `ConnectionException` | No HTTP response (DNS, timeout, network error) |
230
+ | `ApiException` | Any other non-2xx |
231
+
232
+ ## Notes
233
+
234
+ - **GET requests carry a JSON body.** The Dime API expects read parameters in the request body
235
+ even for `GET` endpoints; the SDK handles this transparently.
236
+ - **No API versioning.** Endpoints live under `/api` with no version prefix.
237
+ - **Browser use:** API tokens should generally not be exposed in browser environments. This SDK
238
+ is designed primarily for server-side use (Node.js, Next.js API routes, etc.).
239
+
240
+ ## Development
241
+
242
+ ```bash
243
+ npm install
244
+ npm test # Vitest
245
+ npm run typecheck # tsc --noEmit
246
+ npm run lint # Prettier check
247
+ npm run build # tsup (ESM + CJS + .d.ts)
248
+ ```
249
+
250
+ ## License
251
+
252
+ MIT. See [LICENSE](LICENSE).