@azure/communication-email 1.0.0-beta.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
@@ -0,0 +1,137 @@
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
2
|
+
// Licensed under the MIT license.
|
3
|
+
import { env } from "@azure-tools/test-recorder";
|
4
|
+
import { createRecordedEmailClientWithConnectionString, createRecordedEmailClientWithKeyCredential, } from "./utils/recordedClient";
|
5
|
+
import { assert } from "chai";
|
6
|
+
import { matrix } from "@azure/test-utils";
|
7
|
+
matrix([[true, false]], async function (useKeyCredential) {
|
8
|
+
describe(`EmailClient [Playback/Live]${useKeyCredential ? " [KeyCredential]" : " [ConnectionString]"}`, () => {
|
9
|
+
let recorder;
|
10
|
+
let client;
|
11
|
+
beforeEach(function () {
|
12
|
+
if (useKeyCredential) {
|
13
|
+
({ client, recorder } = createRecordedEmailClientWithKeyCredential(this));
|
14
|
+
}
|
15
|
+
else {
|
16
|
+
({ client, recorder } = createRecordedEmailClientWithConnectionString(this));
|
17
|
+
}
|
18
|
+
});
|
19
|
+
afterEach(async function () {
|
20
|
+
var _a;
|
21
|
+
if (!((_a = this.currentTest) === null || _a === void 0 ? void 0 : _a.isPending())) {
|
22
|
+
await recorder.stop();
|
23
|
+
}
|
24
|
+
});
|
25
|
+
it("successfully sends an email to a single recipient", async function () {
|
26
|
+
const emailMessage = {
|
27
|
+
sender: env.SENDER_ADDRESS,
|
28
|
+
recipients: {
|
29
|
+
to: [
|
30
|
+
{
|
31
|
+
email: env.RECIPIENT_ADDRESS,
|
32
|
+
displayName: "someRecipient",
|
33
|
+
},
|
34
|
+
],
|
35
|
+
},
|
36
|
+
content: {
|
37
|
+
subject: "someSubject",
|
38
|
+
plainText: "somePlainTextBody",
|
39
|
+
html: "<html><h1>someHtmlBody</html>",
|
40
|
+
},
|
41
|
+
};
|
42
|
+
const response = await client.send(emailMessage);
|
43
|
+
assert.isNotNull(response.messageId);
|
44
|
+
}).timeout(5000);
|
45
|
+
it("successfully sends an email to multiple types of recipients", async function () {
|
46
|
+
const emailMessage = {
|
47
|
+
sender: env.SENDER_ADDRESS,
|
48
|
+
recipients: {
|
49
|
+
to: [
|
50
|
+
{
|
51
|
+
email: env.RECIPIENT_ADDRESS,
|
52
|
+
displayName: "someRecipient",
|
53
|
+
},
|
54
|
+
{
|
55
|
+
email: env.RECIPIENT_ADDRESS,
|
56
|
+
displayName: "someRecipient",
|
57
|
+
},
|
58
|
+
],
|
59
|
+
cC: [
|
60
|
+
{
|
61
|
+
email: env.RECIPIENT_ADDRESS,
|
62
|
+
displayName: "someRecipient",
|
63
|
+
},
|
64
|
+
],
|
65
|
+
bCC: [
|
66
|
+
{
|
67
|
+
email: env.RECIPIENT_ADDRESS,
|
68
|
+
displayName: "someRecipient",
|
69
|
+
},
|
70
|
+
],
|
71
|
+
},
|
72
|
+
content: {
|
73
|
+
subject: "someSubject",
|
74
|
+
plainText: "somePlainTextBody",
|
75
|
+
html: "<html><h1>someHtmlBody</html>",
|
76
|
+
},
|
77
|
+
};
|
78
|
+
const response = await client.send(emailMessage);
|
79
|
+
assert.isNotNull(response.messageId);
|
80
|
+
}).timeout(5000);
|
81
|
+
it("successfully sends an email with an attachment", async function () {
|
82
|
+
const emailMessage = {
|
83
|
+
sender: env.SENDER_ADDRESS,
|
84
|
+
recipients: {
|
85
|
+
to: [
|
86
|
+
{
|
87
|
+
email: env.RECIPIENT_ADDRESS,
|
88
|
+
displayName: "someRecipient",
|
89
|
+
},
|
90
|
+
],
|
91
|
+
},
|
92
|
+
content: {
|
93
|
+
subject: "someSubject",
|
94
|
+
plainText: "somePlainTextBody",
|
95
|
+
html: "<html><h1>someHtmlBody</html>",
|
96
|
+
},
|
97
|
+
attachments: [
|
98
|
+
{
|
99
|
+
name: "readme.txt",
|
100
|
+
attachmentType: "txt",
|
101
|
+
contentBytesBase64: "ZW1haWwgdGVzdCBhdHRhY2htZW50",
|
102
|
+
},
|
103
|
+
],
|
104
|
+
};
|
105
|
+
const response = await client.send(emailMessage);
|
106
|
+
assert.isNotNull(response.messageId);
|
107
|
+
}).timeout(5000);
|
108
|
+
it("successfully retrieves the email status with the returned message id", async function () {
|
109
|
+
const emailMessage = {
|
110
|
+
sender: env.SENDER_ADDRESS,
|
111
|
+
recipients: {
|
112
|
+
to: [
|
113
|
+
{
|
114
|
+
email: env.RECIPIENT_ADDRESS,
|
115
|
+
displayName: "someRecipient",
|
116
|
+
},
|
117
|
+
],
|
118
|
+
},
|
119
|
+
content: {
|
120
|
+
subject: "someSubject",
|
121
|
+
plainText: "somePlainTextBody",
|
122
|
+
html: "<html><h1>someHtmlBody</html>",
|
123
|
+
},
|
124
|
+
};
|
125
|
+
const response = await client.send(emailMessage);
|
126
|
+
const messageId = response.messageId;
|
127
|
+
if (messageId) {
|
128
|
+
const messageStatusResponse = await client.getSendStatus(messageId);
|
129
|
+
assert.isNotNull(messageStatusResponse.status);
|
130
|
+
}
|
131
|
+
else {
|
132
|
+
assert.fail();
|
133
|
+
}
|
134
|
+
}).timeout(5000);
|
135
|
+
});
|
136
|
+
});
|
137
|
+
//# sourceMappingURL=emailClient.spec.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"emailClient.spec.js","sourceRoot":"","sources":["../../../test/public/emailClient.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAY,GAAG,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EACL,6CAA6C,EAC7C,0CAA0C,GAC3C,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,K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Q,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACjD,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEjB,EAAE,CAAC,sEAAsE,EAAE,KAAK;YAC9E,MAAM,YAAY,GAAiB;gBACjC,MAAM,EAAE,GAAG,CAAC,cAAc;gBAC1B,UAAU,EAAE;oBACV,EAAE,EAAE;wBACF;4BACE,KAAK,EAAE,GAAG,CAAC,iBAAiB;4BAC5B,WAAW,EAAE,eAAe;yBAC7B;qBACF;iBACF;gBACD,OAAO,EAAE;oBACP,OAAO,EAAE,aAAa;oBACtB,SAAS,EAAE,mBAAmB;oBAC9B,IAAI,EAAE,+BAA+B;iBACtC;aACF,CAAC;YAEF,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACjD,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC;YACrC,IAAI,SAAS,EAAE;gBACb,MAAM,qBAAqB,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;gBACpE,MAAM,CAAC,SAAS,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;aAChD;iBAAM;gBACL,MAAM,CAAC,IAAI,EAAE,CAAC;aACf;QACH,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { EmailClient, EmailMessage } from \"../../src\";\nimport { Recorder, env } from \"@azure-tools/test-recorder\";\nimport {\n createRecordedEmailClientWithConnectionString,\n createRecordedEmailClientWithKeyCredential,\n} from \"./utils/recordedClient\";\nimport { Context } from \"mocha\";\nimport { assert } from \"chai\";\nimport { matrix } from \"@azure/test-utils\";\n\nmatrix([[true, false]], async function (useKeyCredential) {\n describe(`EmailClient [Playback/Live]${\n useKeyCredential ? \" [KeyCredential]\" : \" [ConnectionString]\"\n }`, () => {\n let recorder: Recorder;\n let client: EmailClient;\n\n beforeEach(function (this: Context) {\n if (useKeyCredential) {\n ({ client, recorder } = createRecordedEmailClientWithKeyCredential(this));\n } else {\n ({ client, recorder } = createRecordedEmailClientWithConnectionString(this));\n }\n });\n\n afterEach(async function (this: Context) {\n if (!this.currentTest?.isPending()) {\n await recorder.stop();\n }\n });\n\n it(\"successfully sends an email to a single recipient\", async function () {\n const emailMessage: EmailMessage = {\n sender: env.SENDER_ADDRESS,\n recipients: {\n to: [\n {\n email: env.RECIPIENT_ADDRESS,\n displayName: \"someRecipient\",\n },\n ],\n },\n content: {\n subject: \"someSubject\",\n plainText: \"somePlainTextBody\",\n html: \"<html><h1>someHtmlBody</html>\",\n },\n };\n\n const response = await client.send(emailMessage);\n assert.isNotNull(response.messageId);\n }).timeout(5000);\n\n it(\"successfully sends an email to multiple types of recipients\", async function () {\n const emailMessage: EmailMessage = {\n sender: env.SENDER_ADDRESS,\n recipients: {\n to: [\n {\n email: env.RECIPIENT_ADDRESS,\n displayName: \"someRecipient\",\n },\n {\n email: env.RECIPIENT_ADDRESS,\n displayName: \"someRecipient\",\n },\n ],\n cC: [\n {\n email: env.RECIPIENT_ADDRESS,\n displayName: \"someRecipient\",\n },\n ],\n bCC: [\n {\n email: env.RECIPIENT_ADDRESS,\n displayName: \"someRecipient\",\n },\n ],\n },\n content: {\n subject: \"someSubject\",\n plainText: \"somePlainTextBody\",\n html: \"<html><h1>someHtmlBody</html>\",\n },\n };\n\n const response = await client.send(emailMessage);\n assert.isNotNull(response.messageId);\n }).timeout(5000);\n\n it(\"successfully sends an email with an attachment\", async function () {\n const emailMessage: EmailMessage = {\n sender: env.SENDER_ADDRESS,\n recipients: {\n to: [\n {\n email: env.RECIPIENT_ADDRESS,\n displayName: \"someRecipient\",\n },\n ],\n },\n content: {\n subject: \"someSubject\",\n plainText: \"somePlainTextBody\",\n html: \"<html><h1>someHtmlBody</html>\",\n },\n attachments: [\n {\n name: \"readme.txt\",\n attachmentType: \"txt\",\n contentBytesBase64: \"ZW1haWwgdGVzdCBhdHRhY2htZW50\",\n },\n ],\n };\n\n const response = await client.send(emailMessage);\n assert.isNotNull(response.messageId);\n }).timeout(5000);\n\n it(\"successfully retrieves the email status with the returned message id\", async function () {\n const emailMessage: EmailMessage = {\n sender: env.SENDER_ADDRESS,\n recipients: {\n to: [\n {\n email: env.RECIPIENT_ADDRESS,\n displayName: \"someRecipient\",\n },\n ],\n },\n content: {\n subject: \"someSubject\",\n plainText: \"somePlainTextBody\",\n html: \"<html><h1>someHtmlBody</html>\",\n },\n };\n\n const response = await client.send(emailMessage);\n const messageId = response.messageId;\n if (messageId) {\n const messageStatusResponse = await client.getSendStatus(messageId);\n assert.isNotNull(messageStatusResponse.status);\n } else {\n assert.fail();\n }\n }).timeout(5000);\n });\n});\n"]}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
2
|
+
// Licensed under the MIT license.
|
3
|
+
import * as dotenv from "dotenv";
|
4
|
+
import { env, record } from "@azure-tools/test-recorder";
|
5
|
+
import { EmailClient } from "../../../src";
|
6
|
+
import { isNode } from "@azure/core-http";
|
7
|
+
import { parseConnectionString } from "@azure/communication-common";
|
8
|
+
if (isNode) {
|
9
|
+
dotenv.config();
|
10
|
+
}
|
11
|
+
const replaceableVariables = {
|
12
|
+
COMMUNICATION_CONNECTION_STRING: "endpoint=https://someEndpoint/;accesskey=someAccessKeyw==",
|
13
|
+
SENDER_ADDRESS: "someSender@contoso.com",
|
14
|
+
RECIPIENT_ADDRESS: "someRecipient@domain.com",
|
15
|
+
};
|
16
|
+
export const environmentSetup = {
|
17
|
+
replaceableVariables: replaceableVariables,
|
18
|
+
customizationsOnRecordings: [
|
19
|
+
(recording) => recording.replace(/(https:\/\/)([^/',]*)/, "$1someEndpoint"),
|
20
|
+
(recording) => recording.replace(/("sender":)("(.*?)")/, "$1" + '"someSender@contoso.com"'),
|
21
|
+
(recording) => recording.replace(/("email":)("(.*?)")/g, "$1" + '"someRecipient@domain.com"'),
|
22
|
+
(recording) => recording.replace(/('Operation-Location',[\r\n] {2})'(.*?)'/, "$1" + '"someOperationLocation"'),
|
23
|
+
(recording) => recording.replace(/"operation-location"\s?:\s?"[^"]*"/g, '"operation-location": "someOperationLocation"'),
|
24
|
+
(recording) => recording.replace(/('x-ms-request-id',[\r\n] {2})'(.*?)'/, "$1" + '"someRequestId"'),
|
25
|
+
(recording) => recording.replace(/"x-ms-request-id"\s?:\s?"[^"]*"/g, '"x-ms-request-id": "someRequestId"'),
|
26
|
+
(recording) => recording.replace(/("messageId":)("(.*?)")/g, "$1" + '"someRequestId"'),
|
27
|
+
(recording) => recording.replace(/emails\/[^"']*/g, "emails/someRequestId/status"),
|
28
|
+
],
|
29
|
+
queryParametersToSkip: [],
|
30
|
+
};
|
31
|
+
export function createRecordedEmailClientWithConnectionString(context) {
|
32
|
+
const recorder = record(context, environmentSetup);
|
33
|
+
return {
|
34
|
+
client: new EmailClient(env.COMMUNICATION_CONNECTION_STRING),
|
35
|
+
recorder,
|
36
|
+
};
|
37
|
+
}
|
38
|
+
export function createRecordedEmailClientWithKeyCredential(context) {
|
39
|
+
const recorder = record(context, environmentSetup);
|
40
|
+
const { endpoint, credential } = parseConnectionString(env.COMMUNICATION_CONNECTION_STRING);
|
41
|
+
return {
|
42
|
+
client: new EmailClient(endpoint, credential),
|
43
|
+
recorder,
|
44
|
+
};
|
45
|
+
}
|
46
|
+
//# sourceMappingURL=recordedClient.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"recordedClient.js","sourceRoot":"","sources":["../../../../test/public/utils/recordedClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAsC,GAAG,EAAE,MAAM,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AI,GAAG,iBAAiB,CAAC;QACzE,CAAC,SAAiB,EAAU,EAAE,CAC5B,SAAS,CAAC,OAAO,CAAC,iBAAiB,EAAE,6BAA6B,CAAC;KACtE;IACD,qBAAqB,EAAE,EAAE;CAC1B,CAAC;AAEF,MAAM,UAAU,6CAA6C,CAC3D,OAAgB;IAEhB,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAEnD,OAAO;QACL,MAAM,EAAE,IAAI,WAAW,CAAC,GAAG,CAAC,+BAA+B,CAAC;QAC5D,QAAQ;KACT,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0CAA0C,CAAC,OAAgB;IACzE,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAEnD,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,qBAAqB,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAE5F,OAAO;QACL,MAAM,EAAE,IAAI,WAAW,CAAC,QAAQ,EAAE,UAAU,CAAC;QAC7C,QAAQ;KACT,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as dotenv from \"dotenv\";\nimport { Recorder, RecorderEnvironmentSetup, env, record } from \"@azure-tools/test-recorder\";\nimport { Context } from \"mocha\";\nimport { EmailClient } from \"../../../src\";\nimport { isNode } from \"@azure/core-http\";\nimport { parseConnectionString } from \"@azure/communication-common\";\n\nif (isNode) {\n dotenv.config();\n}\n\nexport interface RecordedEmailClient {\n client: EmailClient;\n recorder: Recorder;\n}\n\nconst replaceableVariables: { [k: string]: string } = {\n COMMUNICATION_CONNECTION_STRING: \"endpoint=https://someEndpoint/;accesskey=someAccessKeyw==\",\n SENDER_ADDRESS: \"someSender@contoso.com\",\n RECIPIENT_ADDRESS: \"someRecipient@domain.com\",\n};\n\nexport const environmentSetup: RecorderEnvironmentSetup = {\n replaceableVariables: replaceableVariables,\n customizationsOnRecordings: [\n (recording: string): string => recording.replace(/(https:\\/\\/)([^/',]*)/, \"$1someEndpoint\"),\n (recording: string): string =>\n recording.replace(/(\"sender\":)(\"(.*?)\")/, \"$1\" + '\"someSender@contoso.com\"'),\n (recording: string): string =>\n recording.replace(/(\"email\":)(\"(.*?)\")/g, \"$1\" + '\"someRecipient@domain.com\"'),\n (recording: string): string =>\n recording.replace(\n /('Operation-Location',[\\r\\n] {2})'(.*?)'/,\n \"$1\" + '\"someOperationLocation\"'\n ),\n (recording: string): string =>\n recording.replace(\n /\"operation-location\"\\s?:\\s?\"[^\"]*\"/g,\n '\"operation-location\": \"someOperationLocation\"'\n ),\n (recording: string): string =>\n recording.replace(/('x-ms-request-id',[\\r\\n] {2})'(.*?)'/, \"$1\" + '\"someRequestId\"'),\n (recording: string): string =>\n recording.replace(/\"x-ms-request-id\"\\s?:\\s?\"[^\"]*\"/g, '\"x-ms-request-id\": \"someRequestId\"'),\n (recording: string): string =>\n recording.replace(/(\"messageId\":)(\"(.*?)\")/g, \"$1\" + '\"someRequestId\"'),\n (recording: string): string =>\n recording.replace(/emails\\/[^\"']*/g, \"emails/someRequestId/status\"),\n ],\n queryParametersToSkip: [],\n};\n\nexport function createRecordedEmailClientWithConnectionString(\n context: Context\n): RecordedEmailClient {\n const recorder = record(context, environmentSetup);\n\n return {\n client: new EmailClient(env.COMMUNICATION_CONNECTION_STRING),\n recorder,\n };\n}\n\nexport function createRecordedEmailClientWithKeyCredential(context: Context): RecordedEmailClient {\n const recorder = record(context, environmentSetup);\n\n const { endpoint, credential } = parseConnectionString(env.COMMUNICATION_CONNECTION_STRING);\n\n return {\n client: new EmailClient(endpoint, credential),\n recorder,\n };\n}\n"]}
|
package/package.json
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
{
|
2
|
+
"name": "@azure/communication-email",
|
3
|
+
"version": "1.0.0-beta.1",
|
4
|
+
"description": "The is the JS Client SDK for email. This SDK enables users to send emails and get the status of sent email message.",
|
5
|
+
"author": "Microsoft Corporation",
|
6
|
+
"license": "MIT",
|
7
|
+
"sdk-type": "client",
|
8
|
+
"main": "dist/index.js",
|
9
|
+
"module": "dist-esm/src/index.js",
|
10
|
+
"types": "types/communication-email.d.ts",
|
11
|
+
"scripts": {
|
12
|
+
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
|
13
|
+
"build": "npm run clean && tsc -p . && dev-tool run bundle --browser-test=false && api-extractor run --local",
|
14
|
+
"build:samples": "dev-tool samples publish -f",
|
15
|
+
"build:test": "tsc -p . && dev-tool run bundle",
|
16
|
+
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
|
17
|
+
"clean": "rimraf dist dist-* temp types *.tgz *.log",
|
18
|
+
"execute:samples": "dev-tool samples run samples-dev",
|
19
|
+
"extract-api": "tsc -p . && api-extractor run --local",
|
20
|
+
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
|
21
|
+
"integration-test:browser": "karma start --single-run",
|
22
|
+
"integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000 dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js",
|
23
|
+
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
|
24
|
+
"lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
|
25
|
+
"lint": "eslint package.json api-extractor.json src test --ext .ts",
|
26
|
+
"pack": "npm pack 2>&1",
|
27
|
+
"test": "npm run build:test && npm run unit-test && npm run integration-test",
|
28
|
+
"test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
|
29
|
+
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
|
30
|
+
"unit-test:browser": "karma start --single-run",
|
31
|
+
"unit-test:node": "mocha -r esm -r ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace --exclude \"test/**/browser/*.spec.ts\" \"test/**/*.spec.ts\"",
|
32
|
+
"unit-test": "npm run unit-test:node && npm run unit-test:browser"
|
33
|
+
},
|
34
|
+
"files": [
|
35
|
+
"dist/",
|
36
|
+
"dist-esm/",
|
37
|
+
"types/communication-email.d.ts",
|
38
|
+
"README.md",
|
39
|
+
"LICENSE"
|
40
|
+
],
|
41
|
+
"repository": "github:Azure/azure-sdk-for-js",
|
42
|
+
"keywords": [
|
43
|
+
"azure",
|
44
|
+
"cloud",
|
45
|
+
"communication",
|
46
|
+
"email"
|
47
|
+
],
|
48
|
+
"dependencies": {
|
49
|
+
"@azure/core-auth": "^1.3.0",
|
50
|
+
"@azure/core-http": "^2.0.0",
|
51
|
+
"@azure/communication-common": "^1.1.0",
|
52
|
+
"@azure/logger": "^1.0.0",
|
53
|
+
"tslib": "^1.9.3",
|
54
|
+
"uuid": "^8.3.2"
|
55
|
+
},
|
56
|
+
"devDependencies": {
|
57
|
+
"@azure/dev-tool": "^1.0.0",
|
58
|
+
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
|
59
|
+
"@azure/test-utils": "^1.0.0",
|
60
|
+
"@azure-tools/test-recorder": "^1.0.0",
|
61
|
+
"@microsoft/api-extractor": "7.18.11",
|
62
|
+
"@types/node": "^12.0.0",
|
63
|
+
"@types/uuid": "^8.3.2",
|
64
|
+
"@types/chai": "^4.1.6",
|
65
|
+
"@types/mocha": "^7.0.2",
|
66
|
+
"chai": "^4.2.0",
|
67
|
+
"dotenv": "^8.2.0",
|
68
|
+
"eslint": "^7.15.0",
|
69
|
+
"karma": "^6.2.0",
|
70
|
+
"karma-chrome-launcher": "^3.0.0",
|
71
|
+
"karma-coverage": "^2.0.0",
|
72
|
+
"karma-edge-launcher": "^0.4.2",
|
73
|
+
"karma-env-preprocessor": "^0.1.1",
|
74
|
+
"karma-firefox-launcher": "^1.1.0",
|
75
|
+
"karma-ie-launcher": "^1.0.0",
|
76
|
+
"karma-json-preprocessor": "^0.3.3",
|
77
|
+
"karma-json-to-file-reporter": "^1.0.1",
|
78
|
+
"karma-junit-reporter": "^2.0.1",
|
79
|
+
"karma-mocha": "^2.0.1",
|
80
|
+
"karma-mocha-reporter": "^2.2.5",
|
81
|
+
"karma-sourcemap-loader": "^0.3.8",
|
82
|
+
"mocha": "^7.1.1",
|
83
|
+
"mocha-junit-reporter": "^2.0.0",
|
84
|
+
"nyc": "^15.0.0",
|
85
|
+
"typescript": "~4.2.0",
|
86
|
+
"prettier": "^2.5.1",
|
87
|
+
"rimraf": "^3.0.0"
|
88
|
+
},
|
89
|
+
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-email/",
|
90
|
+
"bugs": {
|
91
|
+
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
|
92
|
+
},
|
93
|
+
"engines": {
|
94
|
+
"node": ">=12.0.0"
|
95
|
+
},
|
96
|
+
"sideEffects": false,
|
97
|
+
"autoPublish": true,
|
98
|
+
"//sampleConfiguration": {
|
99
|
+
"productName": "Azure Communication Services - Email",
|
100
|
+
"productSlugs": [
|
101
|
+
"azure",
|
102
|
+
"azure-communication-services"
|
103
|
+
],
|
104
|
+
"disableDocsMs": true,
|
105
|
+
"requiredResources": {
|
106
|
+
"Azure Communication Services Resource": "https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource",
|
107
|
+
"Email Communication Services Resource": "https://aka.ms/acsemail/createemailresource"
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
@@ -0,0 +1,200 @@
|
|
1
|
+
import { KeyCredential } from '@azure/core-auth';
|
2
|
+
import { PipelineOptions } from '@azure/core-http';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* An object representing the email address and its display name
|
6
|
+
*/
|
7
|
+
export declare interface EmailAddress {
|
8
|
+
/**
|
9
|
+
* Email address.
|
10
|
+
*/
|
11
|
+
email: string;
|
12
|
+
/**
|
13
|
+
* Email display name.
|
14
|
+
*/
|
15
|
+
displayName?: string;
|
16
|
+
}
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Attachment to the email.
|
20
|
+
*/
|
21
|
+
export declare interface EmailAttachment {
|
22
|
+
/**
|
23
|
+
* Name of the attachment
|
24
|
+
*/
|
25
|
+
name: string;
|
26
|
+
/**
|
27
|
+
* The type of attachment file.
|
28
|
+
*/
|
29
|
+
attachmentType: EmailAttachmentType;
|
30
|
+
/**
|
31
|
+
* Base64 encoded contents of the attachment
|
32
|
+
*/
|
33
|
+
contentBytesBase64: string;
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Defines values for EmailAttachmentType.
|
38
|
+
*/
|
39
|
+
export declare type EmailAttachmentType = "avi" | "bmp" | "doc" | "docm" | "docx" | "gif" | "jpeg" | "mp3" | "one" | "pdf" | "png" | "ppsm" | "ppsx" | "ppt" | "pptm" | "pptx" | "pub" | "rpmsg" | "rtf" | "tif" | "txt" | "vsd" | "wav" | "wma" | "xls" | "xlsb" | "xlsm" | "xlsx";
|
40
|
+
|
41
|
+
/**
|
42
|
+
* The Email service client.
|
43
|
+
*/
|
44
|
+
export declare class EmailClient {
|
45
|
+
private readonly api;
|
46
|
+
/**
|
47
|
+
* Initializes a new instance of the EmailClient class.
|
48
|
+
* @param connectionString - Connection string to connect to an Azure Communication Service resource.
|
49
|
+
* Example: "endpoint=https://contoso.eastus.communications.azure.net/;accesskey=secret";
|
50
|
+
* @param options - Optional. Options to configure the HTTP pipeline.
|
51
|
+
*/
|
52
|
+
constructor(connectionString: string, options?: EmailClientOptions);
|
53
|
+
/**
|
54
|
+
* Initializes a new instance of the EmailClient class using an Azure KeyCredential.
|
55
|
+
* @param endpoint - The endpoint of the service (ex: https://contoso.eastus.communications.azure.net).
|
56
|
+
* @param credential - An object that is used to authenticate requests to the service. Use the Azure KeyCredential or `@azure/identity` to create a credential.
|
57
|
+
* @param options - Optional. Options to configure the HTTP pipeline.
|
58
|
+
*/
|
59
|
+
constructor(endpoint: string, credential: KeyCredential, options?: EmailClientOptions);
|
60
|
+
/**
|
61
|
+
* Queues an email message to be sent to one or more recipients
|
62
|
+
* @param emailMessage - Message payload for sending an email
|
63
|
+
*/
|
64
|
+
send(emailMessage: EmailMessage): Promise<SendEmailResult>;
|
65
|
+
/**
|
66
|
+
* Gets the status of a message sent previously.
|
67
|
+
* @param messageId - System generated message id (GUID) returned from a previous call to send email
|
68
|
+
*/
|
69
|
+
getSendStatus(messageId: string): Promise<SendStatusResult>;
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Client options used to configure SMS Client API requests.
|
74
|
+
*/
|
75
|
+
export declare interface EmailClientOptions extends PipelineOptions {
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Content of the email.
|
80
|
+
*/
|
81
|
+
export declare interface EmailContent {
|
82
|
+
/**
|
83
|
+
* Subject of the email message
|
84
|
+
*/
|
85
|
+
subject: string;
|
86
|
+
/**
|
87
|
+
* Plain text version of the email message.
|
88
|
+
*/
|
89
|
+
plainText?: string;
|
90
|
+
/**
|
91
|
+
* Html version of the email message.
|
92
|
+
*/
|
93
|
+
html?: string;
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Custom header for email.
|
98
|
+
*/
|
99
|
+
export declare interface EmailCustomHeader {
|
100
|
+
/**
|
101
|
+
* Header name.
|
102
|
+
*/
|
103
|
+
name: string;
|
104
|
+
/**
|
105
|
+
* Header value.
|
106
|
+
*/
|
107
|
+
value: string;
|
108
|
+
}
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Defines values for EmailImportance.
|
112
|
+
*/
|
113
|
+
export declare type EmailImportance = "high" | "normal" | "low";
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Message payload for sending an email
|
117
|
+
*/
|
118
|
+
export declare interface EmailMessage {
|
119
|
+
/**
|
120
|
+
* Custom email headers to be passed.
|
121
|
+
*/
|
122
|
+
customHeaders?: EmailCustomHeader[];
|
123
|
+
/**
|
124
|
+
* Sender email address from a verified domain.
|
125
|
+
*/
|
126
|
+
sender: string;
|
127
|
+
/**
|
128
|
+
* Email content to be sent.
|
129
|
+
*/
|
130
|
+
content: EmailContent;
|
131
|
+
/**
|
132
|
+
* The importance type for the email.
|
133
|
+
*/
|
134
|
+
importance?: EmailImportance;
|
135
|
+
/**
|
136
|
+
* Recipients for the email.
|
137
|
+
*/
|
138
|
+
recipients: EmailRecipients;
|
139
|
+
/**
|
140
|
+
* list of attachments
|
141
|
+
*/
|
142
|
+
attachments?: EmailAttachment[];
|
143
|
+
/**
|
144
|
+
* Email addresses where recipients' replies will be sent to.
|
145
|
+
*/
|
146
|
+
replyTo?: EmailAddress[];
|
147
|
+
/**
|
148
|
+
* 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
|
+
*/
|
150
|
+
disableUserEngagementTracking?: boolean;
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Recipients of the email
|
155
|
+
*/
|
156
|
+
export declare interface EmailRecipients {
|
157
|
+
/**
|
158
|
+
* Email to recipients
|
159
|
+
*/
|
160
|
+
to: EmailAddress[];
|
161
|
+
/**
|
162
|
+
* Email cc recipients
|
163
|
+
*/
|
164
|
+
cC?: EmailAddress[];
|
165
|
+
/**
|
166
|
+
* Email bcc recipients
|
167
|
+
*/
|
168
|
+
bCC?: EmailAddress[];
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* Results of a sent email.
|
173
|
+
*/
|
174
|
+
export declare interface SendEmailResult {
|
175
|
+
/**
|
176
|
+
* MessageId of the sent email.
|
177
|
+
*/
|
178
|
+
messageId: string;
|
179
|
+
}
|
180
|
+
|
181
|
+
/**
|
182
|
+
* Defines values for SendStatus.
|
183
|
+
*/
|
184
|
+
export declare type SendStatus = "queued" | "outForDelivery" | "dropped";
|
185
|
+
|
186
|
+
/**
|
187
|
+
* Status of an email message that was sent previously.
|
188
|
+
*/
|
189
|
+
export declare interface SendStatusResult {
|
190
|
+
/**
|
191
|
+
* System generated id of an email message sent.
|
192
|
+
*/
|
193
|
+
messageId: string;
|
194
|
+
/**
|
195
|
+
* The type indicating the status of a request.
|
196
|
+
*/
|
197
|
+
status: SendStatus;
|
198
|
+
}
|
199
|
+
|
200
|
+
export { }
|