@usehercules/sdk 1.14.2 → 1.14.4
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/CHANGELOG.md +111 -0
- package/client.d.mts +8 -1
- package/client.d.mts.map +1 -1
- package/client.d.ts +8 -1
- package/client.d.ts.map +1 -1
- package/client.js +22 -7
- package/client.js.map +1 -1
- package/client.mjs +22 -7
- package/client.mjs.map +1 -1
- package/internal/tslib.js +17 -17
- package/internal/utils/query.d.mts +2 -0
- package/internal/utils/query.d.mts.map +1 -0
- package/internal/utils/query.d.ts +2 -0
- package/internal/utils/query.d.ts.map +1 -0
- package/internal/utils/query.js +10 -0
- package/internal/utils/query.js.map +1 -0
- package/internal/utils/query.mjs +6 -0
- package/internal/utils/query.mjs.map +1 -0
- package/internal/utils.d.mts +1 -0
- package/internal/utils.d.ts +1 -0
- package/internal/utils.js +1 -0
- package/internal/utils.js.map +1 -1
- package/internal/utils.mjs +1 -0
- package/package.json +7 -1
- package/resources/commerce/coupons.d.mts +1 -1
- package/resources/commerce/coupons.d.mts.map +1 -1
- package/resources/commerce/coupons.d.ts +1 -1
- package/resources/commerce/coupons.d.ts.map +1 -1
- package/resources/commerce/coupons.js +1 -1
- package/resources/commerce/coupons.js.map +1 -1
- package/resources/commerce/coupons.mjs +1 -1
- package/resources/commerce/coupons.mjs.map +1 -1
- package/resources/commerce/customers.d.mts +3 -3
- package/resources/commerce/customers.d.mts.map +1 -1
- package/resources/commerce/customers.d.ts +3 -3
- package/resources/commerce/customers.d.ts.map +1 -1
- package/resources/commerce/customers.js +3 -3
- package/resources/commerce/customers.js.map +1 -1
- package/resources/commerce/customers.mjs +3 -3
- package/resources/commerce/customers.mjs.map +1 -1
- package/resources/commerce/features.d.mts +1 -1
- package/resources/commerce/features.d.mts.map +1 -1
- package/resources/commerce/features.d.ts +1 -1
- package/resources/commerce/features.d.ts.map +1 -1
- package/resources/commerce/features.js +1 -1
- package/resources/commerce/features.js.map +1 -1
- package/resources/commerce/features.mjs +1 -1
- package/resources/commerce/features.mjs.map +1 -1
- package/resources/commerce/products/products.d.mts +1 -1
- package/resources/commerce/products/products.d.mts.map +1 -1
- package/resources/commerce/products/products.d.ts +1 -1
- package/resources/commerce/products/products.d.ts.map +1 -1
- package/resources/commerce/products/products.js +1 -1
- package/resources/commerce/products/products.js.map +1 -1
- package/resources/commerce/products/products.mjs +1 -1
- package/resources/commerce/products/products.mjs.map +1 -1
- package/resources/content/assets.d.mts +1 -1
- package/resources/content/assets.d.mts.map +1 -1
- package/resources/content/assets.d.ts +1 -1
- package/resources/content/assets.d.ts.map +1 -1
- package/resources/content/assets.js +1 -1
- package/resources/content/assets.js.map +1 -1
- package/resources/content/assets.mjs +1 -1
- package/resources/content/assets.mjs.map +1 -1
- package/resources/content/collections/collections.d.mts +1 -1
- package/resources/content/collections/collections.d.mts.map +1 -1
- package/resources/content/collections/collections.d.ts +1 -1
- package/resources/content/collections/collections.d.ts.map +1 -1
- package/resources/content/collections/collections.js +1 -1
- package/resources/content/collections/collections.js.map +1 -1
- package/resources/content/collections/collections.mjs +1 -1
- package/resources/content/collections/collections.mjs.map +1 -1
- package/resources/content/entries.d.mts +2 -2
- package/resources/content/entries.d.mts.map +1 -1
- package/resources/content/entries.d.ts +2 -2
- package/resources/content/entries.d.ts.map +1 -1
- package/resources/content/entries.js +2 -2
- package/resources/content/entries.js.map +1 -1
- package/resources/content/entries.mjs +2 -2
- package/resources/content/entries.mjs.map +1 -1
- package/resources/content/locales.d.mts +1 -1
- package/resources/content/locales.d.mts.map +1 -1
- package/resources/content/locales.d.ts +1 -1
- package/resources/content/locales.d.ts.map +1 -1
- package/resources/content/locales.js +1 -1
- package/resources/content/locales.js.map +1 -1
- package/resources/content/locales.mjs +1 -1
- package/resources/content/locales.mjs.map +1 -1
- package/resources/content/releases/releases.d.mts +1 -1
- package/resources/content/releases/releases.d.mts.map +1 -1
- package/resources/content/releases/releases.d.ts +1 -1
- package/resources/content/releases/releases.d.ts.map +1 -1
- package/resources/content/releases/releases.js +1 -1
- package/resources/content/releases/releases.js.map +1 -1
- package/resources/content/releases/releases.mjs +1 -1
- package/resources/content/releases/releases.mjs.map +1 -1
- package/resources/email/email.d.mts +215 -0
- package/resources/email/email.d.mts.map +1 -0
- package/resources/email/email.d.ts +215 -0
- package/resources/email/email.d.ts.map +1 -0
- package/resources/email/email.js +43 -0
- package/resources/email/email.js.map +1 -0
- package/resources/email/email.mjs +38 -0
- package/resources/email/email.mjs.map +1 -0
- package/resources/email/identities.d.mts +145 -0
- package/resources/email/identities.d.mts.map +1 -0
- package/resources/email/identities.d.ts +145 -0
- package/resources/email/identities.d.ts.map +1 -0
- package/resources/email/identities.js +51 -0
- package/resources/email/identities.js.map +1 -0
- package/resources/email/identities.mjs +47 -0
- package/resources/email/identities.mjs.map +1 -0
- package/resources/email/index.d.mts +3 -0
- package/resources/email/index.d.mts.map +1 -0
- package/resources/email/index.d.ts +3 -0
- package/resources/email/index.d.ts.map +1 -0
- package/resources/email/index.js +9 -0
- package/resources/email/index.js.map +1 -0
- package/resources/email/index.mjs +4 -0
- package/resources/email/index.mjs.map +1 -0
- package/resources/email.d.mts +2 -0
- package/resources/email.d.mts.map +1 -0
- package/resources/email.d.ts +2 -0
- package/resources/email.d.ts.map +1 -0
- package/resources/email.js +6 -0
- package/resources/email.js.map +1 -0
- package/resources/email.mjs +3 -0
- package/resources/email.mjs.map +1 -0
- package/resources/index.d.mts +1 -0
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -0
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +3 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -0
- package/resources/index.mjs.map +1 -1
- package/src/client.ts +46 -10
- package/src/internal/utils/query.ts +7 -0
- package/src/internal/utils.ts +1 -0
- package/src/resources/commerce/coupons.ts +1 -5
- package/src/resources/commerce/customers.ts +3 -7
- package/src/resources/commerce/features.ts +1 -5
- package/src/resources/commerce/products/products.ts +1 -5
- package/src/resources/content/assets.ts +1 -5
- package/src/resources/content/collections/collections.ts +1 -1
- package/src/resources/content/entries.ts +2 -10
- package/src/resources/content/locales.ts +1 -5
- package/src/resources/content/releases/releases.ts +1 -5
- package/src/resources/email/email.ts +292 -0
- package/src/resources/email/identities.ts +198 -0
- package/src/resources/email/index.ts +20 -0
- package/src/resources/email.ts +3 -0
- package/src/resources/index.ts +10 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/client.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { APIResponseProps } from './internal/parse';
|
|
|
11
11
|
import { getPlatformHeaders } from './internal/detect-platform';
|
|
12
12
|
import * as Shims from './internal/shims';
|
|
13
13
|
import * as Opts from './internal/request-options';
|
|
14
|
-
import
|
|
14
|
+
import { stringifyQuery } from './internal/utils/query';
|
|
15
15
|
import { VERSION } from './version';
|
|
16
16
|
import * as Errors from './core/error';
|
|
17
17
|
import * as Pagination from './core/pagination';
|
|
@@ -32,6 +32,16 @@ import {
|
|
|
32
32
|
Currency,
|
|
33
33
|
} from './resources/commerce/commerce';
|
|
34
34
|
import { Content } from './resources/content/content';
|
|
35
|
+
import {
|
|
36
|
+
Attachment,
|
|
37
|
+
Email,
|
|
38
|
+
EmailGetResponse,
|
|
39
|
+
EmailListParams,
|
|
40
|
+
EmailResource,
|
|
41
|
+
EmailSendParams,
|
|
42
|
+
EmailSendResponse,
|
|
43
|
+
EmailsCursorIDPage,
|
|
44
|
+
} from './resources/email/email';
|
|
35
45
|
import {
|
|
36
46
|
PushNotificationEnableResponse,
|
|
37
47
|
PushNotificationIdentifyParams,
|
|
@@ -254,8 +264,8 @@ export class Hercules {
|
|
|
254
264
|
return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);
|
|
255
265
|
}
|
|
256
266
|
|
|
257
|
-
protected stringifyQuery(query: Record<string, unknown>): string {
|
|
258
|
-
return
|
|
267
|
+
protected stringifyQuery(query: object | Record<string, unknown>): string {
|
|
268
|
+
return stringifyQuery(query);
|
|
259
269
|
}
|
|
260
270
|
|
|
261
271
|
private getUserAgent(): string {
|
|
@@ -287,12 +297,13 @@ export class Hercules {
|
|
|
287
297
|
: new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
|
|
288
298
|
|
|
289
299
|
const defaultQuery = this.defaultQuery();
|
|
290
|
-
|
|
291
|
-
|
|
300
|
+
const pathQuery = Object.fromEntries(url.searchParams);
|
|
301
|
+
if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
|
|
302
|
+
query = { ...pathQuery, ...defaultQuery, ...query };
|
|
292
303
|
}
|
|
293
304
|
|
|
294
305
|
if (typeof query === 'object' && query && !Array.isArray(query)) {
|
|
295
|
-
url.search = this.stringifyQuery(query
|
|
306
|
+
url.search = this.stringifyQuery(query);
|
|
296
307
|
}
|
|
297
308
|
|
|
298
309
|
return url.toString();
|
|
@@ -476,7 +487,7 @@ export class Hercules {
|
|
|
476
487
|
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
|
477
488
|
|
|
478
489
|
const errText = await response.text().catch((err: any) => castToError(err).message);
|
|
479
|
-
const errJSON = safeJSON(errText);
|
|
490
|
+
const errJSON = safeJSON(errText) as any;
|
|
480
491
|
const errMessage = errJSON ? undefined : errText;
|
|
481
492
|
|
|
482
493
|
loggerFor(this).debug(
|
|
@@ -621,9 +632,9 @@ export class Hercules {
|
|
|
621
632
|
}
|
|
622
633
|
}
|
|
623
634
|
|
|
624
|
-
// If the API asks us to wait a certain amount of time
|
|
625
|
-
//
|
|
626
|
-
if (
|
|
635
|
+
// If the API asks us to wait a certain amount of time, just do what it
|
|
636
|
+
// says, but otherwise calculate a default
|
|
637
|
+
if (timeoutMillis === undefined) {
|
|
627
638
|
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
628
639
|
timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
|
|
629
640
|
}
|
|
@@ -750,6 +761,14 @@ export class Hercules {
|
|
|
750
761
|
(Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
|
|
751
762
|
) {
|
|
752
763
|
return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
|
|
764
|
+
} else if (
|
|
765
|
+
typeof body === 'object' &&
|
|
766
|
+
headers.values.get('content-type') === 'application/x-www-form-urlencoded'
|
|
767
|
+
) {
|
|
768
|
+
return {
|
|
769
|
+
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
770
|
+
body: this.stringifyQuery(body),
|
|
771
|
+
};
|
|
753
772
|
} else {
|
|
754
773
|
return this.#encoder({ body, headers });
|
|
755
774
|
}
|
|
@@ -787,6 +806,11 @@ export class Hercules {
|
|
|
787
806
|
* and SSL status.
|
|
788
807
|
*/
|
|
789
808
|
domains: API.Domains = new API.Domains(this);
|
|
809
|
+
/**
|
|
810
|
+
* Send transactional emails, send batch emails, and retrieve sent email
|
|
811
|
+
* history with delivery status tracking.
|
|
812
|
+
*/
|
|
813
|
+
email: API.EmailResource = new API.EmailResource(this);
|
|
790
814
|
/**
|
|
791
815
|
* Upload, retrieve, and list files and media associated with a website.
|
|
792
816
|
* Upload is a two-step process: first call create to get an upload URL,
|
|
@@ -800,6 +824,7 @@ export class Hercules {
|
|
|
800
824
|
Hercules.Commerce = Commerce;
|
|
801
825
|
Hercules.Content = Content;
|
|
802
826
|
Hercules.Domains = Domains;
|
|
827
|
+
Hercules.EmailResource = EmailResource;
|
|
803
828
|
Hercules.Files = Files;
|
|
804
829
|
Hercules.PushNotifications = PushNotifications;
|
|
805
830
|
|
|
@@ -829,6 +854,17 @@ export declare namespace Hercules {
|
|
|
829
854
|
type DomainListParams as DomainListParams,
|
|
830
855
|
};
|
|
831
856
|
|
|
857
|
+
export {
|
|
858
|
+
EmailResource as EmailResource,
|
|
859
|
+
type Attachment as Attachment,
|
|
860
|
+
type Email as Email,
|
|
861
|
+
type EmailGetResponse as EmailGetResponse,
|
|
862
|
+
type EmailSendResponse as EmailSendResponse,
|
|
863
|
+
type EmailsCursorIDPage as EmailsCursorIDPage,
|
|
864
|
+
type EmailListParams as EmailListParams,
|
|
865
|
+
type EmailSendParams as EmailSendParams,
|
|
866
|
+
};
|
|
867
|
+
|
|
832
868
|
export {
|
|
833
869
|
Files as Files,
|
|
834
870
|
type File as File,
|
package/src/internal/utils.ts
CHANGED
|
@@ -35,11 +35,7 @@ export class Coupons extends APIResource {
|
|
|
35
35
|
* );
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
update(
|
|
39
|
-
couponID: string,
|
|
40
|
-
body: CouponUpdateParams | null | undefined = {},
|
|
41
|
-
options?: RequestOptions,
|
|
42
|
-
): APIPromise<Coupon> {
|
|
38
|
+
update(couponID: string, body: CouponUpdateParams, options?: RequestOptions): APIPromise<Coupon> {
|
|
43
39
|
return this._client.patch(path`/v1/commerce/coupons/${couponID}`, { body, ...options });
|
|
44
40
|
}
|
|
45
41
|
|
|
@@ -18,7 +18,7 @@ export class Customers extends APIResource {
|
|
|
18
18
|
* const customer = await client.commerce.customers.create();
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
-
create(body: CustomerCreateParams
|
|
21
|
+
create(body: CustomerCreateParams, options?: RequestOptions): APIPromise<Customer> {
|
|
22
22
|
return this._client.post('/v1/commerce/customers', { body, ...options });
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -33,11 +33,7 @@ export class Customers extends APIResource {
|
|
|
33
33
|
* );
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
update(
|
|
37
|
-
customerID: string,
|
|
38
|
-
body: CustomerUpdateParams | null | undefined = {},
|
|
39
|
-
options?: RequestOptions,
|
|
40
|
-
): APIPromise<Customer> {
|
|
36
|
+
update(customerID: string, body: CustomerUpdateParams, options?: RequestOptions): APIPromise<Customer> {
|
|
41
37
|
return this._client.patch(path`/v1/commerce/customers/${customerID}`, { body, ...options });
|
|
42
38
|
}
|
|
43
39
|
|
|
@@ -75,7 +71,7 @@ export class Customers extends APIResource {
|
|
|
75
71
|
*/
|
|
76
72
|
billingPortal(
|
|
77
73
|
customerID: string,
|
|
78
|
-
body: CustomerBillingPortalParams
|
|
74
|
+
body: CustomerBillingPortalParams,
|
|
79
75
|
options?: RequestOptions,
|
|
80
76
|
): APIPromise<CustomerBillingPortalResponse> {
|
|
81
77
|
return this._client.post(path`/v1/commerce/customers/${customerID}/billing_portal`, { body, ...options });
|
|
@@ -33,11 +33,7 @@ export class Features extends APIResource {
|
|
|
33
33
|
* );
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
update(
|
|
37
|
-
featureID: string,
|
|
38
|
-
body: FeatureUpdateParams | null | undefined = {},
|
|
39
|
-
options?: RequestOptions,
|
|
40
|
-
): APIPromise<Feature> {
|
|
36
|
+
update(featureID: string, body: FeatureUpdateParams, options?: RequestOptions): APIPromise<Feature> {
|
|
41
37
|
return this._client.patch(path`/v1/commerce/features/${featureID}`, { body, ...options });
|
|
42
38
|
}
|
|
43
39
|
|
|
@@ -61,11 +61,7 @@ export class Products extends APIResource {
|
|
|
61
61
|
* );
|
|
62
62
|
* ```
|
|
63
63
|
*/
|
|
64
|
-
update(
|
|
65
|
-
productID: string,
|
|
66
|
-
body: ProductUpdateParams | null | undefined = {},
|
|
67
|
-
options?: RequestOptions,
|
|
68
|
-
): APIPromise<Product> {
|
|
64
|
+
update(productID: string, body: ProductUpdateParams, options?: RequestOptions): APIPromise<Product> {
|
|
69
65
|
return this._client.patch(path`/v1/commerce/products/${productID}`, { body, ...options });
|
|
70
66
|
}
|
|
71
67
|
|
|
@@ -21,11 +21,7 @@ export class Assets extends APIResource {
|
|
|
21
21
|
* Updates asset metadata including URL, folder, title, description, and custom
|
|
22
22
|
* metadata.
|
|
23
23
|
*/
|
|
24
|
-
update(
|
|
25
|
-
assetID: string,
|
|
26
|
-
body: AssetUpdateParams | null | undefined = {},
|
|
27
|
-
options?: RequestOptions,
|
|
28
|
-
): APIPromise<Asset> {
|
|
24
|
+
update(assetID: string, body: AssetUpdateParams, options?: RequestOptions): APIPromise<Asset> {
|
|
29
25
|
return this._client.patch(path`/v1/content/assets/${assetID}`, { body, ...options });
|
|
30
26
|
}
|
|
31
27
|
|
|
@@ -26,7 +26,7 @@ export class Collections extends APIResource {
|
|
|
26
26
|
*/
|
|
27
27
|
update(
|
|
28
28
|
collectionID: string,
|
|
29
|
-
body: CollectionUpdateParams
|
|
29
|
+
body: CollectionUpdateParams,
|
|
30
30
|
options?: RequestOptions,
|
|
31
31
|
): APIPromise<Collection> {
|
|
32
32
|
return this._client.patch(path`/v1/content/collections/${collectionID}`, { body, ...options });
|
|
@@ -20,11 +20,7 @@ export class Entries extends APIResource {
|
|
|
20
20
|
* fields are modified. Use the version parameter for optimistic locking to prevent
|
|
21
21
|
* concurrent update conflicts.
|
|
22
22
|
*/
|
|
23
|
-
update(
|
|
24
|
-
entryID: string,
|
|
25
|
-
body: EntryUpdateParams | null | undefined = {},
|
|
26
|
-
options?: RequestOptions,
|
|
27
|
-
): APIPromise<Entry> {
|
|
23
|
+
update(entryID: string, body: EntryUpdateParams, options?: RequestOptions): APIPromise<Entry> {
|
|
28
24
|
return this._client.patch(path`/v1/content/entries/${entryID}`, { body, ...options });
|
|
29
25
|
}
|
|
30
26
|
|
|
@@ -61,11 +57,7 @@ export class Entries extends APIResource {
|
|
|
61
57
|
* publishing for a future time. Publishing validates that all required fields have
|
|
62
58
|
* values.
|
|
63
59
|
*/
|
|
64
|
-
publish(
|
|
65
|
-
entryID: string,
|
|
66
|
-
body: EntryPublishParams | null | undefined = {},
|
|
67
|
-
options?: RequestOptions,
|
|
68
|
-
): APIPromise<Entry> {
|
|
60
|
+
publish(entryID: string, body: EntryPublishParams, options?: RequestOptions): APIPromise<Entry> {
|
|
69
61
|
return this._client.post(path`/v1/content/entries/${entryID}/publish`, { body, ...options });
|
|
70
62
|
}
|
|
71
63
|
|
|
@@ -20,11 +20,7 @@ export class Locales extends APIResource {
|
|
|
20
20
|
* Updates a locale's configuration including name, fallback, default status, and
|
|
21
21
|
* active status.
|
|
22
22
|
*/
|
|
23
|
-
update(
|
|
24
|
-
localeCode: string,
|
|
25
|
-
body: LocaleUpdateParams | null | undefined = {},
|
|
26
|
-
options?: RequestOptions,
|
|
27
|
-
): APIPromise<Locale> {
|
|
23
|
+
update(localeCode: string, body: LocaleUpdateParams, options?: RequestOptions): APIPromise<Locale> {
|
|
28
24
|
return this._client.patch(path`/v1/content/locales/${localeCode}`, { body, ...options });
|
|
29
25
|
}
|
|
30
26
|
|
|
@@ -23,11 +23,7 @@ export class Releases extends APIResource {
|
|
|
23
23
|
/**
|
|
24
24
|
* Updates a release name and description. Only draft releases can be updated.
|
|
25
25
|
*/
|
|
26
|
-
update(
|
|
27
|
-
releaseID: string,
|
|
28
|
-
body: ReleaseUpdateParams | null | undefined = {},
|
|
29
|
-
options?: RequestOptions,
|
|
30
|
-
): APIPromise<Release> {
|
|
26
|
+
update(releaseID: string, body: ReleaseUpdateParams, options?: RequestOptions): APIPromise<Release> {
|
|
31
27
|
return this._client.patch(path`/v1/content/releases/${releaseID}`, { body, ...options });
|
|
32
28
|
}
|
|
33
29
|
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../../core/resource';
|
|
4
|
+
import * as IdentitiesAPI from './identities';
|
|
5
|
+
import {
|
|
6
|
+
Identities,
|
|
7
|
+
IdentitiesCursorIDPage,
|
|
8
|
+
Identity,
|
|
9
|
+
IdentityCreateParams,
|
|
10
|
+
IdentityListParams,
|
|
11
|
+
IdentityVerifyParams,
|
|
12
|
+
} from './identities';
|
|
13
|
+
import { APIPromise } from '../../core/api-promise';
|
|
14
|
+
import { CursorIDPage, type CursorIDPageParams, PagePromise } from '../../core/pagination';
|
|
15
|
+
import { RequestOptions } from '../../internal/request-options';
|
|
16
|
+
import { path } from '../../internal/utils/path';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Send transactional emails, send batch emails, and retrieve sent email
|
|
20
|
+
* history with delivery status tracking.
|
|
21
|
+
*/
|
|
22
|
+
export class EmailResource extends APIResource {
|
|
23
|
+
identities: IdentitiesAPI.Identities = new IdentitiesAPI.Identities(this._client);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves a paginated list of sent emails. Returns email metadata including
|
|
27
|
+
* delivery status.
|
|
28
|
+
*/
|
|
29
|
+
list(
|
|
30
|
+
query: EmailListParams | null | undefined = {},
|
|
31
|
+
options?: RequestOptions,
|
|
32
|
+
): PagePromise<EmailsCursorIDPage, Email> {
|
|
33
|
+
return this._client.getAPIList('/v1/email', CursorIDPage<Email>, { query, ...options });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves a single email by its unique identifier.
|
|
38
|
+
*/
|
|
39
|
+
get(emailID: string, options?: RequestOptions): APIPromise<EmailGetResponse> {
|
|
40
|
+
return this._client.get(path`/v1/email/${emailID}`, options);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Sends a single email. The sender address must be a verified identity for this
|
|
45
|
+
* website.
|
|
46
|
+
*/
|
|
47
|
+
send(body: EmailSendParams, options?: RequestOptions): APIPromise<EmailSendResponse> {
|
|
48
|
+
return this._client.post('/v1/email', { body, ...options });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type EmailsCursorIDPage = CursorIDPage<Email>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A file attachment
|
|
56
|
+
*/
|
|
57
|
+
export interface Attachment {
|
|
58
|
+
/**
|
|
59
|
+
* The Base64-encoded content of the attachment. Max 40MB total per email.
|
|
60
|
+
*/
|
|
61
|
+
content: string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The name of the attached file
|
|
65
|
+
*/
|
|
66
|
+
filename: string;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The MIME type of the attachment
|
|
70
|
+
*/
|
|
71
|
+
content_type?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A sent email object
|
|
76
|
+
*/
|
|
77
|
+
export interface Email {
|
|
78
|
+
/**
|
|
79
|
+
* Unique identifier for the email
|
|
80
|
+
*/
|
|
81
|
+
id: string;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Timestamp when the email was sent
|
|
85
|
+
*/
|
|
86
|
+
created_at: string;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Sender email address
|
|
90
|
+
*/
|
|
91
|
+
from: string;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Email subject line
|
|
95
|
+
*/
|
|
96
|
+
subject: string;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Recipient email addresses
|
|
100
|
+
*/
|
|
101
|
+
to: Array<string>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Blind carbon copy recipients
|
|
105
|
+
*/
|
|
106
|
+
bcc?: Array<string> | null;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Carbon copy recipients
|
|
110
|
+
*/
|
|
111
|
+
cc?: Array<string> | null;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The most recent event for this email
|
|
115
|
+
*/
|
|
116
|
+
last_event?: 'sent' | 'delivered' | 'opened' | 'clicked' | 'bounced' | 'complained' | null;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Reply-to addresses
|
|
120
|
+
*/
|
|
121
|
+
reply_to?: Array<string> | null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* A sent email object with full body content
|
|
126
|
+
*/
|
|
127
|
+
export interface EmailGetResponse {
|
|
128
|
+
/**
|
|
129
|
+
* Unique identifier for the email
|
|
130
|
+
*/
|
|
131
|
+
id: string;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Timestamp when the email was sent
|
|
135
|
+
*/
|
|
136
|
+
created_at: string;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Sender email address
|
|
140
|
+
*/
|
|
141
|
+
from: string;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Email subject line
|
|
145
|
+
*/
|
|
146
|
+
subject: string;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Recipient email addresses
|
|
150
|
+
*/
|
|
151
|
+
to: Array<string>;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Blind carbon copy recipients
|
|
155
|
+
*/
|
|
156
|
+
bcc?: Array<string> | null;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Carbon copy recipients
|
|
160
|
+
*/
|
|
161
|
+
cc?: Array<string> | null;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The HTML version of the message body
|
|
165
|
+
*/
|
|
166
|
+
html?: string | null;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The most recent event for this email
|
|
170
|
+
*/
|
|
171
|
+
last_event?: 'sent' | 'delivered' | 'opened' | 'clicked' | 'bounced' | 'complained' | null;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Reply-to addresses
|
|
175
|
+
*/
|
|
176
|
+
reply_to?: Array<string> | null;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* The plain text version of the message body
|
|
180
|
+
*/
|
|
181
|
+
text?: string | null;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Response after sending an email
|
|
186
|
+
*/
|
|
187
|
+
export interface EmailSendResponse {
|
|
188
|
+
/**
|
|
189
|
+
* The unique identifier of the sent email
|
|
190
|
+
*/
|
|
191
|
+
id: string;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface EmailListParams extends CursorIDPageParams {}
|
|
195
|
+
|
|
196
|
+
export interface EmailSendParams {
|
|
197
|
+
/**
|
|
198
|
+
* Sender email address. To include a friendly name, use the format 'Your Name
|
|
199
|
+
* <sender@domain.com>'.
|
|
200
|
+
*/
|
|
201
|
+
from: string;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Email subject line
|
|
205
|
+
*/
|
|
206
|
+
subject: string;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Recipient email address(es). Maximum 50.
|
|
210
|
+
*/
|
|
211
|
+
to: string | Array<string>;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* List of file attachments. Total size must not exceed 40MB after Base64 encoding.
|
|
215
|
+
*/
|
|
216
|
+
attachments?: Array<Attachment>;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Blind carbon copy recipient(s)
|
|
220
|
+
*/
|
|
221
|
+
bcc?: string | Array<string>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Carbon copy recipient(s)
|
|
225
|
+
*/
|
|
226
|
+
cc?: string | Array<string>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Custom email headers as key-value pairs
|
|
230
|
+
*/
|
|
231
|
+
headers?: { [key: string]: string };
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* The HTML version of the message body
|
|
235
|
+
*/
|
|
236
|
+
html?: string;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Reply-to email address(es)
|
|
240
|
+
*/
|
|
241
|
+
reply_to?: string | Array<string>;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Custom metadata tags for the email (max 50)
|
|
245
|
+
*/
|
|
246
|
+
tags?: Array<EmailSendParams.Tag>;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* The plain text version of the message body
|
|
250
|
+
*/
|
|
251
|
+
text?: string;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export namespace EmailSendParams {
|
|
255
|
+
/**
|
|
256
|
+
* A custom metadata tag for the email
|
|
257
|
+
*/
|
|
258
|
+
export interface Tag {
|
|
259
|
+
/**
|
|
260
|
+
* The name of the tag
|
|
261
|
+
*/
|
|
262
|
+
name: string;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The value of the tag
|
|
266
|
+
*/
|
|
267
|
+
value: string;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
EmailResource.Identities = Identities;
|
|
272
|
+
|
|
273
|
+
export declare namespace EmailResource {
|
|
274
|
+
export {
|
|
275
|
+
type Attachment as Attachment,
|
|
276
|
+
type Email as Email,
|
|
277
|
+
type EmailGetResponse as EmailGetResponse,
|
|
278
|
+
type EmailSendResponse as EmailSendResponse,
|
|
279
|
+
type EmailsCursorIDPage as EmailsCursorIDPage,
|
|
280
|
+
type EmailListParams as EmailListParams,
|
|
281
|
+
type EmailSendParams as EmailSendParams,
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
export {
|
|
285
|
+
Identities as Identities,
|
|
286
|
+
type Identity as Identity,
|
|
287
|
+
type IdentitiesCursorIDPage as IdentitiesCursorIDPage,
|
|
288
|
+
type IdentityCreateParams as IdentityCreateParams,
|
|
289
|
+
type IdentityListParams as IdentityListParams,
|
|
290
|
+
type IdentityVerifyParams as IdentityVerifyParams,
|
|
291
|
+
};
|
|
292
|
+
}
|