@azure-tools/communication-short-codes 1.0.0-alpha.20211108.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 (36) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +307 -0
  3. package/dist/index.js +1416 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist-esm/src/generated/src/index.js +12 -0
  6. package/dist-esm/src/generated/src/index.js.map +1 -0
  7. package/dist-esm/src/generated/src/models/index.js +9 -0
  8. package/dist-esm/src/generated/src/models/index.js.map +1 -0
  9. package/dist-esm/src/generated/src/models/mappers.js +746 -0
  10. package/dist-esm/src/generated/src/models/mappers.js.map +1 -0
  11. package/dist-esm/src/generated/src/models/parameters.js +97 -0
  12. package/dist-esm/src/generated/src/models/parameters.js.map +1 -0
  13. package/dist-esm/src/generated/src/operations/index.js +9 -0
  14. package/dist-esm/src/generated/src/operations/index.js.map +1 -0
  15. package/dist-esm/src/generated/src/operations/shortCodes.js +341 -0
  16. package/dist-esm/src/generated/src/operations/shortCodes.js.map +1 -0
  17. package/dist-esm/src/generated/src/shortCodesClient.js +21 -0
  18. package/dist-esm/src/generated/src/shortCodesClient.js.map +1 -0
  19. package/dist-esm/src/generated/src/shortCodesClientContext.js +38 -0
  20. package/dist-esm/src/generated/src/shortCodesClientContext.js.map +1 -0
  21. package/dist-esm/src/index.js +5 -0
  22. package/dist-esm/src/index.js.map +1 -0
  23. package/dist-esm/src/models.js +4 -0
  24. package/dist-esm/src/models.js.map +1 -0
  25. package/dist-esm/src/shortCodesClient.js +133 -0
  26. package/dist-esm/src/shortCodesClient.js.map +1 -0
  27. package/dist-esm/src/utils/constants.js +4 -0
  28. package/dist-esm/src/utils/constants.js.map +1 -0
  29. package/dist-esm/src/utils/index.js +6 -0
  30. package/dist-esm/src/utils/index.js.map +1 -0
  31. package/dist-esm/src/utils/logger.js +8 -0
  32. package/dist-esm/src/utils/logger.js.map +1 -0
  33. package/dist-esm/src/utils/tracing.js +14 -0
  34. package/dist-esm/src/utils/tracing.js.map +1 -0
  35. package/package.json +133 -0
  36. package/types/communication-short-codes.d.ts +298 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Release History
2
+
3
+ ## 1.0.0-beta.1 (2021-11-05)
4
+
5
+ The first preview of the Azure Communication Short Codes Client has the following features:
6
+
7
+ - Management of US Program Briefs
8
+ - Create, Update, Get, List & Delete
9
+ - US Program Brief submission for review to opt for a Short Code
10
+ - List owned Short Codes
package/README.md ADDED
@@ -0,0 +1,307 @@
1
+ # Azure Communication Short Codes client library for JavaScript
2
+
3
+ The phone numbers library provides capabilities for short codes administration.
4
+
5
+ ## Getting started
6
+
7
+ ### Prerequisites
8
+
9
+ - An [Azure subscription][azure_sub].
10
+ - An existing Communication Services resource. If you need to create the resource, you can use the [Azure Portal][azure_portal], the[Azure PowerShell][azure_powershell], or the [Azure CLI][azure_cli].
11
+
12
+ ### Installing
13
+
14
+ ```bash
15
+ npm install @azure-tools/communication-short-codes
16
+ ```
17
+
18
+ ### Browser support
19
+
20
+ #### JavaScript Bundle
21
+
22
+ To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling).
23
+
24
+ ## Key concepts
25
+
26
+ The short codes package exposes the `ShortCodesClient` which provides methods to manage short codes.
27
+
28
+ ### Short Code types
29
+
30
+ Short Codes come in two types; shortCode and alphaId. ShortCode = 5 digit number | alphaId = alphanumeric 5 digit combination.
31
+
32
+ ### Short Codes
33
+
34
+ Short codes are a type of number that are available to enterprise customers. They come in the form of a 5 or 6 digit number and can be used to send sms similar to how a toll-free or geographic number is used. In order to acquire a short code it is necessary to submit an application, or program brief.
35
+
36
+ ### Program Briefs
37
+
38
+ A program brief tracks the application for a short code and contains all the information necessary to process the application as well as information on the status of the application and any updates that may be needed. It can take 8-12 weeks for a program brief to be approved and a short code to be issued once the program brief is submitted.
39
+
40
+ ## Examples
41
+
42
+ ## Authentication
43
+
44
+ To create a client object to access the Communication Services API, you will need a `connection string` or the `endpoint` of your Communication Services resource and a `credential`. The Phone Numbers client can use either Azure Active Directory credentials or an API key credential to authenticate.
45
+
46
+ You can get a key and/or connection string from your Communication Services resource in the [Azure Portal][azure_portal]. You can also find the endpoint for your Communication Services resource in the [Azure Portal][azure_portal].
47
+
48
+ Once you have a key, you can authenticate the `ShortCodesClient` with any of the following methods:
49
+
50
+ ### Using a connection string
51
+
52
+ ```typescript
53
+ import { ShortCodesClient } from "@azure-tools/communication-short-codes";
54
+
55
+ const connectionString = "endpoint=<endpoint>;accessKey=<accessKey>";
56
+ const client = new ShortCodesClient(connectionString);
57
+ ```
58
+
59
+ ### Using an access key with `AzureKeyCredential`
60
+
61
+ If you use a key to initialize the client you will also need to provide the appropriate endpoint. You can get this endpoint from your Communication Services resource in [Azure Portal][azure_portal]. Once you have a key and endpoint, you can authenticate with the following code:
62
+
63
+ ```typescript
64
+ import { AzureKeyCredential } from "@azure/core-auth";
65
+ import { ShortCodesClient } from "@azure-tools/communication-short-codes";
66
+
67
+ const credential = new AzureKeyCredential("<key-from-resource>");
68
+ const client = new ShortCodesClient("<endpoint-from-resource>", credential);
69
+ ```
70
+
71
+ ### Using an Azure Active Directory Credential
72
+
73
+ Connection string authentication is used in most of the examples, but you can also authenticate with Azure Active Directory using the [Azure Identity library][azure_identity]. To use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the [`@azure/identity`][azure_identity] package:
74
+
75
+ ```bash
76
+ npm install @azure/identity
77
+ ```
78
+
79
+ The [`@azure/identity`][azure_identity] package provides a variety of credential types that your application can use to do this. The [README for `@azure/identity`][azure_identity_readme] provides more details and samples to get you started.
80
+
81
+ ```typescript
82
+ import { DefaultAzureCredential } from "@azure/identity";
83
+ import { ShortCodesClient } from "@azure-tools/communication-short-codes";
84
+
85
+ let credential = new DefaultAzureCredential();
86
+ const client = new ShortCodesClient("<endpoint-from-resource>", credential);
87
+ ```
88
+
89
+ ## Usage
90
+
91
+ The following sections provide code snippets that cover some of the common tasks using the Azure Communication Services Phone Numbers client. The scenarios that are covered here consist of:
92
+
93
+ - [Create and submit a program brief](#create-and-submit-program-brief)
94
+ - [Get and delete program briefs](#get-and-delete-program-briefs)
95
+ - [Get and update program brief](#get-and-update-program-brief)
96
+ - [Get short codes](#get-short-codes)
97
+
98
+ ### Create and submit a program brief
99
+ Initialize a `ShortCodesCreateUSProgramBriefParams` object and populate it with the details for your program brief.
100
+
101
+ ```typescript
102
+ import { ShortCodesClient } from "@azure-tools/communication-short-codes";
103
+
104
+ const connectionString = "endpoint=<endpoint>;accessKey=<accessKey>";
105
+ const client = new ShortCodesClient(connectionString);
106
+
107
+ async main function() {
108
+ const programBriefId = "00000000-0000-0000-0000-000000000000";
109
+ const programBriefRequest: ShortCodesCreateUSProgramBriefParams = {
110
+ body: {
111
+ id: programBriefId,
112
+ programDetails: {
113
+ description: "Customers can sign up to receive regular updates on coupons and other perks of our loyalty program.",
114
+ expectedDateOfService: new Date(2022, 1, 25),
115
+ isPoliticalCampaign: false,
116
+ isVanity: false,
117
+ name: "Contoso Loyalty Program",
118
+ numberType: "shortCode",
119
+ privacyPolicyUrl: "https://contoso.com/privacy",
120
+ signUp: "This program will allow customers to receive exclusive offers and information to help them utilize our loyalty program to their best advantage. Customers who opt-in will receive regular coupons they can use in our stores, as well as advanced notice of sales and other promotional and marketing campaigns.",
121
+ signUpTypes: [ "sms", "website" ],
122
+ termsOfServiceUrl: "https://contoso.com/terms",
123
+ url: "https://contoso.com/loyalty-program"
124
+ },
125
+ companyInformation: {
126
+ address: "1 Contoso Way Redmond, WA 98052",
127
+ name: "Contoso",
128
+ url: "contoso.com",
129
+ contactInformation: {
130
+ email: "alex@contoso.com",
131
+ name: "Alex",
132
+ phone: "+14255551234"
133
+ },
134
+ customerCareInformation: {
135
+ email: "customercare@contoso.com",
136
+ tollFreeNumber: "+18005551234"
137
+ }
138
+ },
139
+ messageDetails: {
140
+ types: [ "sms" ],
141
+ recurrence: "subscription",
142
+ contentTypes: [ "coupons", "loyaltyProgram", "loyaltyProgramPointsPrizes" ],
143
+ optInMessage: "Someone requested to subscribe this number to receive updates about Contoso's loyalty program. To confirm subscription, reply to this message with 'JOIN'",
144
+ optInReply: "JOIN",
145
+ confirmationMessage: "Congrats, you have been successfully subscribed to loyalty program updates. Welcome!",
146
+ useCase: "two-way"
147
+ },
148
+ trafficDetails: {
149
+ estimatedVolume: 10000,
150
+ monthlyAverageMessagesFromUser: 1,
151
+ monthlyAverageMessagesToUser: 3,
152
+ isSpiky: true,
153
+ spikeDetails: "Higher traffic expected around major shopping holidays, most notably Black Friday and Memorial Day."
154
+ }
155
+ }
156
+ }
157
+ }
158
+
159
+ main();
160
+ ```
161
+
162
+ Then add a call to `upsertUSProgramBrief` and use the object you created as the parameter. This will create a program brief object which can then be modified as much as needed until it's ready to be submitted.
163
+
164
+ ```typescript
165
+ // create program brief
166
+ var createResponse = await client.upsertUSProgramBrief(programBriefId, programBriefRequest);
167
+ if (createResponse._response.status != 201) {
168
+ throw new Error(`Program brief creation failed.
169
+ Status code: ${createResponse._response.status}; Error: ${createResponse._response.bodyAsText}; CV: ${createResponse._response.headers.get("MS-CV")}`);
170
+ } else {
171
+ console.log(`Successfully created a new program brief with Id ${programBriefId}.`);
172
+ }
173
+ ```
174
+
175
+ When ready to submit, call `submitUSProgramBrief` to submit for processing. After submission no edits will be allowed unless requested as part of the application process.
176
+
177
+ ```typescript
178
+ // submit program brief
179
+ var submittedProgramBrief = await client.submitUSProgramBrief(programBriefId);
180
+ if (submittedProgramBrief._response.status == 200) {
181
+ console.log(`Successfully submitted program brief with Id ${programBriefId}`);
182
+ } else {
183
+ throw new Error(`Failed to submit program brief with Id ${programBriefId}.
184
+ Status code: ${submittedProgramBrief._response.status}; Error: ${submittedProgramBrief._response.bodyAsText}; CV: ${submittedProgramBrief._response.headers.get("MS-CV")}`);
185
+ }
186
+ ```
187
+
188
+ ### Get and delete program briefs
189
+ Use the `listUSProgramBriefs` method to page through all program briefs for an ACS resource. Use `deleteUSProgramBrief` to delete unwanted program briefs. Keep in mind that once a program brief is submitted it is not eligible for deletion.
190
+
191
+ ```typescript
192
+ import { ShortCodesClient } from "@azure-tools/communication-short-codes";
193
+
194
+ const connectionString = "endpoint=<endpoint>;accessKey=<accessKey>";
195
+ const client = new ShortCodesClient(connectionString);
196
+
197
+ async main function() {
198
+ // get all program briefs for a resource
199
+ var programBriefs = await client.listUSProgramBriefs();
200
+
201
+ // find draft program briefs, and delete them
202
+ for await (const programBrief of programBriefs) {
203
+ console.log(`Program Brief with Id ${programBrief.id} has status ${programBrief.status}`);
204
+
205
+ // identify drafts
206
+ if (programBrief.status == 'draft') {
207
+ var unsubmittedProgramBriefId = programBrief.id;
208
+
209
+ // delete draft program brief
210
+ var deleteResponse = await client.deleteUSProgramBrief(unsubmittedProgramBriefId);
211
+ if (deleteResponse._response.status == 200) {
212
+ console.log(`Successfully deleted draft program brief with Id ${unsubmittedProgramBriefId}`);
213
+ } else {
214
+ console.log(`Failed to delete draft program brief with Id ${unsubmittedProgramBriefId}.
215
+ Status code: ${deleteResponse._response.status}; Error: ${deleteResponse._response.bodyAsText}; CV: ${deleteResponse._response.headers.get("MS-CV")}`);
216
+ }
217
+ }
218
+ }
219
+ }
220
+
221
+ main();
222
+ ```
223
+
224
+ ### Get and update program brief
225
+ Use the `getUSProgramBrief` to retrieve a single program brief by its Id. Use the `upsertUSProgramBrief` to update a program brief. `upsertUSProgramBrief` accepts a `ShortCodesUpsertUSProgramBriefOptionalParams` object, in which only the fields that are changing need to be set.
226
+
227
+ ```typescript
228
+ import { ShortCodesClient } from "@azure-tools/communication-short-codes";
229
+
230
+ const connectionString = "endpoint=<endpoint>;accessKey=<accessKey>";
231
+ const client = new ShortCodesClient(connectionString);
232
+
233
+ async main function() {
234
+ // get a program briefs for a resource
235
+ const programBriefId = process.env.PROGRAM_BRIEF_TO_GET || "<program brief Id>";
236
+ var programBrief = await client.getUSProgramBrief(programBriefId);
237
+ console.log(`Program brief with Id ${programBrief.id} has status ${programBrief.status} which was last updated ${programBrief.statusUpdatedDate}`);
238
+
239
+ // update the program brief
240
+ var updateRequest: ShortCodesUpsertUSProgramBriefOptionalParams = {
241
+ body: {
242
+ id: programBriefId,
243
+ programDetails: {
244
+ privacyPolicyUrl: "https://contoso.com/updated-privacy",
245
+ termsOfServiceUrl: "https://contoso.com/updated-terms-of-service"
246
+ }
247
+ }
248
+ };
249
+ var upsertResponse = await client.upsertUSProgramBrief(programBriefId, updateRequest);
250
+ if (upsertResponse._response.status == 200) {
251
+ console.log(`Successfully updated terms of service and privacy policy for program brief ${programBriefId}`);
252
+ } else {
253
+ throw new Error(`Failed to update program brief with Id ${programBriefId}.
254
+ Status code: ${upsertResponse._response.status}; Error: ${upsertResponse._response.bodyAsText}; CV: ${upsertResponse._response.headers.get("MS-CV")}`);
255
+ }
256
+ }
257
+
258
+ main();
259
+ ```
260
+
261
+ ### Get short codes
262
+ Use `listShortCodes` to page through all short codes owned by a resource.
263
+
264
+ ```typescript
265
+ import { ShortCodesClient } from "@azure-tools/communication-short-codes";
266
+
267
+ const connectionString = "endpoint=<endpoint>;accessKey=<accessKey>";
268
+ const client = new ShortCodesClient(connectionString);
269
+
270
+ async main function() {
271
+ // get all short codes for a resource
272
+ var shortCodes = await client.listShortCodes();
273
+
274
+ // print all short codes
275
+ for await (const shortCode of shortCodes) {
276
+ console.log(`${shortCode}`);
277
+ }
278
+ }
279
+
280
+ main();
281
+ ```
282
+
283
+ ## Troubleshooting
284
+
285
+ ## Next steps
286
+
287
+ Please take a look at the
288
+ [samples](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/communication/communication-short-codes/samples)
289
+ directory for detailed examples on how to use this library.
290
+
291
+ ## Contributing
292
+
293
+ If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code.
294
+
295
+ ## Related projects
296
+
297
+ - [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)
298
+
299
+ [azure_cli]: https://docs.microsoft.com/cli/azure
300
+ [azure_sub]: https://azure.microsoft.com/free/
301
+ [azure_portal]: https://portal.azure.com
302
+ [azure_powershell]: https://docs.microsoft.com/powershell/module/az.communication/new-azcommunicationservice
303
+ [defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential
304
+ [azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity
305
+ [azure_identity_readme]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/README.md
306
+
307
+ ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcommunication%2Fcommunication-phone-numbers%2FREADME.png)