@azure/communication-email 1.0.0-alpha.20220524.1 → 1.0.0-alpha.20220630.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.
Files changed (40) hide show
  1. package/README.md +15 -21
  2. package/dist/index.js +138 -76
  3. package/dist/index.js.map +1 -1
  4. package/dist-esm/samples-dev/checkMessageStatus.js +1 -6
  5. package/dist-esm/samples-dev/checkMessageStatus.js.map +1 -1
  6. package/dist-esm/samples-dev/sendEmailMultipleRecipients.js +5 -20
  7. package/dist-esm/samples-dev/sendEmailMultipleRecipients.js.map +1 -1
  8. package/dist-esm/samples-dev/sendEmailSingleRecipient.js +1 -6
  9. package/dist-esm/samples-dev/sendEmailSingleRecipient.js.map +1 -1
  10. package/dist-esm/samples-dev/sendEmailWithAttachments.js +1 -6
  11. package/dist-esm/samples-dev/sendEmailWithAttachments.js.map +1 -1
  12. package/dist-esm/src/emailClient.js +4 -16
  13. package/dist-esm/src/emailClient.js.map +1 -1
  14. package/dist-esm/src/generated/src/emailRestApiClient.js +53 -10
  15. package/dist-esm/src/generated/src/emailRestApiClient.js.map +1 -1
  16. package/dist-esm/src/generated/src/index.js +11 -0
  17. package/dist-esm/src/generated/src/index.js.map +1 -0
  18. package/dist-esm/src/generated/src/models/index.js +80 -1
  19. package/dist-esm/src/generated/src/models/index.js.map +1 -1
  20. package/dist-esm/src/generated/src/models/mappers.js +69 -10
  21. package/dist-esm/src/generated/src/models/mappers.js.map +1 -1
  22. package/dist-esm/src/generated/src/models/parameters.js +11 -0
  23. package/dist-esm/src/generated/src/models/parameters.js.map +1 -1
  24. package/dist-esm/src/generated/src/operations/email.js +10 -17
  25. package/dist-esm/src/generated/src/operations/email.js.map +1 -1
  26. package/dist-esm/src/generated/src/operationsInterfaces/email.js +9 -0
  27. package/dist-esm/src/generated/src/operationsInterfaces/email.js.map +1 -0
  28. package/dist-esm/src/generated/src/operationsInterfaces/index.js +9 -0
  29. package/dist-esm/src/generated/src/operationsInterfaces/index.js.map +1 -0
  30. package/dist-esm/src/models.js.map +1 -1
  31. package/dist-esm/test/public/emailClient.spec.js +122 -127
  32. package/dist-esm/test/public/emailClient.spec.js.map +1 -1
  33. package/dist-esm/test/public/utils/recordedClient.js +49 -31
  34. package/dist-esm/test/public/utils/recordedClient.js.map +1 -1
  35. package/package.json +10 -7
  36. package/types/communication-email.d.ts +84 -101
  37. package/dist-esm/src/constants.js +0 -4
  38. package/dist-esm/src/constants.js.map +0 -1
  39. package/dist-esm/src/generated/src/emailRestApiClientContext.js +0 -38
  40. package/dist-esm/src/generated/src/emailRestApiClientContext.js.map +0 -1
package/README.md CHANGED
@@ -16,33 +16,27 @@ To create these resource, you can use the [Azure Portal][communication_resource_
16
16
  npm install @azure/communication-email
17
17
  ```
18
18
 
19
- ### Browser support
20
-
21
- ## Key concepts
19
+ ## Examples
22
20
 
23
21
  `EmailClient` provides the functionality to send email messages .
24
22
 
25
- ## Examples
26
-
27
23
  ## Authentication
28
24
 
29
25
  Email clients can be authenticated using the connection string acquired from an Azure Communication Resource in the [Azure Portal][azure_portal].
30
26
 
31
- ```typescript
32
- import { EmailClient } from "@azure/communication-email";
27
+ ```javascript
28
+ const { EmailClient } = require("@azure/communication-email");
33
29
 
34
30
  const connectionString = `endpoint=https://<resource-name>.communication.azure.com/;accessKey=<Base64-Encoded-Key>`;
35
31
  const client = new EmailClient(connectionString);
36
32
  ```
37
33
 
38
- ## Examples
39
-
40
34
  ### Send an Email Message
41
35
 
42
36
  To send an email message, call the `send` function from the `EmailClient`.
43
37
 
44
- ```typescript Snippet:Azure_Communication_Email_Send
45
- const emailMessage: EmailMessage = {
38
+ ```javascript Snippet:Azure_Communication_Email_Send
39
+ const emailMessage = {
46
40
  sender: "sender@contoso.com",
47
41
  content: {
48
42
  subject: "This is the subject",
@@ -65,8 +59,8 @@ const response = await emailClient.send(emailMessage);
65
59
 
66
60
  To send an email message to multiple recipients, add a object for each recipient type and an object for each recipient.
67
61
 
68
- ```typescript Snippet:Azure_Communication_Email_Send_Multiple_Recipients
69
- const emailMessage: EmailMessage = {
62
+ ```javascript Snippet:Azure_Communication_Email_Send_Multiple_Recipients
63
+ const emailMessage = {
70
64
  sender: "sender@contoso.com",
71
65
  content: {
72
66
  subject: "This is the subject",
@@ -83,7 +77,7 @@ const emailMessage: EmailMessage = {
83
77
  displayName: "Customer Name 2",
84
78
  },
85
79
  ],
86
- cC: [
80
+ cc: [
87
81
  {
88
82
  email: "ccCustomer1@domain.com",
89
83
  displayName: " CC Customer 1",
@@ -93,7 +87,7 @@ const emailMessage: EmailMessage = {
93
87
  displayName: "CC Customer 2",
94
88
  },
95
89
  ],
96
- bCC: [
90
+ bcc: [
97
91
  {
98
92
  email: "bccCustomer1@domain.com",
99
93
  displayName: " BCC Customer 1",
@@ -113,17 +107,17 @@ const response = await emailClient.send(emailMessage);
113
107
 
114
108
  Azure Communication Services support sending email with attachments.
115
109
 
116
- ```typescript Snippet:Azure_Communication_Email_Send_With_Attachments
110
+ ```javascript Snippet:Azure_Communication_Email_Send_With_Attachments
117
111
  const filePath = "C://readme.txt";
118
112
 
119
- const emailMessage: EmailMessage = {
113
+ const emailMessage = {
120
114
  sender: "sender@contoso.com",
121
115
  content: {
122
116
  subject: "This is the subject",
123
117
  plainText: "This is the body",
124
118
  },
125
119
  recipients: {
126
- toRecipients: [
120
+ to: [
127
121
  {
128
122
  email: "customer@domain.com",
129
123
  displayName: "Customer Name",
@@ -146,10 +140,10 @@ const response = await emailClient.send(emailMessage);
146
140
 
147
141
  The result from the `send` call contains a `messageId` which can be used to query the status of the email.
148
142
 
149
- ```typescript Snippet:Azure_Communication_Email_GetSendStatus
150
- const messageId = await emailClient.send(emailMessage);
143
+ ```javascript Snippet:Azure_Communication_Email_GetSendStatus
144
+ const response = await emailClient.send(emailMessage);
151
145
 
152
- const status = await emailClient.getSendStatus(messageId);
146
+ const status = await emailClient.getSendStatus(response.messageId);
153
147
  ```
154
148
 
155
149
  ## Next steps
package/dist/index.js CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var coreHttp = require('@azure/core-http');
6
5
  var communicationCommon = require('@azure/communication-common');
6
+ var coreClient = require('@azure/core-client');
7
7
  var logger$1 = require('@azure/logger');
8
8
  var uuid = require('uuid');
9
9
 
@@ -25,7 +25,7 @@ function _interopNamespace(e) {
25
25
  return Object.freeze(n);
26
26
  }
27
27
 
28
- var coreHttp__namespace = /*#__PURE__*/_interopNamespace(coreHttp);
28
+ var coreClient__namespace = /*#__PURE__*/_interopNamespace(coreClient);
29
29
 
30
30
  /*
31
31
  * Copyright (c) Microsoft Corporation.
@@ -103,7 +103,10 @@ const CommunicationError = {
103
103
  type: {
104
104
  name: "Sequence",
105
105
  element: {
106
- type: { name: "Composite", className: "CommunicationError" }
106
+ type: {
107
+ name: "Composite",
108
+ className: "CommunicationError"
109
+ }
107
110
  }
108
111
  }
109
112
  },
@@ -127,7 +130,10 @@ const EmailMessage = {
127
130
  type: {
128
131
  name: "Sequence",
129
132
  element: {
130
- type: { name: "Composite", className: "EmailCustomHeader" }
133
+ type: {
134
+ name: "Composite",
135
+ className: "EmailCustomHeader"
136
+ }
131
137
  }
132
138
  }
133
139
  },
@@ -163,14 +169,24 @@ const EmailMessage = {
163
169
  serializedName: "attachments",
164
170
  type: {
165
171
  name: "Sequence",
166
- element: { type: { name: "Composite", className: "EmailAttachment" } }
172
+ element: {
173
+ type: {
174
+ name: "Composite",
175
+ className: "EmailAttachment"
176
+ }
177
+ }
167
178
  }
168
179
  },
169
180
  replyTo: {
170
181
  serializedName: "replyTo",
171
182
  type: {
172
183
  name: "Sequence",
173
- element: { type: { name: "Composite", className: "EmailAddress" } }
184
+ element: {
185
+ type: {
186
+ name: "Composite",
187
+ className: "EmailAddress"
188
+ }
189
+ }
174
190
  }
175
191
  },
176
192
  disableUserEngagementTracking: {
@@ -241,21 +257,36 @@ const EmailRecipients = {
241
257
  required: true,
242
258
  type: {
243
259
  name: "Sequence",
244
- element: { type: { name: "Composite", className: "EmailAddress" } }
260
+ element: {
261
+ type: {
262
+ name: "Composite",
263
+ className: "EmailAddress"
264
+ }
265
+ }
245
266
  }
246
267
  },
247
- cC: {
248
- serializedName: "cC",
268
+ cc: {
269
+ serializedName: "CC",
249
270
  type: {
250
271
  name: "Sequence",
251
- element: { type: { name: "Composite", className: "EmailAddress" } }
272
+ element: {
273
+ type: {
274
+ name: "Composite",
275
+ className: "EmailAddress"
276
+ }
277
+ }
252
278
  }
253
279
  },
254
- bCC: {
280
+ bcc: {
255
281
  serializedName: "bCC",
256
282
  type: {
257
283
  name: "Sequence",
258
- element: { type: { name: "Composite", className: "EmailAddress" } }
284
+ element: {
285
+ type: {
286
+ name: "Composite",
287
+ className: "EmailAddress"
288
+ }
289
+ }
259
290
  }
260
291
  }
261
292
  }
@@ -325,6 +356,20 @@ const EmailGetSendStatusHeaders = {
325
356
  }
326
357
  }
327
358
  };
359
+ const EmailGetSendStatusExceptionHeaders = {
360
+ type: {
361
+ name: "Composite",
362
+ className: "EmailGetSendStatusExceptionHeaders",
363
+ modelProperties: {
364
+ xMsErrorCode: {
365
+ serializedName: "x-ms-error-code",
366
+ type: {
367
+ name: "String"
368
+ }
369
+ }
370
+ }
371
+ }
372
+ };
328
373
  const EmailSendHeaders = {
329
374
  type: {
330
375
  name: "Composite",
@@ -357,6 +402,20 @@ const EmailSendHeaders = {
357
402
  }
358
403
  }
359
404
  };
405
+ const EmailSendExceptionHeaders = {
406
+ type: {
407
+ name: "Composite",
408
+ className: "EmailSendExceptionHeaders",
409
+ modelProperties: {
410
+ xMsErrorCode: {
411
+ serializedName: "x-ms-error-code",
412
+ type: {
413
+ name: "String"
414
+ }
415
+ }
416
+ }
417
+ }
418
+ };
360
419
 
361
420
  var Mappers = /*#__PURE__*/Object.freeze({
362
421
  __proto__: null,
@@ -370,7 +429,9 @@ var Mappers = /*#__PURE__*/Object.freeze({
370
429
  EmailAddress: EmailAddress,
371
430
  EmailAttachment: EmailAttachment,
372
431
  EmailGetSendStatusHeaders: EmailGetSendStatusHeaders,
373
- EmailSendHeaders: EmailSendHeaders
432
+ EmailGetSendStatusExceptionHeaders: EmailGetSendStatusExceptionHeaders,
433
+ EmailSendHeaders: EmailSendHeaders,
434
+ EmailSendExceptionHeaders: EmailSendExceptionHeaders
374
435
  });
375
436
 
376
437
  /*
@@ -380,6 +441,17 @@ var Mappers = /*#__PURE__*/Object.freeze({
380
441
  * Code generated by Microsoft (R) AutoRest Code Generator.
381
442
  * Changes may cause incorrect behavior and will be lost if the code is regenerated.
382
443
  */
444
+ const accept = {
445
+ parameterPath: "accept",
446
+ mapper: {
447
+ defaultValue: "application/json",
448
+ isConstant: true,
449
+ serializedName: "Accept",
450
+ type: {
451
+ name: "String"
452
+ }
453
+ }
454
+ };
383
455
  const endpoint = {
384
456
  parameterPath: "endpoint",
385
457
  mapper: {
@@ -455,10 +527,8 @@ const repeatabilityFirstSent = {
455
527
  * Code generated by Microsoft (R) AutoRest Code Generator.
456
528
  * Changes may cause incorrect behavior and will be lost if the code is regenerated.
457
529
  */
458
- /**
459
- * Class representing a Email.
460
- */
461
- class Email {
530
+ /** Class containing Email operations. */
531
+ class EmailImpl {
462
532
  /**
463
533
  * Initialize a new instance of the class Email class.
464
534
  * @param client Reference to the service client
@@ -472,8 +542,7 @@ class Email {
472
542
  * @param options The options parameters.
473
543
  */
474
544
  getSendStatus(messageId, options) {
475
- const operationOptions = coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {});
476
- return this.client.sendOperationRequest({ messageId, options: operationOptions }, getSendStatusOperationSpec);
545
+ return this.client.sendOperationRequest({ messageId, options }, getSendStatusOperationSpec);
477
546
  }
478
547
  /**
479
548
  * Queues an email message to be sent to one or more recipients
@@ -489,17 +558,11 @@ class Email {
489
558
  * @param options The options parameters.
490
559
  */
491
560
  send(repeatabilityRequestId, repeatabilityFirstSent, emailMessage, options) {
492
- const operationOptions = coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {});
493
- return this.client.sendOperationRequest({
494
- repeatabilityRequestId,
495
- repeatabilityFirstSent,
496
- emailMessage,
497
- options: operationOptions
498
- }, sendOperationSpec);
561
+ return this.client.sendOperationRequest({ repeatabilityRequestId, repeatabilityFirstSent, emailMessage, options }, sendOperationSpec);
499
562
  }
500
563
  }
501
564
  // Operation Specifications
502
- const serializer = new coreHttp__namespace.Serializer(Mappers, /* isXml */ false);
565
+ const serializer = coreClient__namespace.createSerializer(Mappers, /* isXml */ false);
503
566
  const getSendStatusOperationSpec = {
504
567
  path: "/emails/{messageId}/status",
505
568
  httpMethod: "GET",
@@ -510,11 +573,12 @@ const getSendStatusOperationSpec = {
510
573
  },
511
574
  default: {
512
575
  bodyMapper: CommunicationErrorResponse,
513
- headersMapper: EmailGetSendStatusHeaders
576
+ headersMapper: EmailGetSendStatusExceptionHeaders
514
577
  }
515
578
  },
516
579
  queryParameters: [apiVersion],
517
580
  urlParameters: [endpoint, messageId],
581
+ headerParameters: [accept],
518
582
  serializer
519
583
  };
520
584
  const sendOperationSpec = {
@@ -526,13 +590,14 @@ const sendOperationSpec = {
526
590
  },
527
591
  default: {
528
592
  bodyMapper: CommunicationErrorResponse,
529
- headersMapper: EmailSendHeaders
593
+ headersMapper: EmailSendExceptionHeaders
530
594
  }
531
595
  },
532
596
  requestBody: emailMessage,
533
597
  queryParameters: [apiVersion],
534
598
  urlParameters: [endpoint],
535
599
  headerParameters: [
600
+ accept,
536
601
  contentType,
537
602
  repeatabilityRequestId,
538
603
  repeatabilityFirstSent
@@ -548,15 +613,14 @@ const sendOperationSpec = {
548
613
  * Code generated by Microsoft (R) AutoRest Code Generator.
549
614
  * Changes may cause incorrect behavior and will be lost if the code is regenerated.
550
615
  */
551
- const packageName = "@azure/communication-email";
552
- const packageVersion = "1.0.0-beta.1";
553
- class EmailRestApiClientContext extends coreHttp__namespace.ServiceClient {
616
+ class EmailRestApiClient extends coreClient__namespace.ServiceClient {
554
617
  /**
555
- * Initializes a new instance of the EmailRestApiClientContext class.
618
+ * Initializes a new instance of the EmailRestApiClient class.
556
619
  * @param endpoint The communication resource, for example https://my-resource.communication.azure.com
557
620
  * @param options The parameter options
558
621
  */
559
622
  constructor(endpoint, options) {
623
+ var _a, _b;
560
624
  if (endpoint === undefined) {
561
625
  throw new Error("'endpoint' cannot be null");
562
626
  }
@@ -564,43 +628,51 @@ class EmailRestApiClientContext extends coreHttp__namespace.ServiceClient {
564
628
  if (!options) {
565
629
  options = {};
566
630
  }
567
- if (!options.userAgent) {
568
- const defaultUserAgent = coreHttp__namespace.getDefaultUserAgentValue();
569
- options.userAgent = `${packageName}/${packageVersion} ${defaultUserAgent}`;
570
- }
571
- super(undefined, options);
572
- this.requestContentType = "application/json; charset=utf-8";
573
- this.baseUri = options.endpoint || "{endpoint}";
631
+ const defaults = {
632
+ requestContentType: "application/json; charset=utf-8"
633
+ };
634
+ const packageDetails = `azsdk-js-communication-email/1.0.0-beta.2`;
635
+ const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
636
+ ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
637
+ : `${packageDetails}`;
638
+ const optionsWithDefaults = Object.assign(Object.assign(Object.assign({}, defaults), options), { userAgentOptions: {
639
+ userAgentPrefix
640
+ }, baseUri: (_b = (_a = options.endpoint) !== null && _a !== void 0 ? _a : options.baseUri) !== null && _b !== void 0 ? _b : "{endpoint}" });
641
+ super(optionsWithDefaults);
574
642
  // Parameter assignments
575
643
  this.endpoint = endpoint;
576
644
  // Assigning values to Constant parameters
577
645
  this.apiVersion = options.apiVersion || "2021-10-01-preview";
646
+ this.email = new EmailImpl(this);
647
+ this.addCustomApiVersionPolicy(options.apiVersion);
578
648
  }
579
- }
580
-
581
- /*
582
- * Copyright (c) Microsoft Corporation.
583
- * Licensed under the MIT License.
584
- *
585
- * Code generated by Microsoft (R) AutoRest Code Generator.
586
- * Changes may cause incorrect behavior and will be lost if the code is regenerated.
587
- */
588
- class EmailRestApiClient extends EmailRestApiClientContext {
589
- /**
590
- * Initializes a new instance of the EmailRestApiClient class.
591
- * @param endpoint The communication resource, for example https://my-resource.communication.azure.com
592
- * @param options The parameter options
593
- */
594
- constructor(endpoint, options) {
595
- super(endpoint, options);
596
- this.email = new Email(this);
649
+ /** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */
650
+ addCustomApiVersionPolicy(apiVersion) {
651
+ if (!apiVersion) {
652
+ return;
653
+ }
654
+ const apiVersionPolicy = {
655
+ name: "CustomApiVersionPolicy",
656
+ async sendRequest(request, next) {
657
+ const param = request.url.split("?");
658
+ if (param.length > 1) {
659
+ const newParams = param[1].split("&").map((item) => {
660
+ if (item.indexOf("api-version") > -1) {
661
+ return "api-version=" + apiVersion;
662
+ }
663
+ else {
664
+ return item;
665
+ }
666
+ });
667
+ request.url = param[0] + "?" + newParams.join("&");
668
+ }
669
+ return next(request);
670
+ }
671
+ };
672
+ this.pipeline.addPolicy(apiVersionPolicy);
597
673
  }
598
674
  }
599
675
 
600
- // Copyright (c) Microsoft Corporation.
601
- // Licensed under the MIT license.
602
- const SDK_VERSION = "1.0.0-beta.1";
603
-
604
676
  // Copyright (c) Microsoft Corporation.
605
677
  /**
606
678
  * The \@azure/logger configuration for this package.
@@ -621,24 +693,14 @@ class EmailClient {
621
693
  constructor(connectionStringOrUrl, credentialOrOptions, maybeOptions = {}) {
622
694
  const { url, credential } = communicationCommon.parseClientArguments(connectionStringOrUrl, credentialOrOptions);
623
695
  const options = isEmailClientOptions(credentialOrOptions) ? credentialOrOptions : maybeOptions;
624
- const libInfo = `azsdk-js-communication-email/${SDK_VERSION}`;
625
- if (!options.userAgentOptions) {
626
- options.userAgentOptions = {};
627
- }
628
- if (options.userAgentOptions.userAgentPrefix) {
629
- options.userAgentOptions.userAgentPrefix = `${options.userAgentOptions.userAgentPrefix} ${libInfo}`;
630
- }
631
- else {
632
- options.userAgentOptions.userAgentPrefix = libInfo;
633
- }
634
696
  const internalPipelineOptions = Object.assign(Object.assign({}, options), {
635
697
  loggingOptions: {
636
698
  logger: logger.info,
637
699
  },
638
700
  });
639
701
  const authPolicy = communicationCommon.createCommunicationAuthPolicy(credential);
640
- const pipeline = coreHttp.createPipelineFromOptions(internalPipelineOptions, authPolicy);
641
- this.api = new EmailRestApiClient(url, pipeline);
702
+ this.generatedClient = new EmailRestApiClient(url, internalPipelineOptions);
703
+ this.generatedClient.pipeline.addPolicy(authPolicy);
642
704
  }
643
705
  /**
644
706
  * Queues an email message to be sent to one or more recipients
@@ -646,7 +708,7 @@ class EmailClient {
646
708
  */
647
709
  async send(emailMessage) {
648
710
  var _a;
649
- const response = await this.api.email.send(uuid.v4(), new Date().toUTCString(), emailMessage);
711
+ const response = await this.generatedClient.email.send(uuid.v4(), new Date().toUTCString(), emailMessage);
650
712
  return {
651
713
  messageId: (_a = response.xMsRequestId) !== null && _a !== void 0 ? _a : "",
652
714
  };
@@ -656,7 +718,7 @@ class EmailClient {
656
718
  * @param messageId - System generated message id (GUID) returned from a previous call to send email
657
719
  */
658
720
  async getSendStatus(messageId) {
659
- const response = await this.api.email.getSendStatus(messageId);
721
+ const response = await this.generatedClient.email.getSendStatus(messageId);
660
722
  return {
661
723
  messageId: response.messageId,
662
724
  status: response.status,