@azure/communication-email 1.0.0-alpha.20230127.1 → 1.0.0-alpha.20230224.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. package/README.md +24 -32
  2. package/dist/index.js +220 -155
  3. package/dist/index.js.map +1 -1
  4. package/dist-esm/samples-dev/sendEmailMultipleRecipients.js +10 -8
  5. package/dist-esm/samples-dev/sendEmailMultipleRecipients.js.map +1 -1
  6. package/dist-esm/samples-dev/sendEmailSingleRecipient.js +7 -5
  7. package/dist-esm/samples-dev/sendEmailSingleRecipient.js.map +1 -1
  8. package/dist-esm/samples-dev/sendEmailWithAttachments.js +9 -7
  9. package/dist-esm/samples-dev/sendEmailWithAttachments.js.map +1 -1
  10. package/dist-esm/src/emailClient.js +4 -19
  11. package/dist-esm/src/emailClient.js.map +1 -1
  12. package/dist-esm/src/generated/src/emailRestApiClient.js +1 -1
  13. package/dist-esm/src/generated/src/emailRestApiClient.js.map +1 -1
  14. package/dist-esm/src/generated/src/lroImpl.js +25 -0
  15. package/dist-esm/src/generated/src/lroImpl.js.map +1 -0
  16. package/dist-esm/src/generated/src/models/index.js +14 -80
  17. package/dist-esm/src/generated/src/models/index.js.map +1 -1
  18. package/dist-esm/src/generated/src/models/mappers.js +77 -87
  19. package/dist-esm/src/generated/src/models/mappers.js.map +1 -1
  20. package/dist-esm/src/generated/src/models/parameters.js +14 -16
  21. package/dist-esm/src/generated/src/models/parameters.js.map +1 -1
  22. package/dist-esm/src/generated/src/operations/email.js +72 -26
  23. package/dist-esm/src/generated/src/operations/email.js.map +1 -1
  24. package/dist-esm/src/generated/src/operationsInterfaces/email.js.map +1 -1
  25. package/dist-esm/src/models.js +1 -1
  26. package/dist-esm/src/models.js.map +1 -1
  27. package/dist-esm/test/public/emailClient.spec.js +25 -75
  28. package/dist-esm/test/public/emailClient.spec.js.map +1 -1
  29. package/dist-esm/test/public/utils/recordedClient.js +9 -13
  30. package/dist-esm/test/public/utils/recordedClient.js.map +1 -1
  31. package/package.json +2 -1
  32. package/types/communication-email.d.ts +136 -104
  33. package/dist-esm/samples-dev/checkMessageStatus.js +0 -41
  34. package/dist-esm/samples-dev/checkMessageStatus.js.map +0 -1
@@ -1,11 +1,14 @@
1
1
  import { CommonClientOptions } from '@azure/core-client';
2
2
  import { KeyCredential } from '@azure/core-auth';
3
+ import { OperationOptions } from '@azure/core-client';
4
+ import { PollerLike } from '@azure/core-lro';
5
+ import { PollOperationState } from '@azure/core-lro';
3
6
  import { TokenCredential } from '@azure/core-auth';
4
7
 
5
8
  /** An object representing the email address and its display name */
6
9
  export declare interface EmailAddress {
7
10
  /** Email address. */
8
- email: string;
11
+ address: string;
9
12
  /** Email display name. */
10
13
  displayName?: string;
11
14
  }
@@ -14,48 +17,12 @@ export declare interface EmailAddress {
14
17
  export declare interface EmailAttachment {
15
18
  /** Name of the attachment */
16
19
  name: string;
17
- /** The type of attachment file. */
18
- attachmentType: EmailAttachmentType;
20
+ /** MIME type of the content being attached. */
21
+ contentType: string;
19
22
  /** Base64 encoded contents of the attachment */
20
- contentBytesBase64: string;
23
+ contentInBase64: string;
21
24
  }
22
25
 
23
- /**
24
- * Defines values for EmailAttachmentType. \
25
- * {@link KnownEmailAttachmentType} can be used interchangeably with EmailAttachmentType,
26
- * this enum contains the known values that the service supports.
27
- * ### Known values supported by the service
28
- * **avi** \
29
- * **bmp** \
30
- * **doc** \
31
- * **docm** \
32
- * **docx** \
33
- * **gif** \
34
- * **jpeg** \
35
- * **mp3** \
36
- * **one** \
37
- * **pdf** \
38
- * **png** \
39
- * **ppsm** \
40
- * **ppsx** \
41
- * **ppt** \
42
- * **pptm** \
43
- * **pptx** \
44
- * **pub** \
45
- * **rpmsg** \
46
- * **rtf** \
47
- * **tif** \
48
- * **txt** \
49
- * **vsd** \
50
- * **wav** \
51
- * **wma** \
52
- * **xls** \
53
- * **xlsb** \
54
- * **xlsm** \
55
- * **xlsx**
56
- */
57
- export declare type EmailAttachmentType = string;
58
-
59
26
  /**
60
27
  * The Email service client.
61
28
  */
@@ -74,34 +41,26 @@ export declare class EmailClient {
74
41
  * @param credential - An object that is used to authenticate requests to the service. Use the Azure KeyCredential or `@azure/identity` to create a credential.
75
42
  * @param options - Optional. Options to configure the HTTP pipeline.
76
43
  */
77
- constructor(endpoint: string, credential: KeyCredential, options?: EmailClientOptions);
78
- /**
79
- * Initializes a new instance of the EmailClient class using a TokenCredential.
80
- * @param endpoint - The endpoint of the service (ex: https://contoso.eastus.communications.azure.net).
81
- * @param credential - TokenCredential that is used to authenticate requests to the service. Use the Azure KeyCredential or `@azure/identity` to create a credential.
82
- * @param options - Optional. Options to configure the HTTP pipeline.
83
- */
84
- constructor(endpoint: string, credential: TokenCredential, options?: EmailClientOptions);
44
+ constructor(endpoint: string, credential: KeyCredential | TokenCredential, options?: EmailClientOptions);
85
45
  /**
86
46
  * Queues an email message to be sent to one or more recipients
87
- * @param emailMessage - Message payload for sending an email
88
- */
89
- send(emailMessage: EmailMessage): Promise<SendEmailResult>;
90
- /**
91
- * Gets the status of a message sent previously.
92
- * @param messageId - System generated message id (GUID) returned from a previous call to send email
47
+ * @param message - Message payload for sending an email
48
+ * @param options - The options parameters.
93
49
  */
94
- getSendStatus(messageId: string): Promise<SendStatusResult>;
50
+ beginSend(message: EmailMessage, options?: EmailSendOptionalParams): Promise<PollerLike<PollOperationState<EmailSendResponse>, EmailSendResponse>>;
95
51
  }
96
52
 
97
53
  /**
98
- * Client options used to configure SMS Client API requests.
54
+ * Client options used to configure Email Client API requests.
99
55
  */
100
56
  export declare interface EmailClientOptions extends CommonClientOptions {
101
57
  }
102
58
 
103
59
  /** Content of the email. */
104
- export declare interface EmailContent {
60
+ export declare type EmailContent = HtmlEmailContent | PlainTextEmailContent;
61
+
62
+ /** Content of the email. */
63
+ declare interface EmailContent_2 {
105
64
  /** Subject of the email message */
106
65
  subject: string;
107
66
  /** Plain text version of the email message. */
@@ -110,43 +69,24 @@ export declare interface EmailContent {
110
69
  html?: string;
111
70
  }
112
71
 
113
- /** Custom header for email. */
114
- export declare interface EmailCustomHeader {
115
- /** Header name. */
116
- name: string;
117
- /** Header value. */
118
- value: string;
119
- }
120
-
121
- /**
122
- * Defines values for EmailImportance. \
123
- * {@link KnownEmailImportance} can be used interchangeably with EmailImportance,
124
- * this enum contains the known values that the service supports.
125
- * ### Known values supported by the service
126
- * **high** \
127
- * **normal** \
128
- * **low**
129
- */
130
- export declare type EmailImportance = string;
131
-
132
72
  /** Message payload for sending an email */
133
73
  export declare interface EmailMessage {
134
74
  /** Custom email headers to be passed. */
135
- customHeaders?: EmailCustomHeader[];
75
+ headers?: {
76
+ [propertyName: string]: string;
77
+ };
136
78
  /** Sender email address from a verified domain. */
137
- sender: string;
79
+ senderAddress: string;
138
80
  /** Email content to be sent. */
139
- content: EmailContent;
140
- /** The importance type for the email. */
141
- importance?: EmailImportance;
81
+ content: EmailContent_2;
142
82
  /** Recipients for the email. */
143
83
  recipients: EmailRecipients;
144
- /** list of attachments */
84
+ /** List of attachments. Please note that we limit the total size of an email request (which includes attachments) to 10MB. */
145
85
  attachments?: EmailAttachment[];
146
86
  /** Email addresses where recipients' replies will be sent to. */
147
87
  replyTo?: EmailAddress[];
148
88
  /** Indicates whether user engagement tracking should be disabled for this request if the resource-level user engagement tracking setting was already enabled in the control plane. */
149
- disableUserEngagementTracking?: boolean;
89
+ userEngagementTrackingDisabled?: boolean;
150
90
  }
151
91
 
152
92
  /** Recipients of the email */
@@ -159,33 +99,125 @@ export declare interface EmailRecipients {
159
99
  bcc?: EmailAddress[];
160
100
  }
161
101
 
162
- /**
163
- * Results of a sent email.
164
- */
165
- export declare interface SendEmailResult {
166
- /**
167
- * MessageId of the sent email.
168
- */
169
- messageId: string;
102
+ /** Defines headers for Email_send operation. */
103
+ export declare interface EmailSendHeaders {
104
+ /** Location url of where to poll the status of this operation from. */
105
+ operationLocation?: string;
106
+ /** This header will only be present when the operation status is a non-terminal status. It indicates the minimum amount of time in seconds to wait before polling for operation status again. */
107
+ retryAfter?: number;
108
+ }
109
+
110
+ /** Optional parameters for the beginSend method. */
111
+ export declare interface EmailSendOptionalParams extends OperationOptions {
112
+ /** This is the ID used by the status monitor for this long running operation. */
113
+ operationId?: string;
114
+ /** Delay to wait until next poll, in milliseconds. */
115
+ updateIntervalInMs?: number;
116
+ /** A serialized poller which can be used to resume an existing paused Long-Running-Operation. */
117
+ resumeFrom?: string;
118
+ }
119
+
120
+ /** Contains response data for the send operation. */
121
+ export declare type EmailSendResponse = EmailSendHeaders & EmailSendResult;
122
+
123
+ /** Status of the long running operation */
124
+ export declare interface EmailSendResult {
125
+ /** The unique id of the operation. Use a UUID. */
126
+ id: string;
127
+ /** Status of operation. */
128
+ status: EmailSendStatus;
129
+ /** Error details when status is a non-success terminal state. */
130
+ error?: ErrorDetail;
170
131
  }
171
132
 
172
133
  /**
173
- * Defines values for SendStatus. \
174
- * {@link KnownSendStatus} can be used interchangeably with SendStatus,
134
+ * Defines values for EmailSendStatus. \
135
+ * {@link KnownEmailSendStatus} can be used interchangeably with EmailSendStatus,
175
136
  * this enum contains the known values that the service supports.
176
137
  * ### Known values supported by the service
177
- * **queued**: The message has passed basic validations and has been queued to be processed further. \
178
- * **outForDelivery**: The message has been processed and is now out for delivery. \
179
- * **dropped**: The message could not be processed and was dropped.
138
+ * **NotStarted** \
139
+ * **Running** \
140
+ * **Succeeded** \
141
+ * **Failed** \
142
+ * **Canceled**
180
143
  */
181
- export declare type SendStatus = string;
182
-
183
- /** Status of an email message that was sent previously. */
184
- export declare interface SendStatusResult {
185
- /** System generated id of an email message sent. */
186
- messageId: string;
187
- /** The type indicating the status of a request. */
188
- status: SendStatus;
144
+ export declare type EmailSendStatus = string;
145
+
146
+ /** The resource management error additional info. */
147
+ export declare interface ErrorAdditionalInfo {
148
+ /**
149
+ * The additional info type.
150
+ * NOTE: This property will not be serialized. It can only be populated by the server.
151
+ */
152
+ readonly type?: string;
153
+ /**
154
+ * The additional info.
155
+ * NOTE: This property will not be serialized. It can only be populated by the server.
156
+ */
157
+ readonly info?: Record<string, unknown>;
158
+ }
159
+
160
+ /** The error detail. */
161
+ export declare interface ErrorDetail {
162
+ /**
163
+ * The error code.
164
+ * NOTE: This property will not be serialized. It can only be populated by the server.
165
+ */
166
+ readonly code?: string;
167
+ /**
168
+ * The error message.
169
+ * NOTE: This property will not be serialized. It can only be populated by the server.
170
+ */
171
+ readonly message?: string;
172
+ /**
173
+ * The error target.
174
+ * NOTE: This property will not be serialized. It can only be populated by the server.
175
+ */
176
+ readonly target?: string;
177
+ /**
178
+ * The error details.
179
+ * NOTE: This property will not be serialized. It can only be populated by the server.
180
+ */
181
+ readonly details?: ErrorDetail[];
182
+ /**
183
+ * The error additional info.
184
+ * NOTE: This property will not be serialized. It can only be populated by the server.
185
+ */
186
+ readonly additionalInfo?: ErrorAdditionalInfo[];
187
+ }
188
+
189
+ /** Content of the email with a required html property. */
190
+ export declare interface HtmlEmailContent {
191
+ /** Subject of the email message */
192
+ subject: string;
193
+ /** Plain text version of the email message. */
194
+ plainText?: string;
195
+ /** Html version of the email message. */
196
+ html: string;
197
+ }
198
+
199
+ /** Known values of {@link EmailSendStatus} that the service accepts. */
200
+ export declare enum KnownEmailSendStatus {
201
+ /** NotStarted */
202
+ NotStarted = "NotStarted",
203
+ /** Running */
204
+ Running = "Running",
205
+ /** Succeeded */
206
+ Succeeded = "Succeeded",
207
+ /** Failed */
208
+ Failed = "Failed",
209
+ /** Canceled */
210
+ Canceled = "Canceled"
211
+ }
212
+
213
+ /** Content of the email with a required plainText property. */
214
+ export declare interface PlainTextEmailContent {
215
+ /** Subject of the email message */
216
+ subject: string;
217
+ /** Plain text version of the email message. */
218
+ plainText: string;
219
+ /** Html version of the email message. */
220
+ html?: string;
189
221
  }
190
222
 
191
223
  export { }
@@ -1,41 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- /**
4
- * @summary Checks the message status of a sent email
5
- */
6
- import { EmailClient } from "@azure/communication-email";
7
- // Load the .env file (you will need to set these environment variables)
8
- import * as dotenv from "dotenv";
9
- dotenv.config();
10
- const connectionString = process.env["COMMUNICATION_CONNECTION_STRING"] || "";
11
- const senderAddress = process.env["SENDER_ADDRESS"] || "";
12
- const recipientAddress = process.env["RECIPIENT_ADDRESS"] || "";
13
- const getMessageStatusFromEmail = async () => {
14
- // Create the Email Client
15
- const emailClient = new EmailClient(connectionString);
16
- // Create the Email Message to be sent
17
- const emailMessage = {
18
- sender: senderAddress,
19
- content: {
20
- subject: "This is the subject",
21
- plainText: "This is the body",
22
- html: "<html><h1>This is the body</h1></html>",
23
- },
24
- recipients: {
25
- to: [{ email: recipientAddress, displayName: "Customer Name" }],
26
- },
27
- };
28
- try {
29
- // Send the email message
30
- const sendEmailResponse = await emailClient.send(emailMessage);
31
- // Use the message id to get the status of the email
32
- const messageId = sendEmailResponse.messageId || "";
33
- const getMessageStatusResponse = await emailClient.getSendStatus(messageId);
34
- console.log("Message Status: " + getMessageStatusResponse);
35
- }
36
- catch (error) {
37
- console.log(error);
38
- }
39
- };
40
- void getMessageStatusFromEmail();
41
- //# sourceMappingURL=checkMessageStatus.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"checkMessageStatus.js","sourceRoot":"","sources":["../../samples-dev/checkMessageStatus.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAgB,MAAM,4BAA4B,CAAC;AAEvE,wEAAwE;AACxE,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,IAAI,EAAE,CAAC;AAC9E,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC;AAC1D,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,EAAE,CAAC;AAEhE,MAAM,yBAAyB,GAAG,KAAK,IAAmB,EAAE;IAC1D,0BAA0B;IAC1B,MAAM,WAAW,GAAgB,IAAI,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAEnE,sCAAsC;IACtC,MAAM,YAAY,GAAiB;QACjC,MAAM,EAAE,aAAa;QACrB,OAAO,EAAE;YACP,OAAO,EAAE,qBAAqB;YAC9B,SAAS,EAAE,kBAAkB;YAC7B,IAAI,EAAE,wCAAwC;SAC/C;QACD,UAAU,EAAE;YACV,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC;SAChE;KACF,CAAC;IAEF,IAAI;QACF,yBAAyB;QACzB,MAAM,iBAAiB,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAE/D,oDAAoD;QACpD,MAAM,SAAS,GAAG,iBAAiB,CAAC,SAAS,IAAI,EAAE,CAAC;QACpD,MAAM,wBAAwB,GAAG,MAAM,WAAW,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QAE5E,OAAO,CAAC,GAAG,CAAC,kBAAkB,GAAG,wBAAwB,CAAC,CAAC;KAC5D;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;KACpB;AACH,CAAC,CAAC;AAEF,KAAK,yBAAyB,EAAE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * @summary Checks the message status of a sent email\n */\n\nimport { EmailClient, EmailMessage } from \"@azure/communication-email\";\n\n// Load the .env file (you will need to set these environment variables)\nimport * as dotenv from \"dotenv\";\ndotenv.config();\n\nconst connectionString = process.env[\"COMMUNICATION_CONNECTION_STRING\"] || \"\";\nconst senderAddress = process.env[\"SENDER_ADDRESS\"] || \"\";\nconst recipientAddress = process.env[\"RECIPIENT_ADDRESS\"] || \"\";\n\nconst getMessageStatusFromEmail = async (): Promise<void> => {\n // Create the Email Client\n const emailClient: EmailClient = new EmailClient(connectionString);\n\n // Create the Email Message to be sent\n const emailMessage: EmailMessage = {\n sender: senderAddress,\n content: {\n subject: \"This is the subject\",\n plainText: \"This is the body\",\n html: \"<html><h1>This is the body</h1></html>\",\n },\n recipients: {\n to: [{ email: recipientAddress, displayName: \"Customer Name\" }],\n },\n };\n\n try {\n // Send the email message\n const sendEmailResponse = await emailClient.send(emailMessage);\n\n // Use the message id to get the status of the email\n const messageId = sendEmailResponse.messageId || \"\";\n const getMessageStatusResponse = await emailClient.getSendStatus(messageId);\n\n console.log(\"Message Status: \" + getMessageStatusResponse);\n } catch (error) {\n console.log(error);\n }\n};\n\nvoid getMessageStatusFromEmail();\n"]}