@azure/communication-email 1.0.0-alpha.20220524.1
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE.txt +21 -0
- package/README.md +183 -0
- package/dist/index.js +668 -0
- package/dist/index.js.map +1 -0
- package/dist-esm/samples-dev/checkMessageStatus.js +46 -0
- package/dist-esm/samples-dev/checkMessageStatus.js.map +1 -0
- package/dist-esm/samples-dev/sendEmailMultipleRecipients.js +59 -0
- package/dist-esm/samples-dev/sendEmailMultipleRecipients.js.map +1 -0
- package/dist-esm/samples-dev/sendEmailSingleRecipient.js +43 -0
- package/dist-esm/samples-dev/sendEmailSingleRecipient.js.map +1 -0
- package/dist-esm/samples-dev/sendEmailWithAttachments.js +50 -0
- package/dist-esm/samples-dev/sendEmailWithAttachments.js.map +1 -0
- package/dist-esm/src/constants.js +4 -0
- package/dist-esm/src/constants.js.map +1 -0
- package/dist-esm/src/emailClient.js +64 -0
- package/dist-esm/src/emailClient.js.map +1 -0
- package/dist-esm/src/generated/src/emailRestApiClient.js +26 -0
- package/dist-esm/src/generated/src/emailRestApiClient.js.map +1 -0
- package/dist-esm/src/generated/src/emailRestApiClientContext.js +38 -0
- package/dist-esm/src/generated/src/emailRestApiClientContext.js.map +1 -0
- package/dist-esm/src/generated/src/models/index.js +9 -0
- package/dist-esm/src/generated/src/models/index.js.map +1 -0
- package/dist-esm/src/generated/src/models/mappers.js +331 -0
- package/dist-esm/src/generated/src/models/mappers.js.map +1 -0
- package/dist-esm/src/generated/src/models/parameters.js +76 -0
- package/dist-esm/src/generated/src/models/parameters.js.map +1 -0
- package/dist-esm/src/generated/src/operations/email.js +96 -0
- package/dist-esm/src/generated/src/operations/email.js.map +1 -0
- package/dist-esm/src/generated/src/operations/index.js +9 -0
- package/dist-esm/src/generated/src/operations/index.js.map +1 -0
- package/dist-esm/src/index.js +5 -0
- package/dist-esm/src/index.js.map +1 -0
- package/dist-esm/src/logger.js +8 -0
- package/dist-esm/src/logger.js.map +1 -0
- package/dist-esm/src/models.js +4 -0
- package/dist-esm/src/models.js.map +1 -0
- package/dist-esm/test/public/emailClient.spec.js +137 -0
- package/dist-esm/test/public/emailClient.spec.js.map +1 -0
- package/dist-esm/test/public/utils/recordedClient.js +46 -0
- package/dist-esm/test/public/utils/recordedClient.js.map +1 -0
- package/package.json +110 -0
- package/types/communication-email.d.ts +200 -0
package/dist/index.js
ADDED
@@ -0,0 +1,668 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
4
|
+
|
5
|
+
var coreHttp = require('@azure/core-http');
|
6
|
+
var communicationCommon = require('@azure/communication-common');
|
7
|
+
var logger$1 = require('@azure/logger');
|
8
|
+
var uuid = require('uuid');
|
9
|
+
|
10
|
+
function _interopNamespace(e) {
|
11
|
+
if (e && e.__esModule) return e;
|
12
|
+
var n = Object.create(null);
|
13
|
+
if (e) {
|
14
|
+
Object.keys(e).forEach(function (k) {
|
15
|
+
if (k !== 'default') {
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
18
|
+
enumerable: true,
|
19
|
+
get: function () { return e[k]; }
|
20
|
+
});
|
21
|
+
}
|
22
|
+
});
|
23
|
+
}
|
24
|
+
n["default"] = e;
|
25
|
+
return Object.freeze(n);
|
26
|
+
}
|
27
|
+
|
28
|
+
var coreHttp__namespace = /*#__PURE__*/_interopNamespace(coreHttp);
|
29
|
+
|
30
|
+
/*
|
31
|
+
* Copyright (c) Microsoft Corporation.
|
32
|
+
* Licensed under the MIT License.
|
33
|
+
*
|
34
|
+
* Code generated by Microsoft (R) AutoRest Code Generator.
|
35
|
+
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
36
|
+
*/
|
37
|
+
const SendStatusResult = {
|
38
|
+
type: {
|
39
|
+
name: "Composite",
|
40
|
+
className: "SendStatusResult",
|
41
|
+
modelProperties: {
|
42
|
+
messageId: {
|
43
|
+
serializedName: "messageId",
|
44
|
+
required: true,
|
45
|
+
type: {
|
46
|
+
name: "String"
|
47
|
+
}
|
48
|
+
},
|
49
|
+
status: {
|
50
|
+
serializedName: "status",
|
51
|
+
required: true,
|
52
|
+
type: {
|
53
|
+
name: "String"
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
};
|
59
|
+
const CommunicationErrorResponse = {
|
60
|
+
type: {
|
61
|
+
name: "Composite",
|
62
|
+
className: "CommunicationErrorResponse",
|
63
|
+
modelProperties: {
|
64
|
+
error: {
|
65
|
+
serializedName: "error",
|
66
|
+
type: {
|
67
|
+
name: "Composite",
|
68
|
+
className: "CommunicationError"
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
};
|
74
|
+
const CommunicationError = {
|
75
|
+
type: {
|
76
|
+
name: "Composite",
|
77
|
+
className: "CommunicationError",
|
78
|
+
modelProperties: {
|
79
|
+
code: {
|
80
|
+
serializedName: "code",
|
81
|
+
required: true,
|
82
|
+
type: {
|
83
|
+
name: "String"
|
84
|
+
}
|
85
|
+
},
|
86
|
+
message: {
|
87
|
+
serializedName: "message",
|
88
|
+
required: true,
|
89
|
+
type: {
|
90
|
+
name: "String"
|
91
|
+
}
|
92
|
+
},
|
93
|
+
target: {
|
94
|
+
serializedName: "target",
|
95
|
+
readOnly: true,
|
96
|
+
type: {
|
97
|
+
name: "String"
|
98
|
+
}
|
99
|
+
},
|
100
|
+
details: {
|
101
|
+
serializedName: "details",
|
102
|
+
readOnly: true,
|
103
|
+
type: {
|
104
|
+
name: "Sequence",
|
105
|
+
element: {
|
106
|
+
type: { name: "Composite", className: "CommunicationError" }
|
107
|
+
}
|
108
|
+
}
|
109
|
+
},
|
110
|
+
innerError: {
|
111
|
+
serializedName: "innererror",
|
112
|
+
type: {
|
113
|
+
name: "Composite",
|
114
|
+
className: "CommunicationError"
|
115
|
+
}
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
};
|
120
|
+
const EmailMessage = {
|
121
|
+
type: {
|
122
|
+
name: "Composite",
|
123
|
+
className: "EmailMessage",
|
124
|
+
modelProperties: {
|
125
|
+
customHeaders: {
|
126
|
+
serializedName: "headers",
|
127
|
+
type: {
|
128
|
+
name: "Sequence",
|
129
|
+
element: {
|
130
|
+
type: { name: "Composite", className: "EmailCustomHeader" }
|
131
|
+
}
|
132
|
+
}
|
133
|
+
},
|
134
|
+
sender: {
|
135
|
+
serializedName: "sender",
|
136
|
+
required: true,
|
137
|
+
type: {
|
138
|
+
name: "String"
|
139
|
+
}
|
140
|
+
},
|
141
|
+
content: {
|
142
|
+
serializedName: "content",
|
143
|
+
type: {
|
144
|
+
name: "Composite",
|
145
|
+
className: "EmailContent"
|
146
|
+
}
|
147
|
+
},
|
148
|
+
importance: {
|
149
|
+
defaultValue: "normal",
|
150
|
+
serializedName: "importance",
|
151
|
+
type: {
|
152
|
+
name: "String"
|
153
|
+
}
|
154
|
+
},
|
155
|
+
recipients: {
|
156
|
+
serializedName: "recipients",
|
157
|
+
type: {
|
158
|
+
name: "Composite",
|
159
|
+
className: "EmailRecipients"
|
160
|
+
}
|
161
|
+
},
|
162
|
+
attachments: {
|
163
|
+
serializedName: "attachments",
|
164
|
+
type: {
|
165
|
+
name: "Sequence",
|
166
|
+
element: { type: { name: "Composite", className: "EmailAttachment" } }
|
167
|
+
}
|
168
|
+
},
|
169
|
+
replyTo: {
|
170
|
+
serializedName: "replyTo",
|
171
|
+
type: {
|
172
|
+
name: "Sequence",
|
173
|
+
element: { type: { name: "Composite", className: "EmailAddress" } }
|
174
|
+
}
|
175
|
+
},
|
176
|
+
disableUserEngagementTracking: {
|
177
|
+
serializedName: "disableUserEngagementTracking",
|
178
|
+
type: {
|
179
|
+
name: "Boolean"
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}
|
183
|
+
}
|
184
|
+
};
|
185
|
+
const EmailCustomHeader = {
|
186
|
+
type: {
|
187
|
+
name: "Composite",
|
188
|
+
className: "EmailCustomHeader",
|
189
|
+
modelProperties: {
|
190
|
+
name: {
|
191
|
+
serializedName: "name",
|
192
|
+
required: true,
|
193
|
+
type: {
|
194
|
+
name: "String"
|
195
|
+
}
|
196
|
+
},
|
197
|
+
value: {
|
198
|
+
serializedName: "value",
|
199
|
+
required: true,
|
200
|
+
type: {
|
201
|
+
name: "String"
|
202
|
+
}
|
203
|
+
}
|
204
|
+
}
|
205
|
+
}
|
206
|
+
};
|
207
|
+
const EmailContent = {
|
208
|
+
type: {
|
209
|
+
name: "Composite",
|
210
|
+
className: "EmailContent",
|
211
|
+
modelProperties: {
|
212
|
+
subject: {
|
213
|
+
serializedName: "subject",
|
214
|
+
required: true,
|
215
|
+
type: {
|
216
|
+
name: "String"
|
217
|
+
}
|
218
|
+
},
|
219
|
+
plainText: {
|
220
|
+
serializedName: "plainText",
|
221
|
+
type: {
|
222
|
+
name: "String"
|
223
|
+
}
|
224
|
+
},
|
225
|
+
html: {
|
226
|
+
serializedName: "html",
|
227
|
+
type: {
|
228
|
+
name: "String"
|
229
|
+
}
|
230
|
+
}
|
231
|
+
}
|
232
|
+
}
|
233
|
+
};
|
234
|
+
const EmailRecipients = {
|
235
|
+
type: {
|
236
|
+
name: "Composite",
|
237
|
+
className: "EmailRecipients",
|
238
|
+
modelProperties: {
|
239
|
+
to: {
|
240
|
+
serializedName: "to",
|
241
|
+
required: true,
|
242
|
+
type: {
|
243
|
+
name: "Sequence",
|
244
|
+
element: { type: { name: "Composite", className: "EmailAddress" } }
|
245
|
+
}
|
246
|
+
},
|
247
|
+
cC: {
|
248
|
+
serializedName: "cC",
|
249
|
+
type: {
|
250
|
+
name: "Sequence",
|
251
|
+
element: { type: { name: "Composite", className: "EmailAddress" } }
|
252
|
+
}
|
253
|
+
},
|
254
|
+
bCC: {
|
255
|
+
serializedName: "bCC",
|
256
|
+
type: {
|
257
|
+
name: "Sequence",
|
258
|
+
element: { type: { name: "Composite", className: "EmailAddress" } }
|
259
|
+
}
|
260
|
+
}
|
261
|
+
}
|
262
|
+
}
|
263
|
+
};
|
264
|
+
const EmailAddress = {
|
265
|
+
type: {
|
266
|
+
name: "Composite",
|
267
|
+
className: "EmailAddress",
|
268
|
+
modelProperties: {
|
269
|
+
email: {
|
270
|
+
serializedName: "email",
|
271
|
+
required: true,
|
272
|
+
type: {
|
273
|
+
name: "String"
|
274
|
+
}
|
275
|
+
},
|
276
|
+
displayName: {
|
277
|
+
serializedName: "displayName",
|
278
|
+
type: {
|
279
|
+
name: "String"
|
280
|
+
}
|
281
|
+
}
|
282
|
+
}
|
283
|
+
}
|
284
|
+
};
|
285
|
+
const EmailAttachment = {
|
286
|
+
type: {
|
287
|
+
name: "Composite",
|
288
|
+
className: "EmailAttachment",
|
289
|
+
modelProperties: {
|
290
|
+
name: {
|
291
|
+
serializedName: "name",
|
292
|
+
required: true,
|
293
|
+
type: {
|
294
|
+
name: "String"
|
295
|
+
}
|
296
|
+
},
|
297
|
+
attachmentType: {
|
298
|
+
serializedName: "attachmentType",
|
299
|
+
required: true,
|
300
|
+
type: {
|
301
|
+
name: "String"
|
302
|
+
}
|
303
|
+
},
|
304
|
+
contentBytesBase64: {
|
305
|
+
serializedName: "contentBytesBase64",
|
306
|
+
required: true,
|
307
|
+
type: {
|
308
|
+
name: "String"
|
309
|
+
}
|
310
|
+
}
|
311
|
+
}
|
312
|
+
}
|
313
|
+
};
|
314
|
+
const EmailGetSendStatusHeaders = {
|
315
|
+
type: {
|
316
|
+
name: "Composite",
|
317
|
+
className: "EmailGetSendStatusHeaders",
|
318
|
+
modelProperties: {
|
319
|
+
retryAfter: {
|
320
|
+
serializedName: "retry-after",
|
321
|
+
type: {
|
322
|
+
name: "Number"
|
323
|
+
}
|
324
|
+
}
|
325
|
+
}
|
326
|
+
}
|
327
|
+
};
|
328
|
+
const EmailSendHeaders = {
|
329
|
+
type: {
|
330
|
+
name: "Composite",
|
331
|
+
className: "EmailSendHeaders",
|
332
|
+
modelProperties: {
|
333
|
+
repeatabilityResult: {
|
334
|
+
serializedName: "repeatability-result",
|
335
|
+
type: {
|
336
|
+
name: "String"
|
337
|
+
}
|
338
|
+
},
|
339
|
+
operationLocation: {
|
340
|
+
serializedName: "operation-location",
|
341
|
+
type: {
|
342
|
+
name: "String"
|
343
|
+
}
|
344
|
+
},
|
345
|
+
retryAfter: {
|
346
|
+
serializedName: "retry-after",
|
347
|
+
type: {
|
348
|
+
name: "Number"
|
349
|
+
}
|
350
|
+
},
|
351
|
+
xMsRequestId: {
|
352
|
+
serializedName: "x-ms-request-id",
|
353
|
+
type: {
|
354
|
+
name: "String"
|
355
|
+
}
|
356
|
+
}
|
357
|
+
}
|
358
|
+
}
|
359
|
+
};
|
360
|
+
|
361
|
+
var Mappers = /*#__PURE__*/Object.freeze({
|
362
|
+
__proto__: null,
|
363
|
+
SendStatusResult: SendStatusResult,
|
364
|
+
CommunicationErrorResponse: CommunicationErrorResponse,
|
365
|
+
CommunicationError: CommunicationError,
|
366
|
+
EmailMessage: EmailMessage,
|
367
|
+
EmailCustomHeader: EmailCustomHeader,
|
368
|
+
EmailContent: EmailContent,
|
369
|
+
EmailRecipients: EmailRecipients,
|
370
|
+
EmailAddress: EmailAddress,
|
371
|
+
EmailAttachment: EmailAttachment,
|
372
|
+
EmailGetSendStatusHeaders: EmailGetSendStatusHeaders,
|
373
|
+
EmailSendHeaders: EmailSendHeaders
|
374
|
+
});
|
375
|
+
|
376
|
+
/*
|
377
|
+
* Copyright (c) Microsoft Corporation.
|
378
|
+
* Licensed under the MIT License.
|
379
|
+
*
|
380
|
+
* Code generated by Microsoft (R) AutoRest Code Generator.
|
381
|
+
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
382
|
+
*/
|
383
|
+
const endpoint = {
|
384
|
+
parameterPath: "endpoint",
|
385
|
+
mapper: {
|
386
|
+
serializedName: "endpoint",
|
387
|
+
required: true,
|
388
|
+
type: {
|
389
|
+
name: "String"
|
390
|
+
}
|
391
|
+
},
|
392
|
+
skipEncoding: true
|
393
|
+
};
|
394
|
+
const messageId = {
|
395
|
+
parameterPath: "messageId",
|
396
|
+
mapper: {
|
397
|
+
serializedName: "messageId",
|
398
|
+
required: true,
|
399
|
+
type: {
|
400
|
+
name: "String"
|
401
|
+
}
|
402
|
+
}
|
403
|
+
};
|
404
|
+
const apiVersion = {
|
405
|
+
parameterPath: "apiVersion",
|
406
|
+
mapper: {
|
407
|
+
defaultValue: "2021-10-01-preview",
|
408
|
+
isConstant: true,
|
409
|
+
serializedName: "api-version",
|
410
|
+
type: {
|
411
|
+
name: "String"
|
412
|
+
}
|
413
|
+
}
|
414
|
+
};
|
415
|
+
const contentType = {
|
416
|
+
parameterPath: ["options", "contentType"],
|
417
|
+
mapper: {
|
418
|
+
defaultValue: "application/json",
|
419
|
+
isConstant: true,
|
420
|
+
serializedName: "Content-Type",
|
421
|
+
type: {
|
422
|
+
name: "String"
|
423
|
+
}
|
424
|
+
}
|
425
|
+
};
|
426
|
+
const emailMessage = {
|
427
|
+
parameterPath: "emailMessage",
|
428
|
+
mapper: EmailMessage
|
429
|
+
};
|
430
|
+
const repeatabilityRequestId = {
|
431
|
+
parameterPath: "repeatabilityRequestId",
|
432
|
+
mapper: {
|
433
|
+
serializedName: "repeatability-request-id",
|
434
|
+
required: true,
|
435
|
+
type: {
|
436
|
+
name: "String"
|
437
|
+
}
|
438
|
+
}
|
439
|
+
};
|
440
|
+
const repeatabilityFirstSent = {
|
441
|
+
parameterPath: "repeatabilityFirstSent",
|
442
|
+
mapper: {
|
443
|
+
serializedName: "repeatability-first-sent",
|
444
|
+
required: true,
|
445
|
+
type: {
|
446
|
+
name: "String"
|
447
|
+
}
|
448
|
+
}
|
449
|
+
};
|
450
|
+
|
451
|
+
/*
|
452
|
+
* Copyright (c) Microsoft Corporation.
|
453
|
+
* Licensed under the MIT License.
|
454
|
+
*
|
455
|
+
* Code generated by Microsoft (R) AutoRest Code Generator.
|
456
|
+
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
457
|
+
*/
|
458
|
+
/**
|
459
|
+
* Class representing a Email.
|
460
|
+
*/
|
461
|
+
class Email {
|
462
|
+
/**
|
463
|
+
* Initialize a new instance of the class Email class.
|
464
|
+
* @param client Reference to the service client
|
465
|
+
*/
|
466
|
+
constructor(client) {
|
467
|
+
this.client = client;
|
468
|
+
}
|
469
|
+
/**
|
470
|
+
* Gets the status of a message sent previously.
|
471
|
+
* @param messageId System generated message id (GUID) returned from a previous call to send email
|
472
|
+
* @param options The options parameters.
|
473
|
+
*/
|
474
|
+
getSendStatus(messageId, options) {
|
475
|
+
const operationOptions = coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {});
|
476
|
+
return this.client.sendOperationRequest({ messageId, options: operationOptions }, getSendStatusOperationSpec);
|
477
|
+
}
|
478
|
+
/**
|
479
|
+
* Queues an email message to be sent to one or more recipients
|
480
|
+
* @param repeatabilityRequestId If specified, the client directs that the request is repeatable; that
|
481
|
+
* is, that the client can make the request multiple times with the same Repeatability-Request-Id and
|
482
|
+
* get back an appropriate response without the server executing the request multiple times. The value
|
483
|
+
* of the Repeatability-Request-Id is an opaque string representing a client-generated, globally unique
|
484
|
+
* for all time, identifier for the request. It is recommended to use version 4 (random) UUIDs.
|
485
|
+
* @param repeatabilityFirstSent Must be sent by clients to specify that a request is repeatable.
|
486
|
+
* Repeatability-First-Sent is used to specify the date and time at which the request was first created
|
487
|
+
* in the IMF-fix date form of HTTP-date as defined in RFC7231. eg- Tue, 26 Mar 2019 16:06:51 GMT
|
488
|
+
* @param emailMessage Message payload for sending an email
|
489
|
+
* @param options The options parameters.
|
490
|
+
*/
|
491
|
+
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);
|
499
|
+
}
|
500
|
+
}
|
501
|
+
// Operation Specifications
|
502
|
+
const serializer = new coreHttp__namespace.Serializer(Mappers, /* isXml */ false);
|
503
|
+
const getSendStatusOperationSpec = {
|
504
|
+
path: "/emails/{messageId}/status",
|
505
|
+
httpMethod: "GET",
|
506
|
+
responses: {
|
507
|
+
200: {
|
508
|
+
bodyMapper: SendStatusResult,
|
509
|
+
headersMapper: EmailGetSendStatusHeaders
|
510
|
+
},
|
511
|
+
default: {
|
512
|
+
bodyMapper: CommunicationErrorResponse,
|
513
|
+
headersMapper: EmailGetSendStatusHeaders
|
514
|
+
}
|
515
|
+
},
|
516
|
+
queryParameters: [apiVersion],
|
517
|
+
urlParameters: [endpoint, messageId],
|
518
|
+
serializer
|
519
|
+
};
|
520
|
+
const sendOperationSpec = {
|
521
|
+
path: "/emails:send",
|
522
|
+
httpMethod: "POST",
|
523
|
+
responses: {
|
524
|
+
202: {
|
525
|
+
headersMapper: EmailSendHeaders
|
526
|
+
},
|
527
|
+
default: {
|
528
|
+
bodyMapper: CommunicationErrorResponse,
|
529
|
+
headersMapper: EmailSendHeaders
|
530
|
+
}
|
531
|
+
},
|
532
|
+
requestBody: emailMessage,
|
533
|
+
queryParameters: [apiVersion],
|
534
|
+
urlParameters: [endpoint],
|
535
|
+
headerParameters: [
|
536
|
+
contentType,
|
537
|
+
repeatabilityRequestId,
|
538
|
+
repeatabilityFirstSent
|
539
|
+
],
|
540
|
+
mediaType: "json",
|
541
|
+
serializer
|
542
|
+
};
|
543
|
+
|
544
|
+
/*
|
545
|
+
* Copyright (c) Microsoft Corporation.
|
546
|
+
* Licensed under the MIT License.
|
547
|
+
*
|
548
|
+
* Code generated by Microsoft (R) AutoRest Code Generator.
|
549
|
+
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
550
|
+
*/
|
551
|
+
const packageName = "@azure/communication-email";
|
552
|
+
const packageVersion = "1.0.0-beta.1";
|
553
|
+
class EmailRestApiClientContext extends coreHttp__namespace.ServiceClient {
|
554
|
+
/**
|
555
|
+
* Initializes a new instance of the EmailRestApiClientContext class.
|
556
|
+
* @param endpoint The communication resource, for example https://my-resource.communication.azure.com
|
557
|
+
* @param options The parameter options
|
558
|
+
*/
|
559
|
+
constructor(endpoint, options) {
|
560
|
+
if (endpoint === undefined) {
|
561
|
+
throw new Error("'endpoint' cannot be null");
|
562
|
+
}
|
563
|
+
// Initializing default values for options
|
564
|
+
if (!options) {
|
565
|
+
options = {};
|
566
|
+
}
|
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}";
|
574
|
+
// Parameter assignments
|
575
|
+
this.endpoint = endpoint;
|
576
|
+
// Assigning values to Constant parameters
|
577
|
+
this.apiVersion = options.apiVersion || "2021-10-01-preview";
|
578
|
+
}
|
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);
|
597
|
+
}
|
598
|
+
}
|
599
|
+
|
600
|
+
// Copyright (c) Microsoft Corporation.
|
601
|
+
// Licensed under the MIT license.
|
602
|
+
const SDK_VERSION = "1.0.0-beta.1";
|
603
|
+
|
604
|
+
// Copyright (c) Microsoft Corporation.
|
605
|
+
/**
|
606
|
+
* The \@azure/logger configuration for this package.
|
607
|
+
*/
|
608
|
+
const logger = logger$1.createClientLogger("communication-email");
|
609
|
+
|
610
|
+
// Copyright (c) Microsoft Corporation.
|
611
|
+
/**
|
612
|
+
* Checks whether the type of a value is EmailClientOptions or not.
|
613
|
+
*
|
614
|
+
* @param options - The value being checked.
|
615
|
+
*/
|
616
|
+
const isEmailClientOptions = (options) => !!options && !communicationCommon.isKeyCredential(options);
|
617
|
+
/**
|
618
|
+
* The Email service client.
|
619
|
+
*/
|
620
|
+
class EmailClient {
|
621
|
+
constructor(connectionStringOrUrl, credentialOrOptions, maybeOptions = {}) {
|
622
|
+
const { url, credential } = communicationCommon.parseClientArguments(connectionStringOrUrl, credentialOrOptions);
|
623
|
+
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
|
+
const internalPipelineOptions = Object.assign(Object.assign({}, options), {
|
635
|
+
loggingOptions: {
|
636
|
+
logger: logger.info,
|
637
|
+
},
|
638
|
+
});
|
639
|
+
const authPolicy = communicationCommon.createCommunicationAuthPolicy(credential);
|
640
|
+
const pipeline = coreHttp.createPipelineFromOptions(internalPipelineOptions, authPolicy);
|
641
|
+
this.api = new EmailRestApiClient(url, pipeline);
|
642
|
+
}
|
643
|
+
/**
|
644
|
+
* Queues an email message to be sent to one or more recipients
|
645
|
+
* @param emailMessage - Message payload for sending an email
|
646
|
+
*/
|
647
|
+
async send(emailMessage) {
|
648
|
+
var _a;
|
649
|
+
const response = await this.api.email.send(uuid.v4(), new Date().toUTCString(), emailMessage);
|
650
|
+
return {
|
651
|
+
messageId: (_a = response.xMsRequestId) !== null && _a !== void 0 ? _a : "",
|
652
|
+
};
|
653
|
+
}
|
654
|
+
/**
|
655
|
+
* Gets the status of a message sent previously.
|
656
|
+
* @param messageId - System generated message id (GUID) returned from a previous call to send email
|
657
|
+
*/
|
658
|
+
async getSendStatus(messageId) {
|
659
|
+
const response = await this.api.email.getSendStatus(messageId);
|
660
|
+
return {
|
661
|
+
messageId: response.messageId,
|
662
|
+
status: response.status,
|
663
|
+
};
|
664
|
+
}
|
665
|
+
}
|
666
|
+
|
667
|
+
exports.EmailClient = EmailClient;
|
668
|
+
//# sourceMappingURL=index.js.map
|