Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[communication] new phone numbers package #13349

Merged
merged 26 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
101b8b9
ctrl+s
0rland0Wats0n Jan 20, 2021
edc2db0
.
0rland0Wats0n Jan 20, 2021
771cf85
ctrl+s
0rland0Wats0n Jan 20, 2021
d9eb0d9
ctrl+s
0rland0Wats0n Jan 21, 2021
d12ea5f
.
0rland0Wats0n Jan 21, 2021
c1a0262
create new phone nnumbers package
0rland0Wats0n Jan 22, 2021
b3b0fbc
.
0rland0Wats0n Jan 22, 2021
c8dc1a0
.
0rland0Wats0n Jan 22, 2021
87bbbae
add managed identity changes
0rland0Wats0n Jan 25, 2021
160eebc
use PhoneNumbersClient in samples to fix build
0rland0Wats0n Jan 25, 2021
cfdd24e
add relevant env vars to tests.yml
0rland0Wats0n Jan 25, 2021
b7aceab
Update sdk/communication/communication-phone-numbers/test/README.md
0rland0Wats0n Jan 26, 2021
d201cf9
Update sdk/communication/communication-phone-numbers/src/utils/logger.ts
0rland0Wats0n Jan 26, 2021
fefc6e7
Update sdk/communication/communication-phone-numbers/src/phoneNumbers…
0rland0Wats0n Jan 26, 2021
12e2567
Update sdk/communication/communication-phone-numbers/src/phoneNumbers…
0rland0Wats0n Jan 26, 2021
70d7c38
Update sdk/communication/communication-phone-numbers/src/phoneNumbers…
0rland0Wats0n Jan 26, 2021
884ab05
Update sdk/communication/communication-phone-numbers/samples/typescri…
0rland0Wats0n Jan 26, 2021
a54bbe6
Update sdk/communication/communication-phone-numbers/samples/typescri…
0rland0Wats0n Jan 26, 2021
177b6e5
Update sdk/communication/communication-phone-numbers/samples/javascri…
0rland0Wats0n Jan 26, 2021
4e806b0
Update sdk/communication/communication-phone-numbers/samples/javascri…
0rland0Wats0n Jan 26, 2021
7a011eb
Update sdk/communication/communication-phone-numbers/src/phoneNumbers…
0rland0Wats0n Jan 26, 2021
263a76d
Update sdk/communication/communication-phone-numbers/README.md
0rland0Wats0n Jan 26, 2021
f8a8300
Update sdk/communication/communication-phone-numbers/src/phoneNumbers…
0rland0Wats0n Jan 26, 2021
58a459b
rebuild to update review
0rland0Wats0n Jan 26, 2021
358c3e8
comment out links reported as broken
0rland0Wats0n Jan 26, 2021
9a0c714
update test
0rland0Wats0n Jan 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 68 additions & 11 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@
"projectFolder": "sdk/communication/communication-common",
"versionPolicyName": "client"
},
{
"packageName": "@azure/communication-phone-numbers",
"projectFolder": "sdk/communication/communication-phone-numbers",
"versionPolicyName": "client"
},
{
"packageName": "@azure/communication-sms",
"projectFolder": "sdk/communication/communication-sms",
Expand Down
2 changes: 2 additions & 0 deletions sdk/communication/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ extends:
safeName: azurecommunicationsms
- name: azure-communication-chat
safeName: azurecommunicationchat
-name: azure-communication-phone-numbers
safeName: azurecommunicationphonenumbers
2 changes: 2 additions & 0 deletions sdk/communication/communication-phone-numbers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/**/code-model-v*
/docGen
10 changes: 10 additions & 0 deletions sdk/communication/communication-phone-numbers/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"include": ["dist-esm/src/**/*.js"],
"exclude": ["**/*.d.ts", "dist-esm/src/generated/*"],
"reporter": ["text-summary", "html", "cobertura"],
"exclude-after-remap": false,
"sourceMap": true,
"produce-source-map": true,
"instrument": true,
"all": true
}
42 changes: 42 additions & 0 deletions sdk/communication/communication-phone-numbers/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Mocha Test [Without Rollup]",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-r",
"ts-node/register",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test/*.spec.ts"
],
"env": { "TS_NODE_COMPILER_OPTIONS": "{\"module\": \"commonjs\"}" },
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"protocol": "inspector"
},
{
"type": "node",
"request": "launch",
"name": "Debug Unit Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/dist-test/index.node.js"
],
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "npm: build:test"
}
]
}
5 changes: 5 additions & 0 deletions sdk/communication/communication-phone-numbers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Release History

## 1.0.0-beta.4 (Unreleased)

The Azure Communication Phone Numbers Client library contains code which facilitates phone number management.
21 changes: 21 additions & 0 deletions sdk/communication/communication-phone-numbers/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2020 Microsoft

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
145 changes: 145 additions & 0 deletions sdk/communication/communication-phone-numbers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Azure Communication Phone Numbers client library for JavaScript

The phone numbers library provides capabilities for phone number administration.

Acquired phone numbers can come with many capabilities, depending on the country, number type and phone plan. Examples of capabilities are SMS inbound and outbound usage, PSTN inbound and outbound usage. Phone numbers can also be assigned to a bot via a webhook URL.

## Getting started

### Prerequisites

- An [Azure subscription][azure_sub].
- 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].

### Installing

```bash
npm install @azure/communication-phone-numbers
```

## Key concepts

The phone numbers package exposes the `PhoneNumbersClient` which provides methods to manage phone numbers.

### Phone plans overview

Phone plans come in two types; Geographic and Toll-Free. Geographic phone plans are phone plans associated with a location, whose phone numbers' area codes are associated with the area code of a geographic location. Toll-Free phone plans are phone plans not associated location. For example, in the US, toll-free numbers can come with area codes such as 800 or 888.

All geographic phone plans within the same country are grouped into a phone plan group with a Geographic phone number type. All Toll-Free phone plans within the same country are grouped into a phone plan group.

### Searching and acquiring numbers

Phone numbers can be searched through the search creation API by providing a phone plan id, an area code and quantity of phone numbers. The provided quantity of phone numbers will be reserved for ten minutes. This search of phone numbers can either be cancelled or purchased. If the search is cancelled, then the phone numbers will become available to others. If the search is purchased, then the phone numbers are acquired for the Azure resource.

### Configuring and assigning numbers

Phone numbers can be assigned to a callback URL via the update number API. As part of the configuration, you will need an acquired phone number, callback URL and application id.

## Examples

## Authentication

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.

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].

Once you have a key, you can authenticate the `PhoneNumbersClient` with any of the following methods:

### Create `KeyCredential` with `AzureKeyCredential`

```typescript
import { AzureKeyCredential } from "@azure/core-auth";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new AzureKeyCredential(KEY);
const client = new PhoneNumbersClient(endpoint, credential);
```

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].

### Using a connection string

```typescript
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const connectionString = `endpoint=HOST;accessKey=KEY`;
const client = new PhoneNumbersClient(connectionString);
```

### Using an Azure Active Directory Credential

Client API key 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:

```bash
npm install @azure/identity
```

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 provides more details and samples to get you started.

```typescript
import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

let credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient(endpoint, credential);
```

## Usage

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:

- [Search for available phone numbers to purchase](#search-for-available-phone-numbers)
- [Purchase phone numbers from a search](#purchase-phone-numbers-from-a-search)
- [Release an acquired phone number](#release-an-acquired-phone-number)
- [Get an acquired phone number](#get-an-acquired-phone-number)
- [Update an acquired phone number](#update-an-acquired-phone-number)
- [List acquired phone numbers](#list-acquired-phone-numbers)

### Search for available phone numbers

Use the `beginSearchAvailablePhoneNumbers` method to search for phone numbers and reserve them. This is a long running operation.

### Purchase phone numbers from a search

Use the `beginPurchasePhoneNumbers` method to purchase the phone numbers from your search. The `id` returned from `beginSearchAvailablePhoneNumbers` is required. `beginPurchasePhoneNumbers` is also a long running operation.

### Release an acquired phone number

Use the `beginReleasePhoneNumber` method to release a previously acquired phone number. This is a long running operation.

### Get an acquired phone number

Use the `getPhoneNumber` method to get an acquired phone number.

### Update an acquired phone number

Use the `updatePhoneNumber` method to update the `callbackUri` and `applicationId` of an acquired phone number.

### List acquired phone numbers

Use the `listPhoneNumbers` method to page through all acquired phone numbers.

## Troubleshooting

## Next steps

Please take a look at the
[samples](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/communication/communication-phone-numbers/samples)
directory for detailed examples on how to use this library.

## Contributing

If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test the code.

## Related projects

- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)

[azure_cli]: https://docs.microsoft.com/cli/azure
[azure_sub]: https://azure.microsoft.com/free/
[azure_portal]: https://portal.azure.com
[azure_powershell]: https://docs.microsoft.com/powershell/module/az.communication/new-azcommunicationservice
[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential
[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcommunication%2Fcommunication-administration%2FREADME.png)
Loading