@cosmoner/sdk 1.18.1 → 1.19.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/README.md +30 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +25 -8
- package/dist/index.mjs +25 -8
- package/dist/services/email.d.ts +42 -6
- package/dist/version.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -76,17 +76,45 @@ Set `maxRetries: 0` to disable retries entirely.
|
|
|
76
76
|
|
|
77
77
|
### `client.email.send(params)`
|
|
78
78
|
|
|
79
|
+
Takes either raw content — a `subject` with `html`, `text` or both — or a
|
|
80
|
+
stored `template`, which supplies all three. The two forms are a union type, so
|
|
81
|
+
TypeScript refuses a call that mixes them, and the client rejects one at
|
|
82
|
+
runtime before sending anything.
|
|
83
|
+
|
|
79
84
|
| Parameter | Type | Required | Description |
|
|
80
85
|
| -------------- | -------------------- | -------- | ------------------------------------ |
|
|
81
86
|
| `credentialId` | `string` | Yes | SMTP credential ID |
|
|
82
87
|
| `to` | `string \| string[]` | Yes | Recipient(s), max 50 |
|
|
83
|
-
| `subject` | `string` | Yes
|
|
88
|
+
| `subject` | `string` | Yes* | Email subject line |
|
|
84
89
|
| `html` | `string` | No* | HTML body |
|
|
85
90
|
| `text` | `string` | No* | Plain text body |
|
|
91
|
+
| `template` | `EmailTemplateRef` | No* | A stored template to send instead |
|
|
86
92
|
| `replyTo` | `string \| string[]` | No | Reply-to address(es), max 5 |
|
|
87
93
|
| `projectId` | `string` | No | Overrides the client-level project |
|
|
88
94
|
|
|
89
|
-
\*
|
|
95
|
+
\* Pass `subject` with at least one of `html` or `text`, or pass `template`
|
|
96
|
+
and none of the three.
|
|
97
|
+
|
|
98
|
+
`template` is `{ id, version?, variables? }`: `id` is the template's id or its
|
|
99
|
+
alias, `version` a positive integer (the published version when left out), and
|
|
100
|
+
`variables` the values for the variables the template declares. The response
|
|
101
|
+
names what was rendered under `data.template` (`id`, `alias`, `version`).
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
const { data } = await client.email.send({
|
|
105
|
+
credentialId: "your-credential-id",
|
|
106
|
+
to: "recipient@example.com",
|
|
107
|
+
template: { id: "welcome", variables: { name: "Ada" } },
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
console.log(data.messageId, data.template?.version);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Sending a template needs an API key with `email-templates:read` as well as
|
|
114
|
+
`email:write`. The API answers 404 for an unknown template or version, 409
|
|
115
|
+
(`EMAIL_TEMPLATE_NOT_PUBLISHED`) when no version has been published, 422 when
|
|
116
|
+
the variables do not match what the template declares or rendering hits a
|
|
117
|
+
limit, and 503 when the template is briefly unavailable.
|
|
90
118
|
|
|
91
119
|
## Apps
|
|
92
120
|
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { BucketsService, type Bucket, type BucketTier, type CreateBucketParams,
|
|
|
10
10
|
export { CatalogService, type AppSize, type CatalogRegion, type DatabaseCatalog, type DatabaseSize, type GetDatabaseCatalogResponse, type ListAppRegionsResponse, type ListAppSizesResponse, type ListRedisPlansResponse, type ListRegionsResponse, type ListServerImagesResponse, type ListServerSizesResponse, type RedisPlan, type ServerSize, } from "./services/catalog";
|
|
11
11
|
export { DatabasesService, type CreateDedicatedDatabaseParams, type CreateDedicatedDatabaseResponse, type DatabaseSummary, type DedicatedDatabase, type DedicatedDatabaseDetail, type DeleteDatabaseResponse, type GetDedicatedDatabaseResponse, type GetSharedDatabaseResponse, type ListDatabasesResponse, type ListDedicatedDatabasesResponse, type ListSharedDatabasesResponse, type PreviewDedicatedDatabaseParams, type PreviewDedicatedDatabaseResponse, type RotateSharedDatabasePasswordResponse, type RotatedSharedDatabasePassword, type SharedDatabase, } from "./services/databases";
|
|
12
12
|
export { DomainsService, type CreateDomainResponse, type DeleteDomainResponse, type DnsRecord, type Domain, type GetDomainResponse, type ListDomainsResponse, type VerificationRecord, type VerifyDomainResponse, } from "./services/domains";
|
|
13
|
-
export { EmailService, type CreateEmailDomainParams, type CreateEmailDomainResponse, type CreateExternalEmailDomainParams, type CreateSmtpCredentialParams, type CreateSmtpCredentialResponse, type EmailDomain, type EmailDomainDetail, type EmailDomainVerification, type EmailLimits, type GetEmailDomainResponse, type GetEmailLimitsResponse, type ListEmailDomainsResponse, type NewSmtpCredential, type SendEmailParams, type SendEmailResponse, type VerifyEmailDomainResponse, } from "./services/email";
|
|
13
|
+
export { EmailService, type CreateEmailDomainParams, type CreateEmailDomainResponse, type CreateExternalEmailDomainParams, type CreateSmtpCredentialParams, type CreateSmtpCredentialResponse, type EmailDomain, type EmailDomainDetail, type EmailDomainVerification, type EmailLimits, type EmailTemplateRef, type GetEmailDomainResponse, type GetEmailLimitsResponse, type ListEmailDomainsResponse, type NewSmtpCredential, type SendEmailParams, type SendEmailResponse, type SendRawEmailParams, type SendTemplateEmailParams, type SentEmailTemplate, type VerifyEmailDomainResponse, } from "./services/email";
|
|
14
14
|
export { HostingService, type CreateHostingSiteParams, type CreateHostingSiteResponse, type DeleteHostingSiteResponse, type EnableHostingMailParams, type GetHostingAccessResponse, type GetHostingSiteParams, type GetHostingSiteResponse, type GetHostingSiteWithCredentialsResponse, type HostingAccess, type HostingImageBuild, type HostingImageStatus, type HostingImageStatusResponse, type HostingImageUpdate, type HostingMailStatus, type HostingMailStatusResponse, type HostingPrice, type HostingSite, type HostingSiteStatus, type HostingSiteWithCredentials, type HostingTier, type ListHostingPricesResponse, type ListHostingSitesResponse, type PreviewHostingSiteParams, type PreviewHostingSiteResponse, type SetHostingPhpVersionParams, } from "./services/hosting";
|
|
15
15
|
export { IamService, type CreateIamCredentialParams, type CreateIamCredentialResponse, type GetIamCredentialResponse, type IamCredential, type IamCredentialList, type IamRegistryGrant, type IamStorageGrant, type ListIamCredentialsResponse, type NewIamCredential, } from "./services/iam";
|
|
16
16
|
export { MembersService, type ListMembersResponse, type ProjectMember, type ProjectMembers } from "./services/members";
|
package/dist/index.js
CHANGED
|
@@ -563,6 +563,14 @@ var DomainsService = class {
|
|
|
563
563
|
};
|
|
564
564
|
|
|
565
565
|
// src/services/email.ts
|
|
566
|
+
function templatePayload(template) {
|
|
567
|
+
if (typeof template !== "object" || template === null) throw new Error("template must be an object");
|
|
568
|
+
if (typeof template.id !== "string" || !template.id) throw new Error("template.id is required");
|
|
569
|
+
if (template.version !== void 0 && !(Number.isInteger(template.version) && template.version > 0)) {
|
|
570
|
+
throw new Error("template.version must be a positive integer");
|
|
571
|
+
}
|
|
572
|
+
return { id: template.id, version: template.version, variables: template.variables };
|
|
573
|
+
}
|
|
566
574
|
var EmailService = class {
|
|
567
575
|
constructor(transport, config) {
|
|
568
576
|
this.transport = transport;
|
|
@@ -571,14 +579,25 @@ var EmailService = class {
|
|
|
571
579
|
/**
|
|
572
580
|
* Sends a transactional email and resolves with the API envelope.
|
|
573
581
|
*
|
|
574
|
-
*
|
|
582
|
+
* Pass either `subject` with at least one of `html` or `text`, or a
|
|
583
|
+
* `template`, which supplies all three. A template send's response names
|
|
584
|
+
* the version it rendered under `data.template`.
|
|
575
585
|
*/
|
|
576
586
|
// eslint-disable-next-line require-await -- `async` makes the validation below reject rather than throw synchronously.
|
|
577
587
|
async send(params) {
|
|
578
588
|
if (!params.to) throw new Error("to is required");
|
|
579
|
-
|
|
580
|
-
if (
|
|
581
|
-
|
|
589
|
+
let content;
|
|
590
|
+
if (params.template !== void 0) {
|
|
591
|
+
for (const field of ["subject", "html", "text"]) {
|
|
592
|
+
if (params[field] !== void 0) throw new Error(`Omit ${field} when sending a template`);
|
|
593
|
+
}
|
|
594
|
+
content = { template: templatePayload(params.template) };
|
|
595
|
+
} else {
|
|
596
|
+
if (!params.subject) throw new Error("subject is required");
|
|
597
|
+
if (!params.html && !params.text) {
|
|
598
|
+
throw new Error("Either html or text must be provided");
|
|
599
|
+
}
|
|
600
|
+
content = { subject: params.subject, html: params.html, text: params.text };
|
|
582
601
|
}
|
|
583
602
|
const projectId = resolveProjectId(this.config, params.projectId);
|
|
584
603
|
return this.transport.request(
|
|
@@ -588,9 +607,7 @@ var EmailService = class {
|
|
|
588
607
|
body: {
|
|
589
608
|
credentialId: params.credentialId,
|
|
590
609
|
to: params.to,
|
|
591
|
-
|
|
592
|
-
html: params.html,
|
|
593
|
-
text: params.text,
|
|
610
|
+
...content,
|
|
594
611
|
replyTo: params.replyTo
|
|
595
612
|
}
|
|
596
613
|
}
|
|
@@ -1718,7 +1735,7 @@ function sleep(ms) {
|
|
|
1718
1735
|
}
|
|
1719
1736
|
|
|
1720
1737
|
// src/version.ts
|
|
1721
|
-
var VERSION = "1.
|
|
1738
|
+
var VERSION = "1.19.1";
|
|
1722
1739
|
var USER_AGENT = `cosmoner-node/${VERSION}`;
|
|
1723
1740
|
|
|
1724
1741
|
// src/transport.ts
|
package/dist/index.mjs
CHANGED
|
@@ -488,6 +488,14 @@ var DomainsService = class {
|
|
|
488
488
|
};
|
|
489
489
|
|
|
490
490
|
// src/services/email.ts
|
|
491
|
+
function templatePayload(template) {
|
|
492
|
+
if (typeof template !== "object" || template === null) throw new Error("template must be an object");
|
|
493
|
+
if (typeof template.id !== "string" || !template.id) throw new Error("template.id is required");
|
|
494
|
+
if (template.version !== void 0 && !(Number.isInteger(template.version) && template.version > 0)) {
|
|
495
|
+
throw new Error("template.version must be a positive integer");
|
|
496
|
+
}
|
|
497
|
+
return { id: template.id, version: template.version, variables: template.variables };
|
|
498
|
+
}
|
|
491
499
|
var EmailService = class {
|
|
492
500
|
constructor(transport, config) {
|
|
493
501
|
this.transport = transport;
|
|
@@ -496,14 +504,25 @@ var EmailService = class {
|
|
|
496
504
|
/**
|
|
497
505
|
* Sends a transactional email and resolves with the API envelope.
|
|
498
506
|
*
|
|
499
|
-
*
|
|
507
|
+
* Pass either `subject` with at least one of `html` or `text`, or a
|
|
508
|
+
* `template`, which supplies all three. A template send's response names
|
|
509
|
+
* the version it rendered under `data.template`.
|
|
500
510
|
*/
|
|
501
511
|
// eslint-disable-next-line require-await -- `async` makes the validation below reject rather than throw synchronously.
|
|
502
512
|
async send(params) {
|
|
503
513
|
if (!params.to) throw new Error("to is required");
|
|
504
|
-
|
|
505
|
-
if (
|
|
506
|
-
|
|
514
|
+
let content;
|
|
515
|
+
if (params.template !== void 0) {
|
|
516
|
+
for (const field of ["subject", "html", "text"]) {
|
|
517
|
+
if (params[field] !== void 0) throw new Error(`Omit ${field} when sending a template`);
|
|
518
|
+
}
|
|
519
|
+
content = { template: templatePayload(params.template) };
|
|
520
|
+
} else {
|
|
521
|
+
if (!params.subject) throw new Error("subject is required");
|
|
522
|
+
if (!params.html && !params.text) {
|
|
523
|
+
throw new Error("Either html or text must be provided");
|
|
524
|
+
}
|
|
525
|
+
content = { subject: params.subject, html: params.html, text: params.text };
|
|
507
526
|
}
|
|
508
527
|
const projectId = resolveProjectId(this.config, params.projectId);
|
|
509
528
|
return this.transport.request(
|
|
@@ -513,9 +532,7 @@ var EmailService = class {
|
|
|
513
532
|
body: {
|
|
514
533
|
credentialId: params.credentialId,
|
|
515
534
|
to: params.to,
|
|
516
|
-
|
|
517
|
-
html: params.html,
|
|
518
|
-
text: params.text,
|
|
535
|
+
...content,
|
|
519
536
|
replyTo: params.replyTo
|
|
520
537
|
}
|
|
521
538
|
}
|
|
@@ -1643,7 +1660,7 @@ function sleep(ms) {
|
|
|
1643
1660
|
}
|
|
1644
1661
|
|
|
1645
1662
|
// src/version.ts
|
|
1646
|
-
var VERSION = "1.
|
|
1663
|
+
var VERSION = "1.19.1";
|
|
1647
1664
|
var USER_AGENT = `cosmoner-node/${VERSION}`;
|
|
1648
1665
|
|
|
1649
1666
|
// src/transport.ts
|
package/dist/services/email.d.ts
CHANGED
|
@@ -1,22 +1,55 @@
|
|
|
1
1
|
/** Email service namespace — transactional sending through a project's SMTP credential. */
|
|
2
2
|
import { type ResolvedConfig } from "../config";
|
|
3
3
|
import type { Transport } from "../transport";
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/** The envelope fields shared by both forms of `client.email.send()`. */
|
|
5
|
+
interface SendEmailBaseParams {
|
|
6
6
|
credentialId: string;
|
|
7
7
|
to: string | string[];
|
|
8
|
-
subject: string;
|
|
9
|
-
html?: string;
|
|
10
|
-
text?: string;
|
|
11
8
|
replyTo?: string | string[];
|
|
12
9
|
/** Overrides the client-level default project for this call. */
|
|
13
10
|
projectId?: string;
|
|
14
11
|
}
|
|
12
|
+
/** Sends content carried in the request: a subject and at least one of `html` or `text`. */
|
|
13
|
+
export interface SendRawEmailParams extends SendEmailBaseParams {
|
|
14
|
+
subject: string;
|
|
15
|
+
html?: string;
|
|
16
|
+
text?: string;
|
|
17
|
+
template?: never;
|
|
18
|
+
}
|
|
19
|
+
/** Names a stored template to render the email from. */
|
|
20
|
+
export interface EmailTemplateRef {
|
|
21
|
+
/** The template's id or its alias. */
|
|
22
|
+
id: string;
|
|
23
|
+
/** A positive integer. Leave it out to send the published version. */
|
|
24
|
+
version?: number;
|
|
25
|
+
/** Values for the variables the template declares. */
|
|
26
|
+
variables?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Sends a stored template, which supplies the subject and both bodies. Needs
|
|
30
|
+
* an API key with `email-templates:read` as well as `email:write`.
|
|
31
|
+
*/
|
|
32
|
+
export interface SendTemplateEmailParams extends SendEmailBaseParams {
|
|
33
|
+
template: EmailTemplateRef;
|
|
34
|
+
subject?: never;
|
|
35
|
+
html?: never;
|
|
36
|
+
text?: never;
|
|
37
|
+
}
|
|
38
|
+
/** Arguments accepted by `client.email.send()`: raw content or a template, never both. */
|
|
39
|
+
export type SendEmailParams = SendRawEmailParams | SendTemplateEmailParams;
|
|
40
|
+
/** The template version a template send rendered. */
|
|
41
|
+
export interface SentEmailTemplate {
|
|
42
|
+
id: string;
|
|
43
|
+
alias: string;
|
|
44
|
+
version: number;
|
|
45
|
+
}
|
|
15
46
|
/** Envelope returned by a successful send. */
|
|
16
47
|
export interface SendEmailResponse {
|
|
17
48
|
success: true;
|
|
18
49
|
data: {
|
|
19
50
|
messageId: string;
|
|
51
|
+
/** Present only on a template send. */
|
|
52
|
+
template?: SentEmailTemplate;
|
|
20
53
|
};
|
|
21
54
|
}
|
|
22
55
|
/** A project's sending domain. SMTP passwords and the DKIM private key are never returned. */
|
|
@@ -158,7 +191,9 @@ export declare class EmailService {
|
|
|
158
191
|
/**
|
|
159
192
|
* Sends a transactional email and resolves with the API envelope.
|
|
160
193
|
*
|
|
161
|
-
*
|
|
194
|
+
* Pass either `subject` with at least one of `html` or `text`, or a
|
|
195
|
+
* `template`, which supplies all three. A template send's response names
|
|
196
|
+
* the version it rendered under `data.template`.
|
|
162
197
|
*/
|
|
163
198
|
send(params: SendEmailParams): Promise<SendEmailResponse>;
|
|
164
199
|
/** Lists the project's sending domains, with their SMTP credentials and DNS records. */
|
|
@@ -202,3 +237,4 @@ export declare class EmailService {
|
|
|
202
237
|
*/
|
|
203
238
|
deleteCredential(emailDomainId: string, credentialId: string, params?: ProjectScopedParams): Promise<void>;
|
|
204
239
|
}
|
|
240
|
+
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.
|
|
12
|
-
export declare const USER_AGENT = "cosmoner-node/1.
|
|
11
|
+
export declare const VERSION = "1.19.1";
|
|
12
|
+
export declare const USER_AGENT = "cosmoner-node/1.19.1";
|