@cosmoner/sdk 1.22.1 → 1.23.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/README.md CHANGED
@@ -68,7 +68,8 @@ jitter, honouring `Retry-After` when the API sends it.
68
68
  so replaying it cannot duplicate a side effect.
69
69
  - **Timeouts and 5xx** are retried only for idempotent methods. A write such as
70
70
  `email.send` is *not* replayed, because the API may have completed the send
71
- before failing to answer.
71
+ before failing to answer. `sms.send` is the exception: the API collapses a
72
+ repeated idempotency key, so it is retried (see [SMS](#sms)).
72
73
 
73
74
  Set `maxRetries: 0` to disable retries entirely.
74
75
 
@@ -116,6 +117,58 @@ Sending a template needs an API key with `email-templates:read` as well as
116
117
  the variables do not match what the template declares or rendering hits a
117
118
  limit, and 503 when the template is briefly unavailable.
118
119
 
120
+ ## SMS
121
+
122
+ Text messages sent from a project's prepaid balance, under a sender name the
123
+ project has had approved.
124
+
125
+ ```typescript
126
+ const { data } = await client.sms.send({
127
+ from: "Acme",
128
+ to: "+46701234567",
129
+ message: "Your order has shipped.",
130
+ idempotencyKey: `order-${orderId}-shipped`,
131
+ });
132
+
133
+ console.log(data.message.status, data.balance);
134
+ ```
135
+
136
+ | Method | Description |
137
+ | --- | --- |
138
+ | `account()` | Balance, auto top-up, daily part limit and usage, and the price of a part per destination |
139
+ | `send({ from, to, message, idempotencyKey? })` | Sends one SMS; `to` is E.164. Longer texts go as up to six parts, each charged |
140
+ | `listMessages({ limit?, cursor? })`, `getMessage(messageId)` | The message log, newest first, with each message's delivery `status` |
141
+ | `listSenders()` | The project's sender names, at every stage of review |
142
+ | `createSender({ name, purpose })` | Asks for a sender name; only an `APPROVED` one can send |
143
+ | `requestSenderReview(senderId, { message })` | Asks a person to review a name that was rejected automatically |
144
+ | `deleteSender(senderId)` | Removes a pending or approved name; a rejected one stays (409) |
145
+ | `listTopUps({ limit?, cursor? })` | Top-ups, newest first |
146
+ | `previewTopUp({ amount })` | What buying `amount` would charge: tax, account credit, and the card charge |
147
+ | `createTopUp({ amount })` | Buys credit now; `PAID`, or `PENDING` with a `paymentUrl` when the card asks for confirmation |
148
+ | `setAutoTopUp({ enabled, threshold?, amount? })` | Buys `amount` whenever a send leaves the balance below `threshold` |
149
+
150
+ Every method also takes `projectId`. The lists page with the previous page's
151
+ `nextCursor` as `cursor`.
152
+
153
+ Reads need `sms:read`, and sending and managing senders `sms:write`. Buying
154
+ credit charges the project's card, so `createTopUp` and `setAutoTopUp` need
155
+ `billing:write` and `previewTopUp` needs `billing:read`. Amounts are whole minor units
156
+ (öre or cents) of the project's billing currency, before VAT. Every SMS route
157
+ answers 404 while SMS is not enabled for the project.
158
+
159
+ Sending is paid for from the prepaid balance before the message goes out: 402
160
+ when the balance cannot cover it, 403 when the sender is not approved or SMS is
161
+ suspended, 422 when the number is not a mobile number in a country on sale, and
162
+ 429 once the project's daily part limit is reached.
163
+
164
+ `send` is the one write the client retries after a timeout or 5xx. Each send
165
+ carries an `Idempotency-Key`, reused across retries, and the API answers a
166
+ repeat with the message it already sent instead of sending and charging again.
167
+ Pass your own key (`idempotencyKey`) to make a send safe to repeat across calls or
168
+ processes; reusing one for a different message is a 409
169
+ (`SMS_IDEMPOTENCY_MISMATCH`). `createTopUp` is not retried, since the charge
170
+ may have gone through: check `listTopUps()` before trying again.
171
+
119
172
  ## Apps
120
173
 
121
174
  ```ts
package/dist/client.d.ts CHANGED
@@ -15,6 +15,7 @@ import { RedisService } from "./services/redis";
15
15
  import { RegistriesService } from "./services/registries";
16
16
  import { SecretsService } from "./services/secrets";
17
17
  import { ServersService } from "./services/servers";
18
+ import { SmsService } from "./services/sms";
18
19
  import { SshKeysService } from "./services/ssh-keys";
19
20
  import { VariablesService } from "./services/variables";
20
21
  import { WebhooksService } from "./services/webhooks";
@@ -55,6 +56,7 @@ export declare class Cosmoner {
55
56
  readonly registries: RegistriesService;
56
57
  readonly secrets: SecretsService;
57
58
  readonly servers: ServersService;
59
+ readonly sms: SmsService;
58
60
  readonly sshKeys: SshKeysService;
59
61
  readonly variables: VariablesService;
60
62
  readonly webhooks: WebhooksService;
package/dist/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export { ProjectsService, type DeleteProjectResponse, type GetProjectResponse, t
20
20
  export { RedisService, type CreateRedisParams, type CreateRedisResponse, type DeleteRedisDatabaseResponse, type GetRedisDatabaseResponse, type ListRedisDatabasesResponse, type PreviewRedisParams, type PreviewRedisResponse, type RedisDatabase, type RedisDatabaseDetail, type RedisPersistence, } from "./services/redis";
21
21
  export { RegistriesService, type CreateRegistryParams, type CreateRegistryResponse, type DeleteRegistryResponse, type GetRegistryResponse, type ListRegistriesResponse, type ListRegistryProvidersResponse, type PreviewRegistryResponse, type Registry, type RegistryProvider, type RegistryRepository, } from "./services/registries";
22
22
  export { ServersService, type CreateServerParams, type CreateServerResponse, type DeleteServerResponse, type GetServerResponse, type ListServersResponse, type PreviewServerParams, type PreviewServerResponse, type ServerActionResponse, type Server, type ServerDetail, type ServerStatus, type UpdateServerParams, type UpdateServerResponse, } from "./services/servers";
23
+ export { SmsService, type CreateSmsSenderParams, type CreateSmsSenderResponse, type CreateSmsTopUpResponse, type GetSmsAccountResponse, type GetSmsMessageResponse, type ListSmsMessagesResponse, type ListSmsParams, type ListSmsSendersResponse, type ListSmsTopUpsResponse, type PreviewSmsTopUpResponse, type RequestSmsSenderReviewParams, type RequestSmsSenderReviewResponse, type SendSmsParams, type SendSmsResponse, type SetSmsAutoTopUpParams, type SmsAccount, type SmsMessage, type SmsMessageStatus, type SmsPage, type SmsSender, type SmsSenderStatus, type SmsSendResult, type SmsTopUp, type SmsTopUpParams, type SmsTopUpPreview, type SmsTopUpStatus, type SmsTopUpTrigger, } from "./services/sms";
23
24
  export { SshKeysService, type CreateSshKeyParams, type CreateSshKeyResponse, type DeleteSshKeyResponse, type GenerateSshKeyResponse, type GeneratedSshKey, type ListSshKeysResponse, type SshKey, } from "./services/ssh-keys";
24
25
  export { PROJECT_ENVIRONMENTS, type Actor, type ProjectEnvironment, } from "./services/project-config";
25
26
  export { SecretsService, type CreateSecretParams, type GetSecretAuditResponse, type GetSecretResponse, type GetSecretsUsageResponse, type ListSecretsParams, type ListSecretsResponse, type ProjectSecret, type RevealedProjectSecret, type SecretAuditEntry, type SecretsUsage, type SetSecretResponse, type UpdateSecretParams, } from "./services/secrets";
package/dist/index.js CHANGED
@@ -59,6 +59,7 @@ __export(index_exports, {
59
59
  SecretsService: () => SecretsService,
60
60
  ServerError: () => ServerError,
61
61
  ServersService: () => ServersService,
62
+ SmsService: () => SmsService,
62
63
  SshKeysService: () => SshKeysService,
63
64
  VERSION: () => VERSION,
64
65
  ValidationError: () => ValidationError,
@@ -1340,6 +1341,149 @@ var ServersService = class {
1340
1341
  }
1341
1342
  };
1342
1343
 
1344
+ // src/services/sms.ts
1345
+ function requireAmount(field, value, allowZero = false) {
1346
+ if (typeof value !== "number" || !Number.isInteger(value) || value < (allowZero ? 0 : 1)) {
1347
+ throw new Error(`${field} must be a ${allowZero ? "non-negative" : "positive"} integer`);
1348
+ }
1349
+ }
1350
+ var SmsService = class {
1351
+ constructor(transport, config) {
1352
+ this.transport = transport;
1353
+ this.config = config;
1354
+ }
1355
+ /** Reads the project's balance, auto top-up, daily limit and per-destination prices. */
1356
+ async account(params = {}) {
1357
+ return this.transport.request("GET", this.basePath(params.projectId));
1358
+ }
1359
+ /**
1360
+ * Sends one SMS, paid for from the balance before it goes out, and resolves
1361
+ * with the message and the balance left.
1362
+ *
1363
+ * Safe to retry: every send carries an idempotency key, so a timeout or 5xx
1364
+ * is retried, and a repeat returns the message already sent rather than
1365
+ * sending and charging again. Pass your own `idempotencyKey` to extend that
1366
+ * across calls or processes; reusing one for different content is a 409.
1367
+ */
1368
+ async send(params) {
1369
+ if (!params?.from) throw new Error("from is required");
1370
+ if (!params.to) throw new Error("to is required");
1371
+ if (!params.message) throw new Error("message is required");
1372
+ return this.transport.request("POST", `${this.basePath(params.projectId)}/messages`, {
1373
+ body: { from: params.from, to: params.to, message: params.message },
1374
+ idempotencyKey: params.idempotencyKey || void 0,
1375
+ retryNonIdempotent: true
1376
+ });
1377
+ }
1378
+ /** Lists one page of sent messages, newest first. */
1379
+ async listMessages(params = {}) {
1380
+ return this.transport.request("GET", `${this.basePath(params.projectId)}/messages`, {
1381
+ query: pageQuery(params)
1382
+ });
1383
+ }
1384
+ /** Reads one message, with its delivery status. */
1385
+ async getMessage(messageId, params = {}) {
1386
+ if (!messageId) throw new Error("messageId is required");
1387
+ return this.transport.request(
1388
+ "GET",
1389
+ `${this.basePath(params.projectId)}/messages/${encodeURIComponent(messageId)}`
1390
+ );
1391
+ }
1392
+ /** Lists the project's sender names, at every stage of review. */
1393
+ async listSenders(params = {}) {
1394
+ return this.transport.request("GET", `${this.basePath(params.projectId)}/senders`);
1395
+ }
1396
+ /**
1397
+ * Asks for a sender name. A name that fits the project's verified domains
1398
+ * may be approved or rejected at once; otherwise it waits as `PENDING` for
1399
+ * a person. Only an `APPROVED` name can send.
1400
+ */
1401
+ async createSender(params) {
1402
+ if (!params?.name) throw new Error("name is required");
1403
+ if (!params.purpose) throw new Error("purpose is required");
1404
+ return this.transport.request("POST", `${this.basePath(params.projectId)}/senders`, {
1405
+ body: { name: params.name, purpose: params.purpose }
1406
+ });
1407
+ }
1408
+ /**
1409
+ * Asks a person to review a name that was rejected automatically. Opens a
1410
+ * support ticket and resolves with the sender, its `reviewTicketId` set.
1411
+ * 409 when the name was not rejected automatically, or a review was already
1412
+ * asked for.
1413
+ */
1414
+ async requestSenderReview(senderId, params) {
1415
+ if (!senderId) throw new Error("senderId is required");
1416
+ if (!params?.message) throw new Error("message is required");
1417
+ return this.transport.request(
1418
+ "POST",
1419
+ `${this.basePath(params.projectId)}/senders/${encodeURIComponent(senderId)}/review-request`,
1420
+ { body: { message: params.message } }
1421
+ );
1422
+ }
1423
+ /**
1424
+ * Removes a pending or approved sender name; nothing more can be sent under
1425
+ * it. A rejected name stays on the project: deleting one is a 409.
1426
+ */
1427
+ async deleteSender(senderId, params = {}) {
1428
+ if (!senderId) throw new Error("senderId is required");
1429
+ await this.transport.request(
1430
+ "DELETE",
1431
+ `${this.basePath(params.projectId)}/senders/${encodeURIComponent(senderId)}`
1432
+ );
1433
+ }
1434
+ /** Lists one page of top-ups, newest first. */
1435
+ async listTopUps(params = {}) {
1436
+ return this.transport.request("GET", `${this.basePath(params.projectId)}/top-ups`, {
1437
+ query: pageQuery(params)
1438
+ });
1439
+ }
1440
+ /** Prices a top-up without buying it: the tax, any account credit, and what the card would be charged. */
1441
+ async previewTopUp(params) {
1442
+ requireAmount("amount", params?.amount);
1443
+ return this.transport.request(
1444
+ "GET",
1445
+ `${this.basePath(params.projectId)}/top-ups/preview`,
1446
+ { query: { amount: params.amount } }
1447
+ );
1448
+ }
1449
+ /**
1450
+ * Buys credit now, charging the project's card. The top-up comes back
1451
+ * `PAID`, or `PENDING` with a `paymentUrl` when the card asks for
1452
+ * confirmation. Not retried on a timeout or 5xx, since the charge may have
1453
+ * gone through: check `listTopUps()` before trying again.
1454
+ */
1455
+ async createTopUp(params) {
1456
+ requireAmount("amount", params?.amount);
1457
+ return this.transport.request("POST", `${this.basePath(params.projectId)}/top-ups`, {
1458
+ body: { amount: params.amount }
1459
+ });
1460
+ }
1461
+ /**
1462
+ * Turns automatic top-ups on or off, and resolves with the account as it
1463
+ * now stands. While on, a send that leaves the balance below `threshold`
1464
+ * buys `amount` more, charging the project's card.
1465
+ */
1466
+ async setAutoTopUp(params) {
1467
+ if (typeof params?.enabled !== "boolean") throw new Error("enabled must be a boolean");
1468
+ if (params.enabled) {
1469
+ if (params.threshold === void 0) throw new Error("threshold is required when enabled");
1470
+ if (params.amount === void 0) throw new Error("amount is required when enabled");
1471
+ }
1472
+ if (params.threshold !== void 0) requireAmount("threshold", params.threshold, true);
1473
+ if (params.amount !== void 0) requireAmount("amount", params.amount);
1474
+ return this.transport.request("PUT", `${this.basePath(params.projectId)}/auto-top-up`, {
1475
+ body: { enabled: params.enabled, threshold: params.threshold, amount: params.amount }
1476
+ });
1477
+ }
1478
+ /** Builds the collection route for the resolved project. */
1479
+ basePath(projectId) {
1480
+ return `/v1/projects/${resolveProjectId(this.config, projectId)}/sms`;
1481
+ }
1482
+ };
1483
+ function pageQuery(params) {
1484
+ return { limit: params.limit, cursor: params.cursor || void 0 };
1485
+ }
1486
+
1343
1487
  // src/services/ssh-keys.ts
1344
1488
  var SshKeysService = class {
1345
1489
  constructor(transport, config) {
@@ -1828,7 +1972,7 @@ function sleep(ms) {
1828
1972
  }
1829
1973
 
1830
1974
  // src/version.ts
1831
- var VERSION = "1.22.1";
1975
+ var VERSION = "1.23.0";
1832
1976
  var USER_AGENT = `cosmoner-node/${VERSION}`;
1833
1977
 
1834
1978
  // src/transport.ts
@@ -1966,6 +2110,7 @@ var Cosmoner = class {
1966
2110
  this.registries = new RegistriesService(this.transport, this.config);
1967
2111
  this.secrets = new SecretsService(this.transport, this.config);
1968
2112
  this.servers = new ServersService(this.transport, this.config);
2113
+ this.sms = new SmsService(this.transport, this.config);
1969
2114
  this.sshKeys = new SshKeysService(this.transport, this.config);
1970
2115
  this.variables = new VariablesService(this.transport, this.config);
1971
2116
  this.webhooks = new WebhooksService(this.transport, this.config);
@@ -2361,6 +2506,7 @@ var index_default = Cosmoner;
2361
2506
  SecretsService,
2362
2507
  ServerError,
2363
2508
  ServersService,
2509
+ SmsService,
2364
2510
  SshKeysService,
2365
2511
  VERSION,
2366
2512
  ValidationError,
package/dist/index.mjs CHANGED
@@ -1264,6 +1264,149 @@ var ServersService = class {
1264
1264
  }
1265
1265
  };
1266
1266
 
1267
+ // src/services/sms.ts
1268
+ function requireAmount(field, value, allowZero = false) {
1269
+ if (typeof value !== "number" || !Number.isInteger(value) || value < (allowZero ? 0 : 1)) {
1270
+ throw new Error(`${field} must be a ${allowZero ? "non-negative" : "positive"} integer`);
1271
+ }
1272
+ }
1273
+ var SmsService = class {
1274
+ constructor(transport, config) {
1275
+ this.transport = transport;
1276
+ this.config = config;
1277
+ }
1278
+ /** Reads the project's balance, auto top-up, daily limit and per-destination prices. */
1279
+ async account(params = {}) {
1280
+ return this.transport.request("GET", this.basePath(params.projectId));
1281
+ }
1282
+ /**
1283
+ * Sends one SMS, paid for from the balance before it goes out, and resolves
1284
+ * with the message and the balance left.
1285
+ *
1286
+ * Safe to retry: every send carries an idempotency key, so a timeout or 5xx
1287
+ * is retried, and a repeat returns the message already sent rather than
1288
+ * sending and charging again. Pass your own `idempotencyKey` to extend that
1289
+ * across calls or processes; reusing one for different content is a 409.
1290
+ */
1291
+ async send(params) {
1292
+ if (!params?.from) throw new Error("from is required");
1293
+ if (!params.to) throw new Error("to is required");
1294
+ if (!params.message) throw new Error("message is required");
1295
+ return this.transport.request("POST", `${this.basePath(params.projectId)}/messages`, {
1296
+ body: { from: params.from, to: params.to, message: params.message },
1297
+ idempotencyKey: params.idempotencyKey || void 0,
1298
+ retryNonIdempotent: true
1299
+ });
1300
+ }
1301
+ /** Lists one page of sent messages, newest first. */
1302
+ async listMessages(params = {}) {
1303
+ return this.transport.request("GET", `${this.basePath(params.projectId)}/messages`, {
1304
+ query: pageQuery(params)
1305
+ });
1306
+ }
1307
+ /** Reads one message, with its delivery status. */
1308
+ async getMessage(messageId, params = {}) {
1309
+ if (!messageId) throw new Error("messageId is required");
1310
+ return this.transport.request(
1311
+ "GET",
1312
+ `${this.basePath(params.projectId)}/messages/${encodeURIComponent(messageId)}`
1313
+ );
1314
+ }
1315
+ /** Lists the project's sender names, at every stage of review. */
1316
+ async listSenders(params = {}) {
1317
+ return this.transport.request("GET", `${this.basePath(params.projectId)}/senders`);
1318
+ }
1319
+ /**
1320
+ * Asks for a sender name. A name that fits the project's verified domains
1321
+ * may be approved or rejected at once; otherwise it waits as `PENDING` for
1322
+ * a person. Only an `APPROVED` name can send.
1323
+ */
1324
+ async createSender(params) {
1325
+ if (!params?.name) throw new Error("name is required");
1326
+ if (!params.purpose) throw new Error("purpose is required");
1327
+ return this.transport.request("POST", `${this.basePath(params.projectId)}/senders`, {
1328
+ body: { name: params.name, purpose: params.purpose }
1329
+ });
1330
+ }
1331
+ /**
1332
+ * Asks a person to review a name that was rejected automatically. Opens a
1333
+ * support ticket and resolves with the sender, its `reviewTicketId` set.
1334
+ * 409 when the name was not rejected automatically, or a review was already
1335
+ * asked for.
1336
+ */
1337
+ async requestSenderReview(senderId, params) {
1338
+ if (!senderId) throw new Error("senderId is required");
1339
+ if (!params?.message) throw new Error("message is required");
1340
+ return this.transport.request(
1341
+ "POST",
1342
+ `${this.basePath(params.projectId)}/senders/${encodeURIComponent(senderId)}/review-request`,
1343
+ { body: { message: params.message } }
1344
+ );
1345
+ }
1346
+ /**
1347
+ * Removes a pending or approved sender name; nothing more can be sent under
1348
+ * it. A rejected name stays on the project: deleting one is a 409.
1349
+ */
1350
+ async deleteSender(senderId, params = {}) {
1351
+ if (!senderId) throw new Error("senderId is required");
1352
+ await this.transport.request(
1353
+ "DELETE",
1354
+ `${this.basePath(params.projectId)}/senders/${encodeURIComponent(senderId)}`
1355
+ );
1356
+ }
1357
+ /** Lists one page of top-ups, newest first. */
1358
+ async listTopUps(params = {}) {
1359
+ return this.transport.request("GET", `${this.basePath(params.projectId)}/top-ups`, {
1360
+ query: pageQuery(params)
1361
+ });
1362
+ }
1363
+ /** Prices a top-up without buying it: the tax, any account credit, and what the card would be charged. */
1364
+ async previewTopUp(params) {
1365
+ requireAmount("amount", params?.amount);
1366
+ return this.transport.request(
1367
+ "GET",
1368
+ `${this.basePath(params.projectId)}/top-ups/preview`,
1369
+ { query: { amount: params.amount } }
1370
+ );
1371
+ }
1372
+ /**
1373
+ * Buys credit now, charging the project's card. The top-up comes back
1374
+ * `PAID`, or `PENDING` with a `paymentUrl` when the card asks for
1375
+ * confirmation. Not retried on a timeout or 5xx, since the charge may have
1376
+ * gone through: check `listTopUps()` before trying again.
1377
+ */
1378
+ async createTopUp(params) {
1379
+ requireAmount("amount", params?.amount);
1380
+ return this.transport.request("POST", `${this.basePath(params.projectId)}/top-ups`, {
1381
+ body: { amount: params.amount }
1382
+ });
1383
+ }
1384
+ /**
1385
+ * Turns automatic top-ups on or off, and resolves with the account as it
1386
+ * now stands. While on, a send that leaves the balance below `threshold`
1387
+ * buys `amount` more, charging the project's card.
1388
+ */
1389
+ async setAutoTopUp(params) {
1390
+ if (typeof params?.enabled !== "boolean") throw new Error("enabled must be a boolean");
1391
+ if (params.enabled) {
1392
+ if (params.threshold === void 0) throw new Error("threshold is required when enabled");
1393
+ if (params.amount === void 0) throw new Error("amount is required when enabled");
1394
+ }
1395
+ if (params.threshold !== void 0) requireAmount("threshold", params.threshold, true);
1396
+ if (params.amount !== void 0) requireAmount("amount", params.amount);
1397
+ return this.transport.request("PUT", `${this.basePath(params.projectId)}/auto-top-up`, {
1398
+ body: { enabled: params.enabled, threshold: params.threshold, amount: params.amount }
1399
+ });
1400
+ }
1401
+ /** Builds the collection route for the resolved project. */
1402
+ basePath(projectId) {
1403
+ return `/v1/projects/${resolveProjectId(this.config, projectId)}/sms`;
1404
+ }
1405
+ };
1406
+ function pageQuery(params) {
1407
+ return { limit: params.limit, cursor: params.cursor || void 0 };
1408
+ }
1409
+
1267
1410
  // src/services/ssh-keys.ts
1268
1411
  var SshKeysService = class {
1269
1412
  constructor(transport, config) {
@@ -1752,7 +1895,7 @@ function sleep(ms) {
1752
1895
  }
1753
1896
 
1754
1897
  // src/version.ts
1755
- var VERSION = "1.22.1";
1898
+ var VERSION = "1.23.0";
1756
1899
  var USER_AGENT = `cosmoner-node/${VERSION}`;
1757
1900
 
1758
1901
  // src/transport.ts
@@ -1890,6 +2033,7 @@ var Cosmoner = class {
1890
2033
  this.registries = new RegistriesService(this.transport, this.config);
1891
2034
  this.secrets = new SecretsService(this.transport, this.config);
1892
2035
  this.servers = new ServersService(this.transport, this.config);
2036
+ this.sms = new SmsService(this.transport, this.config);
1893
2037
  this.sshKeys = new SshKeysService(this.transport, this.config);
1894
2038
  this.variables = new VariablesService(this.transport, this.config);
1895
2039
  this.webhooks = new WebhooksService(this.transport, this.config);
@@ -2284,6 +2428,7 @@ export {
2284
2428
  SecretsService,
2285
2429
  ServerError,
2286
2430
  ServersService,
2431
+ SmsService,
2287
2432
  SshKeysService,
2288
2433
  VERSION,
2289
2434
  ValidationError,
@@ -0,0 +1,271 @@
1
+ /**
2
+ * SMS service namespace — sending text messages from a project's prepaid
3
+ * balance, the sender names they go out under, and the credit that pays for
4
+ * them.
5
+ */
6
+ import { type ResolvedConfig } from "../config";
7
+ import type { Transport } from "../transport";
8
+ /** Where a message is. `UNKNOWN` means the provider never answered; it is settled later. */
9
+ export type SmsMessageStatus = "SENDING" | "SENT" | "DELIVERED" | "FAILED" | "UNKNOWN";
10
+ /** Where a sender name is in its review. */
11
+ export type SmsSenderStatus = "PENDING" | "APPROVED" | "REJECTED";
12
+ /** Where a top-up's payment is. */
13
+ export type SmsTopUpStatus = "PENDING" | "PAID" | "FAILED" | "VOID";
14
+ /** Who started a top-up: someone buying credit, or the auto top-up. */
15
+ export type SmsTopUpTrigger = "MANUAL" | "AUTO";
16
+ /**
17
+ * Amounts throughout are whole minor units of `currency` (öre or cents),
18
+ * before VAT unless a field says otherwise.
19
+ */
20
+ export interface SmsTopUp {
21
+ id: string;
22
+ trigger: SmsTopUpTrigger;
23
+ status: SmsTopUpStatus;
24
+ amount: number;
25
+ currency: string;
26
+ failureReason: string | null;
27
+ /** The stable code for `failureReason`. Null unless `FAILED` or `VOID`. */
28
+ failureCode: string | null;
29
+ createdAt: string;
30
+ paidAt: string | null;
31
+ /** Where to pay a `PENDING` top-up, such as one whose card asked for confirmation. Null otherwise. */
32
+ paymentUrl: string | null;
33
+ /** The paid invoice's page. Null unless `PAID`. */
34
+ invoiceUrl: string | null;
35
+ /** The tax on the invoice: VAT where it applies, 0 under reverse charge. Null until the invoice is finalized. */
36
+ tax: number | null;
37
+ /** `amount` plus `tax`. Null with `tax`. */
38
+ total: number | null;
39
+ }
40
+ /** The project's SMS balance, limits and prices. */
41
+ export interface SmsAccount {
42
+ /** Minor units of `currency`. */
43
+ balance: number;
44
+ /** Null until the first top-up; the project's billing currency after. */
45
+ currency: string | null;
46
+ autoTopUp: {
47
+ enabled: boolean;
48
+ threshold: number | null;
49
+ amount: number | null;
50
+ /** When the last automatic top-up's payment failed. While set, none is attempted. */
51
+ failedAt: string | null;
52
+ };
53
+ dailyPartLimit: number;
54
+ /** Parts sent in the current day's window. */
55
+ dailyPartsUsed: number;
56
+ /** When the current day's window closes and `dailyPartsUsed` starts again. Null while none is open. */
57
+ dailyWindowResetsAt: string | null;
58
+ suspended: boolean;
59
+ /** A top-up waiting for payment, if any. */
60
+ pendingTopUp: SmsTopUp | null;
61
+ /** What one part costs per destination, in `priceCurrency`. */
62
+ prices: Array<{
63
+ country: string;
64
+ name: string;
65
+ pricePerPart: number;
66
+ }>;
67
+ /** The smallest and largest top-up, and the highest auto top-up threshold, in `priceCurrency`. */
68
+ topUpBounds: {
69
+ min: number;
70
+ max: number;
71
+ thresholdMax: number;
72
+ };
73
+ priceCurrency: string;
74
+ }
75
+ /** One message in the project's log. */
76
+ export interface SmsMessage {
77
+ id: string;
78
+ /** The sender name it went out under. */
79
+ from: string;
80
+ /** The recipient, in E.164. */
81
+ to: string;
82
+ country: string;
83
+ /** How many parts the text was split into; each is charged. */
84
+ parts: number;
85
+ /** What it cost, in minor units of `currency`. */
86
+ price: number;
87
+ currency: string;
88
+ status: SmsMessageStatus;
89
+ /** Why it `FAILED`, or why its outcome is `UNKNOWN`. Null otherwise. */
90
+ failureReason: string | null;
91
+ /** The stable code for `failureReason`. Null whenever it is. */
92
+ failureCode: string | null;
93
+ createdAt: string;
94
+ deliveredAt: string | null;
95
+ }
96
+ /** A name messages can be sent under. Only an `APPROVED` one can send. */
97
+ export interface SmsSender {
98
+ id: string;
99
+ name: string;
100
+ status: SmsSenderStatus;
101
+ purpose: string;
102
+ rejectionReason: string | null;
103
+ createdAt: string;
104
+ reviewedAt: string | null;
105
+ /** When an approval was withdrawn; the status is then `REJECTED`. */
106
+ revokedAt: string | null;
107
+ /** True when the name was approved or rejected on request, from the project's verified domains, rather than by a person. */
108
+ reviewedAutomatically: boolean;
109
+ /** The support ticket asking a person to review an automatic rejection. Null until one is opened. */
110
+ reviewTicketId: string | null;
111
+ }
112
+ /** What buying an amount of credit would charge. Minor units of `currency`. */
113
+ export interface SmsTopUpPreview {
114
+ /** The credit bought, before tax: what the balance grows by. */
115
+ amount: number;
116
+ /** The tax that would be added. Null when the project's tax location is not known yet. */
117
+ tax: number | null;
118
+ /** `amount` plus `tax`. Null with `tax`. */
119
+ total: number | null;
120
+ /** Account credit applied before the card is charged. 0 when none. */
121
+ creditApplied: number;
122
+ /** What the card would be charged: `total` less `creditApplied`. Null with `tax`. */
123
+ charged: number | null;
124
+ currency: string;
125
+ }
126
+ /** One page of the message log or the top-up history, newest first. */
127
+ export interface SmsPage<T> {
128
+ items: T[];
129
+ /** Pass back as `cursor` for the next page; null on the last one. */
130
+ nextCursor: string | null;
131
+ }
132
+ /** What a send returns. */
133
+ export interface SmsSendResult {
134
+ message: SmsMessage;
135
+ /** The balance after this message was paid for. */
136
+ balance: number;
137
+ }
138
+ interface Envelope<T> {
139
+ success: true;
140
+ data: T;
141
+ }
142
+ /** Options accepted by every method, for working across projects. */
143
+ export interface ProjectScopedParams {
144
+ /** Overrides the client-level default project for this call. */
145
+ projectId?: string;
146
+ }
147
+ /** Arguments accepted by `client.sms.send()`. */
148
+ export interface SendSmsParams extends ProjectScopedParams {
149
+ /** An approved sender name of this project. */
150
+ from: string;
151
+ /** The recipient's mobile number in E.164, such as `+46701234567`. */
152
+ to: string;
153
+ /** The text. Longer texts are sent as several parts, up to six, each charged. */
154
+ message: string;
155
+ /**
156
+ * Makes the send safe to repeat: a send reusing a key returns the message
157
+ * the first one sent, without sending or charging again. 1 to 255 printable
158
+ * ASCII characters. Left out, the client generates one per call.
159
+ */
160
+ idempotencyKey?: string;
161
+ }
162
+ /** Arguments accepted by `client.sms.listMessages()` and `listTopUps()`. */
163
+ export interface ListSmsParams extends ProjectScopedParams {
164
+ /** Page size, 1 to 100. The API defaults to 50. */
165
+ limit?: number;
166
+ /** The previous page's `nextCursor`. */
167
+ cursor?: string;
168
+ }
169
+ /** Arguments accepted by `client.sms.createSender()`. */
170
+ export interface CreateSmsSenderParams extends ProjectScopedParams {
171
+ /** What recipients see as the sender: a letter, then 2 to 10 letters or digits. */
172
+ name: string;
173
+ /** Who the name stands for and what will be sent, for the review. 10 to 500 characters. */
174
+ purpose: string;
175
+ }
176
+ /** Arguments accepted by `client.sms.requestSenderReview()`. */
177
+ export interface RequestSmsSenderReviewParams extends ProjectScopedParams {
178
+ /** Why the project may use the name: whose it is, and how the project is connected to it. 20 to 2,000 characters. */
179
+ message: string;
180
+ }
181
+ /** Arguments accepted by `client.sms.previewTopUp()` and `createTopUp()`. */
182
+ export interface SmsTopUpParams extends ProjectScopedParams {
183
+ /** The credit, in minor units of the project's billing currency, before VAT. */
184
+ amount: number;
185
+ }
186
+ /** Arguments accepted by `client.sms.setAutoTopUp()`. */
187
+ export interface SetSmsAutoTopUpParams extends ProjectScopedParams {
188
+ enabled: boolean;
189
+ /** Top up when a send leaves the balance below this. Required when enabled. */
190
+ threshold?: number;
191
+ /** How much to buy each time; more than `threshold`. Required when enabled. */
192
+ amount?: number;
193
+ }
194
+ export type GetSmsAccountResponse = Envelope<SmsAccount>;
195
+ export type SendSmsResponse = Envelope<SmsSendResult>;
196
+ export type ListSmsMessagesResponse = Envelope<SmsPage<SmsMessage>>;
197
+ export type GetSmsMessageResponse = Envelope<SmsMessage>;
198
+ export type ListSmsSendersResponse = Envelope<SmsSender[]>;
199
+ export type CreateSmsSenderResponse = Envelope<SmsSender>;
200
+ export type ListSmsTopUpsResponse = Envelope<SmsPage<SmsTopUp>>;
201
+ export type PreviewSmsTopUpResponse = Envelope<SmsTopUpPreview>;
202
+ export type CreateSmsTopUpResponse = Envelope<SmsTopUp>;
203
+ export type RequestSmsSenderReviewResponse = Envelope<SmsSender>;
204
+ /**
205
+ * SMS for a project. Reads need `sms:read`, and sending and managing senders
206
+ * `sms:write`. Buying credit charges the project's card, so `createTopUp()`
207
+ * and `setAutoTopUp()` need `billing:write` instead, and `previewTopUp()`
208
+ * `billing:read`. Answers 404 throughout while SMS is not enabled for the
209
+ * project.
210
+ */
211
+ export declare class SmsService {
212
+ private readonly transport;
213
+ private readonly config;
214
+ constructor(transport: Transport, config: ResolvedConfig);
215
+ /** Reads the project's balance, auto top-up, daily limit and per-destination prices. */
216
+ account(params?: ProjectScopedParams): Promise<GetSmsAccountResponse>;
217
+ /**
218
+ * Sends one SMS, paid for from the balance before it goes out, and resolves
219
+ * with the message and the balance left.
220
+ *
221
+ * Safe to retry: every send carries an idempotency key, so a timeout or 5xx
222
+ * is retried, and a repeat returns the message already sent rather than
223
+ * sending and charging again. Pass your own `idempotencyKey` to extend that
224
+ * across calls or processes; reusing one for different content is a 409.
225
+ */
226
+ send(params: SendSmsParams): Promise<SendSmsResponse>;
227
+ /** Lists one page of sent messages, newest first. */
228
+ listMessages(params?: ListSmsParams): Promise<ListSmsMessagesResponse>;
229
+ /** Reads one message, with its delivery status. */
230
+ getMessage(messageId: string, params?: ProjectScopedParams): Promise<GetSmsMessageResponse>;
231
+ /** Lists the project's sender names, at every stage of review. */
232
+ listSenders(params?: ProjectScopedParams): Promise<ListSmsSendersResponse>;
233
+ /**
234
+ * Asks for a sender name. A name that fits the project's verified domains
235
+ * may be approved or rejected at once; otherwise it waits as `PENDING` for
236
+ * a person. Only an `APPROVED` name can send.
237
+ */
238
+ createSender(params: CreateSmsSenderParams): Promise<CreateSmsSenderResponse>;
239
+ /**
240
+ * Asks a person to review a name that was rejected automatically. Opens a
241
+ * support ticket and resolves with the sender, its `reviewTicketId` set.
242
+ * 409 when the name was not rejected automatically, or a review was already
243
+ * asked for.
244
+ */
245
+ requestSenderReview(senderId: string, params: RequestSmsSenderReviewParams): Promise<RequestSmsSenderReviewResponse>;
246
+ /**
247
+ * Removes a pending or approved sender name; nothing more can be sent under
248
+ * it. A rejected name stays on the project: deleting one is a 409.
249
+ */
250
+ deleteSender(senderId: string, params?: ProjectScopedParams): Promise<void>;
251
+ /** Lists one page of top-ups, newest first. */
252
+ listTopUps(params?: ListSmsParams): Promise<ListSmsTopUpsResponse>;
253
+ /** Prices a top-up without buying it: the tax, any account credit, and what the card would be charged. */
254
+ previewTopUp(params: SmsTopUpParams): Promise<PreviewSmsTopUpResponse>;
255
+ /**
256
+ * Buys credit now, charging the project's card. The top-up comes back
257
+ * `PAID`, or `PENDING` with a `paymentUrl` when the card asks for
258
+ * confirmation. Not retried on a timeout or 5xx, since the charge may have
259
+ * gone through: check `listTopUps()` before trying again.
260
+ */
261
+ createTopUp(params: SmsTopUpParams): Promise<CreateSmsTopUpResponse>;
262
+ /**
263
+ * Turns automatic top-ups on or off, and resolves with the account as it
264
+ * now stands. While on, a send that leaves the balance below `threshold`
265
+ * buys `amount` more, charging the project's card.
266
+ */
267
+ setAutoTopUp(params: SetSmsAutoTopUpParams): Promise<GetSmsAccountResponse>;
268
+ /** Builds the collection route for the resolved project. */
269
+ private basePath;
270
+ }
271
+ export {};
package/dist/version.d.ts CHANGED
@@ -8,5 +8,5 @@
8
8
  * the release workflow runs that straight after `npm version`, and
9
9
  * `version.test.ts` fails the build if the two ever disagree.
10
10
  */
11
- export declare const VERSION = "1.22.1";
12
- export declare const USER_AGENT = "cosmoner-node/1.22.1";
11
+ export declare const VERSION = "1.23.0";
12
+ export declare const USER_AGENT = "cosmoner-node/1.23.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmoner/sdk",
3
- "version": "1.22.1",
3
+ "version": "1.23.0",
4
4
  "description": "Cosmoner SDK for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",