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] update new phone numbers client #13560

Merged
merged 46 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
46 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
66edf4c
.
0rland0Wats0n Jan 27, 2021
75a8fb2
regenerate
0rland0Wats0n Jan 28, 2021
41e5212
add header tests
0rland0Wats0n Feb 3, 2021
66b94f3
formatted
0rland0Wats0n Feb 3, 2021
7dc19d7
add getPhoneNumber tests
0rland0Wats0n Feb 3, 2021
f5224cb
add update tests
0rland0Wats0n Feb 3, 2021
45abc50
Merge branch 'master' of github.com:Azure/azure-sdk-for-js into redes…
0rland0Wats0n Feb 3, 2021
1162146
Merge branch 'feature/communication/new-phone-numbers' of github.com:…
0rland0Wats0n Feb 3, 2021
b0d5d8e
Merge branch 'feature/communication/new-phone-numbers' of github.com:…
0rland0Wats0n Feb 3, 2021
f9715df
update autorest.typescript version and regen
0rland0Wats0n Feb 4, 2021
2f56a28
update list method
0rland0Wats0n Feb 5, 2021
0e646f5
ctrl+s
0rland0Wats0n Feb 5, 2021
040471a
.
0rland0Wats0n Feb 5, 2021
0ad1e2d
add remaining lro tests
0rland0Wats0n Feb 10, 2021
05ada55
.
0rland0Wats0n Feb 10, 2021
cc15101
Delete .gitKeep
0rland0Wats0n Feb 10, 2021
d134c20
.
0rland0Wats0n Feb 10, 2021
0948ebd
.
0rland0Wats0n Feb 16, 2021
9ae961a
.
0rland0Wats0n Feb 16, 2021
f362fd6
.
0rland0Wats0n Feb 16, 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
215 changes: 108 additions & 107 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module.exports = function(config) {
"TEST_MODE",
"COMMUNICATION_CONNECTION_STRING",
"INCLUDE_PHONENUMBER_TESTS",
"AZURE_PHONE_NUMBER",
"COMMUNICATION_ENDPOINT"
],

Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/communication-phone-numbers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"lint": "eslint package.json tsconfig.json api-extractor.json src test --ext .ts -f html -o communication-phone-numbers-lintReport.html || exit 0",
"pack": "npm pack 2>&1",
"prebuild": "npm run clean",
"test": "npm run build:test && npm run unit-test && npm run integration-test",
"test": "rimraf dist-test && npm run build:test && npm run unit-test && npm run integration-test",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we need to add rimraf here?

"test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
"test:watch": "npm run test -- --watch --reporter min",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,24 @@ import { HttpResponse } from '@azure/core-http';
import { KeyCredential } from '@azure/core-auth';
import { OperationOptions } from '@azure/core-http';
import { PagedAsyncIterableIterator } from '@azure/core-paging';
import { PageSettings } from '@azure/core-paging';
import { PipelineOptions } from '@azure/core-http';
import { PollerLike } from '@azure/core-lro';
import { PollOperationState } from '@azure/core-lro';
import { TokenCredential } from '@azure/core-auth';

// @public
export interface AcquiredPhoneNumber {
applicationId: string;
applicationId?: string;
assignmentType: PhoneNumberAssignmentType;
callbackUri: string;
callbackUri?: string;
capabilities: PhoneNumberCapabilities;
cost: PhoneNumberCost;
cost?: PhoneNumberCost;
countryCode: string;
id: string;
phoneNumber: string;
phoneNumberType: PhoneNumberType;
purchaseDate: Date;
}

// @public
export interface AcquiredPhoneNumberUpdate {
applicationId?: string;
callbackUri?: string;
purchaseDate?: Date;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up: These will change again in a future swagger, applicationId and callbackUri are going away, cost and purchaseDate will become required.

}

// @public (undocumented)
Expand All @@ -49,17 +44,57 @@ export interface BeginSearchAvailablePhoneNumbersOptions extends PhoneNumberPoll
export interface BeginUpdatePhoneNumberOptions extends PhoneNumberPollerOptionsBase, OperationOptions {
}

// @public
export type BillingFrequency = string;

// @public (undocumented)
export type GetPhoneNumberOptions = OperationOptions;

// @public (undocumented)
export type GetPhoneNumberResponse = WithResponse<AcquiredPhoneNumber>;

// @public (undocumented)
export type ListPhoneNumbersOptions = OperationOptions;
// @public
export const enum KnownBillingFrequency {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this Known prefix come from?

// (undocumented)
Monthly = "monthly"
}

// @public
export type PhoneNumberAssignmentType = "person" | "application";
export const enum KnownPhoneNumberAssignmentType {
// (undocumented)
Application = "application",
// (undocumented)
User = "user"
}

// @public
export const enum KnownPhoneNumberCapabilityValue {
// (undocumented)
Inbound = "inbound",
// (undocumented)
InboundOutbound = "inbound+outbound",
// (undocumented)
None = "none",
// (undocumented)
Outbound = "outbound"
}

// @public
export const enum KnownPhoneNumberType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did autorest change how it models extensible enums? I would have expected string unions (and prefer them from a TS language perspective :-( )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea this changed with the version of autorest/ts I got to fix the LRO problem.

// (undocumented)
Geographic = "geographic",
// (undocumented)
TollFree = "tollFree"
}

// @public
export interface ListPhoneNumbersOptions extends OperationOptions {
skip?: number;
top?: number;
}

// @public
export type PhoneNumberAssignmentType = string;

// @public
export interface PhoneNumberCapabilities {
Expand All @@ -74,12 +109,12 @@ export interface PhoneNumberCapabilitiesRequest {
}

// @public
export type PhoneNumberCapabilityValue = "inbound" | "outbound" | "inbound+outbound" | "none";
export type PhoneNumberCapabilityValue = string;

// @public
export interface PhoneNumberCost {
amount: number;
billingFrequency: "monthly";
billingFrequency: BillingFrequency;
currencyCode: string;
}

Expand All @@ -101,8 +136,7 @@ export class PhoneNumbersClient {
beginSearchAvailablePhoneNumbers(countryCode: string, search: PhoneNumberSearchRequest, options?: BeginSearchAvailablePhoneNumbersOptions): Promise<PollerLike<PollOperationState<PhoneNumberSearchResult>, PhoneNumberSearchResult>>;
beginUpdatePhoneNumberCapabilities(phoneNumber: string, request: PhoneNumberCapabilitiesRequest, options?: BeginUpdatePhoneNumberOptions): Promise<PollerLike<PollOperationState<AcquiredPhoneNumber>, AcquiredPhoneNumber>>;
getPhoneNumber(phoneNumber: string, options?: GetPhoneNumberOptions): Promise<GetPhoneNumberResponse>;
listPhoneNumbers(options?: ListPhoneNumbersOptions): PagedAsyncIterableIterator<AcquiredPhoneNumber>;
updatePhoneNumber(phoneNumber: string, update: AcquiredPhoneNumberUpdate, options?: UpdatePhoneNumberOptions): Promise<UpdatePhoneNumberResponse>;
listPhoneNumbers(options?: ListPhoneNumbersOptions): PagedAsyncIterableIterator<AcquiredPhoneNumber, AcquiredPhoneNumber[], PageSettings>;
}

// @public
Expand All @@ -111,9 +145,9 @@ export interface PhoneNumbersClientOptions extends PipelineOptions {

// @public
export interface PhoneNumberSearchRequest {
areaCode?: string;
areaCode: string;
assignmentType: PhoneNumberAssignmentType;
capabilities: PhoneNumberCapabilitiesRequest;
capabilities: PhoneNumberCapabilities;
phoneNumberType: PhoneNumberType;
quantity?: number;
}
Expand All @@ -122,21 +156,15 @@ export interface PhoneNumberSearchRequest {
export interface PhoneNumberSearchResult {
assignmentType: PhoneNumberAssignmentType;
capabilities: PhoneNumberCapabilities;
cost: PhoneNumberCost;
id: string;
cost?: PhoneNumberCost;
phoneNumbers: string[];
phoneNumberType: PhoneNumberType;
searchExpiresBy: Date;
searchExpiresBy?: Date;
searchId: string;
}

// @public
export type PhoneNumberType = "tollFree" | "geographic";

// @public (undocumented)
export type UpdatePhoneNumberOptions = OperationOptions;

// @public (undocumented)
export type UpdatePhoneNumberResponse = WithResponse<AcquiredPhoneNumber>;
export type PhoneNumberType = string;

// @public
export type VoidResponse = WithResponse<{}>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/

/// <reference lib="esnext.asynciterable" />
export * from "./models";
export { PhoneNumbersClient } from "./phoneNumbersClient";
export { PhoneNumbersClientContext } from "./phoneNumbersClientContext";
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {
BaseResult,
LROOperationStep,
LROResponseInfo,
FinalStateVia
FinalStateVia,
LROSYM
} from "./models";
import { OperationSpec, OperationArguments } from "@azure/core-http";
import { OperationSpec, OperationArguments, OperationResponse } from "@azure/core-http";
import { terminalStates } from "./constants";
import { SendOperationFn } from ".";

Expand All @@ -22,7 +23,7 @@ export function createAzureAsyncOperationStrategy<TResult extends BaseResult>(
sendOperationFn: SendOperationFn<TResult>,
finalStateVia?: FinalStateVia
): LROStrategy<TResult> {
const lroData = initialOperation.result._lroData;
const lroData = initialOperation.result._response[LROSYM];
if (!lroData) {
throw new Error("Expected lroData to be defined for Azure-AsyncOperation strategy");
}
Expand All @@ -32,7 +33,7 @@ export function createAzureAsyncOperationStrategy<TResult extends BaseResult>(

return {
isTerminal: () => {
const currentResult = currentOperation.result._lroData;
const currentResult = currentOperation.result._response[LROSYM];

if (!currentResult) {
throw new Error("Expected lroData to determine terminal status");
Expand All @@ -48,28 +49,28 @@ export function createAzureAsyncOperationStrategy<TResult extends BaseResult>(
return terminalStates.includes(status.toLowerCase());
},
sendFinalRequest: async () => {
if (!initialOperation.result._lroData) {
if (!initialOperation.result._response[LROSYM]) {
throw new Error("Expected lroData to determine terminal status");
}

if (!currentOperation.result._lroData) {
if (!currentOperation.result._response[LROSYM]) {
throw new Error("Expected lroData to determine terminal status");
}

const initialOperationResult = initialOperation.result._lroData;
const currentOperationResult = currentOperation.result._lroData;
const initialOperationResult = initialOperation.result._response[LROSYM];
const currentOperationResult = currentOperation.result._response[LROSYM];

if (!shouldPerformFinalGet(initialOperationResult, currentOperationResult)) {
return currentOperation;
}

if (initialOperationResult.requestMethod === "PUT") {
if (initialOperationResult?.requestMethod === "PUT") {
currentOperation = await sendFinalGet(initialOperation, sendOperationFn);

return currentOperation;
}

if (initialOperationResult.location) {
if (initialOperationResult?.location) {
switch (finalStateVia) {
case "original-uri":
currentOperation = await sendFinalGet(initialOperation, sendOperationFn);
Expand All @@ -79,7 +80,7 @@ export function createAzureAsyncOperationStrategy<TResult extends BaseResult>(
return currentOperation;
case "location":
default:
const location = initialOperationResult.location || currentOperationResult.location;
const location = initialOperationResult.location || currentOperationResult?.location;

if (!location) {
throw new Error("Couldn't determine final GET URL from location");
Expand All @@ -99,9 +100,11 @@ export function createAzureAsyncOperationStrategy<TResult extends BaseResult>(

const pollingArgs = currentOperation.args;
// Make sure we don't send any body to the get request
const { requestBody, ...restSpec } = currentOperation.spec;
const { requestBody, responses, ...restSpec } = currentOperation.spec;

const pollingSpec: OperationSpec = {
...restSpec,
responses: getCompositeMappers(responses),
httpMethod: "GET",
path: lastKnownPollingUrl
};
Expand All @@ -110,8 +113,8 @@ export function createAzureAsyncOperationStrategy<TResult extends BaseResult>(

// Update latest polling url
lastKnownPollingUrl =
result._lroData?.azureAsyncOperation ||
result._lroData?.operationLocation ||
result._response[LROSYM]?.azureAsyncOperation ||
result._response[LROSYM]?.operationLocation ||
lastKnownPollingUrl;

// Update lastOperation result
Expand All @@ -126,9 +129,44 @@ export function createAzureAsyncOperationStrategy<TResult extends BaseResult>(
};
}

function shouldPerformFinalGet(initialResult: LROResponseInfo, currentResult: LROResponseInfo) {
const { status } = currentResult;
const { requestMethod: initialRequestMethod, location } = initialResult;
/**
* Polling calls will always return a status object i.e. {"status": "success"}
* these intermediate responses are not described in the swagger so we need to
* pass custom mappers at runtime.
* This function replaces all the existing mappers to be able to deserialize a status object
* @param responses Original set of responses defined in the operation
*/
function getCompositeMappers(responses: {
[responseCode: string]: OperationResponse;
}): {
[responseCode: string]: OperationResponse;
} {
return Object.keys(responses).reduce((acc, statusCode) => {
return {
...acc,
[statusCode]: {
...responses[statusCode],
bodyMapper: {
type: {
name: "Composite",
modelProperties: {
status: {
serializedName: "status",
type: {
name: "String"
}
}
}
}
}
}
};
}, {} as { [responseCode: string]: OperationResponse });
}

function shouldPerformFinalGet(initialResult?: LROResponseInfo, currentResult?: LROResponseInfo) {
const { status } = currentResult || {};
const { requestMethod: initialRequestMethod, location } = initialResult || {};
if (status && status.toLowerCase() !== "succeeded") {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/

import { LROStrategy, BaseResult, LROOperationStep } from "./models";
import { LROStrategy, BaseResult, LROOperationStep, LROSYM } from "./models";
import { OperationSpec } from "@azure/core-http";
import { terminalStates } from "./constants";
import { SendOperationFn } from "./lroPoller";
Expand All @@ -19,15 +19,15 @@ export function createBodyPollingStrategy<TResult extends BaseResult>(
initialOperation: LROOperationStep<TResult>,
sendOperation: SendOperationFn<TResult>
): LROStrategy<TResult> {
if (!initialOperation.result._lroData) {
if (!initialOperation.result._response[LROSYM]) {
throw new Error("Expected lroData to be defined for BodyPolling strategy");
}

let currentOperation = initialOperation;

return {
isTerminal: () => {
const currentResult = currentOperation.result._lroData;
const currentResult = currentOperation.result._response[LROSYM];
if (!currentResult) {
throw new Error("Expected lroData to determine terminal status");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/

import { BaseResult, LROOperationStep, LROStrategy } from "./models";
import { BaseResult, LROOperationStep, LROStrategy, LROSYM } from "./models";
import { SendOperationFn } from "./lroPoller";
import { OperationSpec } from "@azure/core-http";

export function createLocationStrategy<TResult extends BaseResult>(
initialOperation: LROOperationStep<TResult>,
sendOperationFn: SendOperationFn<TResult>
): LROStrategy<TResult> {
const lroData = initialOperation.result._lroData;
const lroData = initialOperation.result._response[LROSYM];
if (!lroData) {
throw new Error("Expected lroData to be defined for Azure-AsyncOperation strategy");
}
Expand All @@ -24,7 +24,7 @@ export function createLocationStrategy<TResult extends BaseResult>(

return {
isTerminal: () => {
const currentResult = currentOperation.result._lroData;
const currentResult = currentOperation.result._response[LROSYM];
if (!currentResult) {
throw new Error("Expected lroData to determine terminal status");
}
Expand Down Expand Up @@ -57,7 +57,7 @@ export function createLocationStrategy<TResult extends BaseResult>(
const result = await sendOperationFn(pollingArgs, pollingSpec);

// Update latest polling url
lastKnownPollingUrl = result._lroData?.location || lastKnownPollingUrl;
lastKnownPollingUrl = result._response[LROSYM]?.location || lastKnownPollingUrl;

// Update lastOperation result
currentOperation = {
Expand Down
Loading