smspva-sdk 0.0.0-stage → 0.1.0-alpha.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.
- package/LICENSE +21 -0
- package/METHODS.md +76 -0
- package/README.md +129 -2
- package/dist/cjs/contracts.cjs +1800 -0
- package/dist/cjs/contracts.cjs.map +1 -0
- package/dist/cjs/contracts.d.cts +2 -0
- package/dist/cjs/errors.cjs +60 -0
- package/dist/cjs/errors.cjs.map +1 -0
- package/dist/cjs/errors.d.cts +32 -0
- package/dist/cjs/index.cjs +37 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +13 -0
- package/dist/cjs/polling.cjs +40 -0
- package/dist/cjs/polling.cjs.map +1 -0
- package/dist/cjs/polling.d.cts +11 -0
- package/dist/cjs/resources.cjs +195 -0
- package/dist/cjs/resources.cjs.map +1 -0
- package/dist/cjs/resources.d.cts +72 -0
- package/dist/cjs/transport.cjs +148 -0
- package/dist/cjs/transport.cjs.map +1 -0
- package/dist/cjs/transport.d.cts +53 -0
- package/dist/cjs/types.cjs +3 -0
- package/dist/cjs/types.cjs.map +1 -0
- package/dist/cjs/types.d.cts +753 -0
- package/dist/esm/contracts.d.ts +2 -0
- package/dist/esm/contracts.js +1797 -0
- package/dist/esm/contracts.js.map +1 -0
- package/dist/esm/errors.d.ts +32 -0
- package/dist/esm/errors.js +50 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/polling.d.ts +11 -0
- package/dist/esm/polling.js +35 -0
- package/dist/esm/polling.js.map +1 -0
- package/dist/esm/resources.d.ts +72 -0
- package/dist/esm/resources.js +189 -0
- package/dist/esm/resources.js.map +1 -0
- package/dist/esm/transport.d.ts +53 -0
- package/dist/esm/transport.js +143 -0
- package/dist/esm/transport.js.map +1 -0
- package/dist/esm/types.d.ts +753 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +58 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SMSPVA
|
|
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/METHODS.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# SDK method index
|
|
2
|
+
|
|
3
|
+
All six packages cover these same 56 methods. Both Python clients use the Python names. PHP and Java use the JavaScript camelCase method names, with their own resource access syntax. Go capitalizes the first letter (for example, `GetBalance`); C# also appends `Async` (`GetBalanceAsync`). See each package README for request types and working usage. Parameters retain their API spelling.
|
|
4
|
+
|
|
5
|
+
## activation
|
|
6
|
+
|
|
7
|
+
| Python (sync and async) | JavaScript / TypeScript | HTTP |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `client.activation.get_balance` | `client.activation.getBalance` | `GET /activation/balance` |
|
|
10
|
+
| `client.activation.get_user_info` | `client.activation.getUserInfo` | `GET /activation/userinfo` |
|
|
11
|
+
| `client.activation.get_operators` | `client.activation.getOperators` | `GET /activation/operators/{country}` |
|
|
12
|
+
| `client.activation.get_conversions` | `client.activation.getConversions` | `GET /activation/conversions/{service}` |
|
|
13
|
+
| `client.activation.get_message_type_settings` | `client.activation.getMessageTypeSettings` | `GET /activation/countryservicesettings` |
|
|
14
|
+
| `client.activation.get_all_number_counts` | `client.activation.getAllNumberCounts` | `GET /activation/countnumbers` |
|
|
15
|
+
| `client.activation.get_country_number_counts` | `client.activation.getCountryNumberCounts` | `GET /activation/countnumbers/{country}` |
|
|
16
|
+
| `client.activation.get_service_price` | `client.activation.getServicePrice` | `GET /activation/serviceprice/{country}/{service}` |
|
|
17
|
+
| `client.activation.get_country_operator_prices` | `client.activation.getCountryOperatorPrices` | `GET /activation/serviceprice/{country}` |
|
|
18
|
+
| `client.activation.get_service_prices` | `client.activation.getServicePrices` | `GET /activation/serviceprices/{service}` |
|
|
19
|
+
| `client.activation.get_all_service_prices` | `client.activation.getAllServicePrices` | `GET /activation/servicesprices` |
|
|
20
|
+
| `client.activation.get_number` | `client.activation.getNumber` | `GET /activation/number/{country}/{service}` |
|
|
21
|
+
| `client.activation.get_number_by_operator` | `client.activation.getNumberByOperator` | `GET /activation/number/{country}/{service}/{operator}` |
|
|
22
|
+
| `client.activation.receive_sms` | `client.activation.receiveSms` | `GET /activation/sms/{orderid}` |
|
|
23
|
+
| `client.activation.get_orders` | `client.activation.getOrders` | `GET /activation/orders` |
|
|
24
|
+
| `client.activation.get_number_status` | `client.activation.getNumberStatus` | `GET /activation/numberstatus/{number}/{service}` |
|
|
25
|
+
| `client.activation.clear_sms` | `client.activation.clearSms` | `PUT /activation/clearsms/{orderid}` |
|
|
26
|
+
| `client.activation.stop_sms` | `client.activation.stopSms` | `PUT /activation/stopsms/{orderid}` |
|
|
27
|
+
| `client.activation.cancel_order` | `client.activation.cancelOrder` | `PUT /activation/cancelorder/{orderid}` |
|
|
28
|
+
| `client.activation.block_number` | `client.activation.blockNumber` | `PUT /activation/blocknumber/{orderid}` |
|
|
29
|
+
|
|
30
|
+
## rental
|
|
31
|
+
|
|
32
|
+
| Python (sync and async) | JavaScript / TypeScript | HTTP |
|
|
33
|
+
| --- | --- | --- |
|
|
34
|
+
| `client.rental.get_countries` | `client.rental.getCountries` | `GET /api/rent.php?method=getcountries` |
|
|
35
|
+
| `client.rental.get_default_services` | `client.rental.getDefaultServices` | `GET /api/rent.php?method=get_default_services` |
|
|
36
|
+
| `client.rental.get_countries_by_service` | `client.rental.getCountriesByService` | `GET /api/rent.php?method=get_country_by_service` |
|
|
37
|
+
| `client.rental.get_data` | `client.rental.getData` | `GET /api/rent.php?method=getdata` |
|
|
38
|
+
| `client.rental.get_data_with_providers` | `client.rental.getDataWithProviders` | `GET /api/rent.php?method=getdataWithProviders` |
|
|
39
|
+
| `client.rental.get_count` | `client.rental.getCount` | `GET /api/rent.php?method=getcount` |
|
|
40
|
+
| `client.rental.get_count_with_providers` | `client.rental.getCountWithProviders` | `GET /api/rent.php?method=getCountWithProviders` |
|
|
41
|
+
| `client.rental.get_multi_service_count` | `client.rental.getMultiServiceCount` | `GET /api/rent.php?method=get_count_multi` |
|
|
42
|
+
| `client.rental.get_canada_paypal_days` | `client.rental.getCanadaPaypalDays` | `GET /api/rent.php?method=get_days_canada_paypal` |
|
|
43
|
+
| `client.rental.get_minimum_paypal_days` | `client.rental.getMinimumPaypalDays` | `GET /api/rent.php?method=get_min_paypal_days` |
|
|
44
|
+
| `client.rental.create` | `client.rental.create` | `GET /api/rent.php?method=create` |
|
|
45
|
+
| `client.rental.create_multi` | `client.rental.createMulti` | `GET /api/rent.php?method=create_multi` |
|
|
46
|
+
| `client.rental.add_service_to_order` | `client.rental.addServiceToOrder` | `GET /api/rent.php?method=add_service_to_order` |
|
|
47
|
+
| `client.rental.get_orders` | `client.rental.getOrders` | `GET /api/rent.php?method=orders` |
|
|
48
|
+
| `client.rental.activate` | `client.rental.activate` | `GET /api/rent.php?method=activate` |
|
|
49
|
+
| `client.rental.get_sms` | `client.rental.getSms` | `GET /api/rent.php?method=sms` |
|
|
50
|
+
| `client.rental.prolong` | `client.rental.prolong` | `GET /api/rent.php?method=prolong` |
|
|
51
|
+
| `client.rental.prolong_by_days` | `client.rental.prolongByDays` | `GET /api/rent.php?method=prolong_max` |
|
|
52
|
+
| `client.rental.delete_order` | `client.rental.deleteOrder` | `GET /api/rent.php?method=delete` |
|
|
53
|
+
| `client.rental.get_history` | `client.rental.getHistory` | `GET /api/rent.php?method=get_rent_history` |
|
|
54
|
+
| `client.rental.get_restore_cost` | `client.rental.getRestoreCost` | `GET /api/rent.php?method=restore_user_precalc` |
|
|
55
|
+
| `client.rental.restore` | `client.rental.restore` | `GET /api/rent.php?method=restore_user` |
|
|
56
|
+
|
|
57
|
+
## email
|
|
58
|
+
|
|
59
|
+
| Python (sync and async) | JavaScript / TypeScript | HTTP |
|
|
60
|
+
| --- | --- | --- |
|
|
61
|
+
| `client.email.get_providers` | `client.email.getProviders` | `GET /api/rent_email.php?method=get_providers` |
|
|
62
|
+
| `client.email.get_data` | `client.email.getData` | `GET /api/rent_email.php?method=get_data` |
|
|
63
|
+
| `client.email.get_count` | `client.email.getCount` | `GET /api/rent_email.php?method=get_count` |
|
|
64
|
+
| `client.email.create_order` | `client.email.createOrder` | `GET /api/rent_email.php?method=create_order` |
|
|
65
|
+
| `client.email.get_orders` | `client.email.getOrders` | `GET /api/rent_email.php?method=get_orders` |
|
|
66
|
+
| `client.email.get_mails` | `client.email.getMails` | `GET /api/rent_email.php?method=get_mails` |
|
|
67
|
+
| `client.email.get_mail_body` | `client.email.getMailBody` | `GET /api/rent_email.php?method=get_mail_body` |
|
|
68
|
+
| `client.email.buy_alias` | `client.email.buyAlias` | `GET /api/rent_email.php?method=buy_alias` |
|
|
69
|
+
| `client.email.get_mails_by_alias` | `client.email.getMailsByAlias` | `GET /api/rent_email.php?method=get_mails_by_alias` |
|
|
70
|
+
| `client.email.prolong_order` | `client.email.prolongOrder` | `GET /api/rent_email.php?method=prolong_order` |
|
|
71
|
+
| `client.email.cancel_order` | `client.email.cancelOrder` | `GET /api/rent_email.php?method=cancel_order` |
|
|
72
|
+
| `client.email.get_archived_orders` | `client.email.getArchivedOrders` | `GET /api/rent_email.php?method=get_archived_orders` |
|
|
73
|
+
| `client.email.calc_restore_order` | `client.email.calcRestoreOrder` | `GET /api/rent_email.php?method=calc_restore_order` |
|
|
74
|
+
| `client.email.restore_order` | `client.email.restoreOrder` | `GET /api/rent_email.php?method=restore_order` |
|
|
75
|
+
|
|
76
|
+
Activation also provides `wait_for_sms` / `waitForSms`. It polls an existing order until a caller-supplied expiry, without purchasing or cancelling an order.
|
package/README.md
CHANGED
|
@@ -1,3 +1,130 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SMSPVA JavaScript / TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/SMSPVA/smspva-js/actions/workflows/ci.yml) [](LICENSE) 
|
|
4
|
+
|
|
5
|
+
Node.js 22.16+, ESM and CommonJS, with TypeScript declarations. Covers all 56 methods: Activation V2 (20), Rental (22) and Private Email (14). Alternative API is excluded. This is an alpha release. Use the explicit version or the `alpha` tag when installing.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install smspva-sdk@alpha
|
|
11
|
+
# Or pin the first alpha:
|
|
12
|
+
npm install smspva-sdk@0.1.0-alpha.1
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Build and install from source:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
git clone https://github.com/SMSPVA/smspva-js.git
|
|
19
|
+
cd smspva-js
|
|
20
|
+
npm ci
|
|
21
|
+
npm run build
|
|
22
|
+
# In the application that will use the SDK:
|
|
23
|
+
npm install /absolute/path/to/smspva-js
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
import { SMSPVA } from 'smspva-sdk';
|
|
28
|
+
|
|
29
|
+
const client = new SMSPVA({ apiKey: process.env.SMSPVA_API_KEY });
|
|
30
|
+
console.log(await client.activation.getBalance());
|
|
31
|
+
console.log(await client.rental.getCountries());
|
|
32
|
+
console.log(await client.email.getProviders());
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
CommonJS: `const { SMSPVA } = require('smspva-sdk')`. Use the SDK on your server; keep account keys out of browser code. The package has no runtime dependencies and uses Node's native fetch.
|
|
36
|
+
|
|
37
|
+
## Requests and results
|
|
38
|
+
|
|
39
|
+
- Wire methods, parameter names and response values follow the source documentation. Price strings, timestamps and IDs are not converted. Optional source fields remain optional in the generated types.
|
|
40
|
+
- Activation V2 sends the key in the `apikey` header. Rental and Email use query `apikey`. Public methods send no key. Optional-key Rental methods can omit it with a second argument `{ useApiKey: false }`.
|
|
41
|
+
- All documented optional parameters are available, including `partnerkey`, `partner_key`, `provider`, `extend`, pagination and search. Query and path values are encoded. Omitted, undefined or empty Email `pcode` is not sent.
|
|
42
|
+
- `rental.getMultiServiceCount` requires `dtype` and `dcount` explicitly: the docs warn against relying on backend defaults for this method. The wire method stays `get_count_multi`.
|
|
43
|
+
- No request is retried automatically and no redirect is followed. This includes GET operations that create orders, modify state or trigger charges.
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
// No key needed for public reference lists.
|
|
47
|
+
const publicClient = new SMSPVA();
|
|
48
|
+
const providers = await publicClient.email.getProviders();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Paid example (run only when you intend to create a rental):
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { SMSPVA, isNoStock } from 'smspva-sdk';
|
|
55
|
+
|
|
56
|
+
const client = new SMSPVA({ apiKey: process.env.SMSPVA_API_KEY });
|
|
57
|
+
const result = await client.email.createOrder({
|
|
58
|
+
scode: 'CODE_FROM_GET_DATA', dtype: 'week', dcount: 1,
|
|
59
|
+
});
|
|
60
|
+
if (isNoStock(result)) {
|
|
61
|
+
console.log('No mailbox available; refresh counts before trying again.');
|
|
62
|
+
} else {
|
|
63
|
+
console.log(result.data);
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Waiting for SMS
|
|
68
|
+
|
|
69
|
+
`activation.receiveSms({ orderid })` returns the original pending envelope for HTTP 202 / `SMS_NOT_YET_RECEIVED`. Use `isPending(result)` to recognise it. Email creation `status=2` similarly stays an ordinary no-stock result, recognised by `isNoStock`.
|
|
70
|
+
|
|
71
|
+
For repeated waiting requests, calculate an expiry once when your number is created:
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
// numberResult is the successful response from your own getNumber request.
|
|
75
|
+
const expiresAt = Date.now() + numberResult.data.orderExpireIn * 1000;
|
|
76
|
+
const result = await client.activation.waitForSms({
|
|
77
|
+
orderid: numberResult.data.orderId,
|
|
78
|
+
expiresAt,
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The helper polls only Receive SMS. It uses a five-second interval by default and does not allow a shorter one; this is a helper policy, not an API-wide rate limit. It stops at the saved deadline, on terminal API errors, transport failures or cancellation. It never creates or cancels an order for you. Reading a newly received SMS can trigger payment.
|
|
83
|
+
|
|
84
|
+
## Errors, timeouts and cancellation
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
import { ApiError, TransportError } from 'smspva-sdk';
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
console.log(await client.activation.getBalance());
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (error instanceof ApiError) {
|
|
93
|
+
console.error(error.family, error.httpStatus, error.code);
|
|
94
|
+
} else if (error instanceof TransportError) {
|
|
95
|
+
console.error(error.kind, error.outcomeUnknown);
|
|
96
|
+
} else {
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`ApiError.response` retains the original API body. `ProtocolError` means invalid JSON or a missing/invalid status envelope. `RequestTimeoutError` extends `TransportError`; for state-changing operations, `outcomeUnknown` reminds you to check orders before trying again. `PollingTimeoutError` means the saved order deadline passed without a result. Exception messages omit request URLs and keys; redact credentials if your own fetch/logging layer logs query URLs.
|
|
103
|
+
|
|
104
|
+
The default request timeout is 30 seconds, covering fetch and body reading. Set `timeoutMs` in the constructor or a method's second argument. Pass an `AbortSignal` as `{ signal }` to cancel a request or polling. You can inject `fetch` and override `activationBaseUrl`, `rentalBaseUrl`, `emailBaseUrl` for proxies and local testing.
|
|
105
|
+
|
|
106
|
+
All generated request and response types are exported from the package. The complete method index is in `METHODS.md`. The generated source is committed. `npm run build` compiles it without needing the documentation source.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT. See [LICENSE](LICENSE).
|
|
111
|
+
|
|
112
|
+
## Development
|
|
113
|
+
|
|
114
|
+
```sh
|
|
115
|
+
npm ci
|
|
116
|
+
npm run build
|
|
117
|
+
npm test
|
|
118
|
+
npm run test:types
|
|
119
|
+
npm pack
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Tests use synthetic fixtures and local HTTP servers; they do not buy numbers or call the production API.
|
|
123
|
+
|
|
124
|
+
## Documentation
|
|
125
|
+
|
|
126
|
+
[API documentation](https://docs.smspva.com)
|
|
127
|
+
|
|
128
|
+
The new documentation is being prepared in English, Spanish and Chinese. Localized links will be added when it is deployed.
|
|
129
|
+
|
|
130
|
+
The SDK covers Activation V2, Rental and Private Email. Alternative API is not supported.
|