diff --git a/.vscode/cspell.json b/.vscode/cspell.json index bd72f2c8985e..dee9ee873d86 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -74,6 +74,7 @@ "Eugps", "EUGPS", "Fhir", + "Fnhr", "Guids", "Hana", "Idrg", @@ -107,6 +108,8 @@ "prettierrc", "pwsh", "Rasterize", + "reoffer", + "Resourceid", "Rollup", "rrggbb", "Rtsp", diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index c74e20adb815..31149596298b 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -236,6 +236,7 @@ specifiers: '@rush-temp/communication-rooms': file:./projects/communication-rooms.tgz '@rush-temp/communication-short-codes': file:./projects/communication-short-codes.tgz '@rush-temp/communication-sms': file:./projects/communication-sms.tgz + '@rush-temp/communication-tiering': file:./projects/communication-tiering.tgz '@rush-temp/communication-toll-free-verification': file:./projects/communication-toll-free-verification.tgz '@rush-temp/confidential-ledger': file:./projects/confidential-ledger.tgz '@rush-temp/container-registry': file:./projects/container-registry.tgz @@ -581,6 +582,7 @@ dependencies: '@rush-temp/communication-rooms': file:projects/communication-rooms.tgz '@rush-temp/communication-short-codes': file:projects/communication-short-codes.tgz '@rush-temp/communication-sms': file:projects/communication-sms.tgz + '@rush-temp/communication-tiering': file:projects/communication-tiering.tgz '@rush-temp/communication-toll-free-verification': file:projects/communication-toll-free-verification.tgz '@rush-temp/confidential-ledger': file:projects/confidential-ledger.tgz '@rush-temp/container-registry': file:projects/container-registry.tgz @@ -15981,6 +15983,50 @@ packages: - utf-8-validate dev: false + file:projects/communication-tiering.tgz: + resolution: {integrity: sha512-zym5Gh8ntlYl6yvsJHNwMGkrr/JVyK155DZjK/JEurf7RHz8MBzHEP4dVzUeqgruDhZy5+1uhwpedlNbZnNtwg==, tarball: file:projects/communication-tiering.tgz} + name: '@rush-temp/communication-tiering' + version: 0.0.0 + dependencies: + '@azure/communication-common': 2.2.0 + '@azure/identity': 2.1.0 + '@microsoft/api-extractor': 7.35.1_@types+node@14.18.48 + '@types/chai': 4.3.5 + '@types/mocha': 7.0.2 + '@types/node': 14.18.48 + '@types/sinon': 9.0.11 + '@types/uuid': 8.3.4 + chai: 4.3.7 + cross-env: 7.0.3 + dotenv: 16.1.4 + eslint: 8.42.0 + events: 3.3.0 + inherits: 2.0.4 + karma: 6.4.2 + karma-chrome-launcher: 3.2.0 + karma-coverage: 2.2.0 + karma-env-preprocessor: 0.1.1 + karma-firefox-launcher: 1.3.0 + karma-junit-reporter: 2.0.1_karma@6.4.2 + karma-mocha: 2.0.1 + karma-mocha-reporter: 2.2.5_karma@6.4.2 + karma-sourcemap-loader: 0.3.8 + mocha: 7.2.0 + mocha-junit-reporter: 2.2.0_mocha@7.2.0 + nyc: 15.1.0 + prettier: 2.8.8 + rimraf: 3.0.2 + sinon: 9.2.4 + tslib: 2.5.3 + typescript: 5.0.4 + uuid: 8.3.2 + transitivePeerDependencies: + - bufferutil + - debug + - supports-color + - utf-8-validate + dev: false + file:projects/communication-toll-free-verification.tgz: resolution: {integrity: sha512-tEbb2X57aezkEjuGn0Sfggw8Jv9ln+5DvZPp307DJuYODDtUqm6gjkBDdPqJgKMrOTsIsERq+DG5ndKlWok6QQ==, tarball: file:projects/communication-toll-free-verification.tgz} name: '@rush-temp/communication-toll-free-verification' diff --git a/rush.json b/rush.json index edeb46475e2c..98055c2c669a 100644 --- a/rush.json +++ b/rush.json @@ -455,6 +455,11 @@ "projectFolder": "sdk/communication/communication-recipient-verification", "versionPolicyName": "client" }, + { + "packageName": "@azure-tools/communication-tiering", + "projectFolder": "sdk/communication/communication-tiering", + "versionPolicyName": "client" + }, { "packageName": "@azure-tools/communication-alpha-ids", "projectFolder": "sdk/communication/communication-alpha-ids", diff --git a/sdk/communication/communication-tiering/.nycrc b/sdk/communication/communication-tiering/.nycrc new file mode 100644 index 000000000000..29174b423579 --- /dev/null +++ b/sdk/communication/communication-tiering/.nycrc @@ -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 +} diff --git a/sdk/communication/communication-tiering/CHANGELOG.md b/sdk/communication/communication-tiering/CHANGELOG.md new file mode 100644 index 000000000000..11d85a6e2857 --- /dev/null +++ b/sdk/communication/communication-tiering/CHANGELOG.md @@ -0,0 +1,8 @@ +# Release History + +## 1.0.0-beta.1 (2023-06-05) + +The first preview of the Azure Communication Tiering client library has the following features: + +- Retrieving tiering info +- Retrieving telephone number summary diff --git a/sdk/communication/communication-tiering/README.md b/sdk/communication/communication-tiering/README.md new file mode 100644 index 000000000000..74abcc7fac75 --- /dev/null +++ b/sdk/communication/communication-tiering/README.md @@ -0,0 +1,142 @@ +# Azure Communication Tiering client library for JavaScript + +The Tiering client library allows developers to retrieve limits for each capability (SMS/PSTN Calling/Phone Number purchasing) for a specific resource/tier. + +## 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-tools/communication-tiering +``` + +### Browser support + +#### JavaScript Bundle + +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). + +## Key concepts + +## 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 Tiering 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 `TieringClient` with any of the following methods: + +### Using a connection string + +```javascript +const { TieringClient } = require("@azure-tools/communication-tiering"); +const connectionString = "endpoint=;accessKey="; +const client = new TieringClient(connectionString); +``` + +### Using an access key with `AzureKeyCredential` + +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: + +```javascript +const { AzureKeyCredential } = require("@azure/core-auth"); +const { TieringClient } = require("@azure-tools/communication-tiering"); +const credential = new AzureKeyCredential(""); +const client = new TieringClient("", credential); +``` + +### Using an Azure Active Directory Credential + +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: + +```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`][azure_identity_readme] provides more details and samples to get you started. + +```javascript +const { DefaultAzureCredential } = require("@azure/identity"); +const { TieringClient } = require("@azure-tools/communication-tiering"); + +let credential = new DefaultAzureCredential(); +const client = new TieringClient("", credential); +``` + +## Usage + +The following sections provide code snippets that cover some of the common tasks using the Azure Communication Services Tiering Client. The scenarios that are covered here consist of: + +- [Get acquired number limits](#get-acquired-number-limits) +- [Get Tier Info](#get-tier-info) + +### Get acquired number limits + +```typescript +import { Tiering } from "@azure-tools/communication-tiering"; +const connectionString = "endpoint=;accessKey="; +const client = new Tiering(connectionString); + +async main function() { + const resourceId = "5d41e908-de88-4bbf-94dc-fe9a1b51029b"; + + // Get acquired numbers and limits for a resource + var acquiredNumberLimits = await client.getAcquiredNumberLimits(resourceId); + + // print all number limits + console.log(acquiredNumberLimits); +} + +main(); +``` + +### Get tier info + +```typescript +import { Tiering } from "@azure-tools/communication-tiering"; +const connectionString = "endpoint=;accessKey="; +const client = new Tiering(connectionString); + +async main function() { + const resourceId = "5d41e908-de88-4bbf-94dc-fe9a1b51029b"; + + // Get tier info for a resource + var tierInfo = await client.getTierByResourceId(resourceId); + + // print all tier info + console.log(tierInfo); +} + +main(); +``` + +## Troubleshooting + +## Next steps + +Please take a look at the 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/main/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/main/sdk/identity/identity#defaultazurecredential +[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity +[azure_identity_readme]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/README.md + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcommunication%2Fcommunication-toll-free-verification%2FREADME.png) diff --git a/sdk/communication/communication-tiering/api-extractor.json b/sdk/communication/communication-tiering/api-extractor.json new file mode 100644 index 000000000000..f326ea93930c --- /dev/null +++ b/sdk/communication/communication-tiering/api-extractor.json @@ -0,0 +1,35 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + "mainEntryPointFilePath": "types/src/index.d.ts", + "docModel": { + "enabled": true + }, + "apiReport": { + "enabled": true, + "reportFolder": "./review" + }, + "dtsRollup": { + "enabled": true, + "untrimmedFilePath": "", + "publicTrimmedFilePath": "./types/communication-tiering.d.ts" + }, + "messages": { + "tsdocMessageReporting": { + "default": { + "logLevel": "none" + } + }, + "extractorMessageReporting": { + "ae-forgotten-export": { + "logLevel": "error", + "addToApiReportFile": false + }, + "ae-missing-release-tag": { + "logLevel": "none" + }, + "ae-unresolved-link": { + "logLevel": "error" + } + } + } +} diff --git a/sdk/communication/communication-tiering/karma.conf.js b/sdk/communication/communication-tiering/karma.conf.js new file mode 100644 index 000000000000..b7223a7f2b76 --- /dev/null +++ b/sdk/communication/communication-tiering/karma.conf.js @@ -0,0 +1,129 @@ +// https://github.com/karma-runner/karma-chrome-launcher +process.env.CHROME_BIN = require("puppeteer").executablePath(); +require("dotenv").config(); +const { relativeRecordingsPath } = require("@azure-tools/test-recorder"); + +process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath(); +module.exports = function (config) { + config.set({ + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: "./", + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ["mocha"], + + plugins: [ + "karma-mocha", + "karma-mocha-reporter", + "karma-chrome-launcher", + "karma-firefox-launcher", + "karma-env-preprocessor", + "karma-coverage", + "karma-sourcemap-loader", + "karma-junit-reporter", + ], + + // list of files / patterns to load in the browser + files: ["dist-test/index.browser.js"], + + // list of files / patterns to exclude + exclude: [], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + "**/*.js": ["sourcemap", "env"], + // IMPORTANT: COMMENT following line if you want to debug in your browsers!! + // Preprocess source file to calculate code coverage, however this will make source file unreadable + //"dist-test/index.browser.js": ["coverage"] + }, + + // inject following environment values into browser testing with window.__env__ + // environment values MUST be exported or set with same console running "karma start" + // https://www.npmjs.com/package/karma-env-preprocessor + envPreprocessor: [ + "TEST_MODE", + "COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING", + "INCLUDE_PHONENUMBER_LIVE_TESTS", + "AZURE_PHONE_NUMBER", + "COMMUNICATION_ENDPOINT", + "AZURE_CLIENT_ID", + "AZURE_CLIENT_SECRET", + "AZURE_TENANT_ID", + "COMMUNICATION_SKIP_INT_PHONENUMBERS_TESTS", + "RECORDINGS_RELATIVE_PATH", + ], + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ["mocha", "coverage", "junit"], + + coverageReporter: { + // specify a common output directory + dir: "coverage-browser/", + reporters: [ + { type: "json", subdir: ".", file: "coverage.json" }, + { type: "lcovonly", subdir: ".", file: "lcov.info" }, + { type: "html", subdir: "html" }, + { type: "cobertura", subdir: ".", file: "cobertura-coverage.xml" }, + ], + }, + + junitReporter: { + outputDir: "", // results will be saved as $outputDir/$browserName.xml + outputFile: "test-results.browser.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile + suite: "", // suite will become the package name attribute in xml testsuite element + useBrowserName: false, // add browser name to report and classes names + nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element + classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element + properties: {}, // key value pair of properties to add to the section of the report + }, + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: false, + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + // 'ChromeHeadless', 'Chrome', 'Firefox', 'Edge', 'IE' + browsers: ["HeadlessChrome"], + + customLaunchers: { + HeadlessChrome: { + base: "ChromeHeadless", + flags: ["--no-sandbox", "--disable-web-security"], + }, + }, + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: true, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: 1, + + browserNoActivityTimeout: 600000, + browserDisconnectTimeout: 10000, + browserDisconnectTolerance: 3, + + client: { + mocha: { + // change Karma's debug.html to the mocha web reporter + reporter: "html", + timeout: "600000", + }, + }, + }); +}; diff --git a/sdk/communication/communication-tiering/package.json b/sdk/communication/communication-tiering/package.json new file mode 100644 index 000000000000..ea4271a25ccc --- /dev/null +++ b/sdk/communication/communication-tiering/package.json @@ -0,0 +1,139 @@ +{ + "name": "@azure-tools/communication-tiering", + "version": "1.0.0-beta.0", + "description": "Test", + "sdk-type": "client", + "main": "dist/index.js", + "module": "dist-esm/src/index.js", + "types": "types/communication-tiering.d.ts", + "scripts": { + "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", + "build": "npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local", + "build:autorest": "autorest --typescript ./swagger/README.md && rushx format", + "build:clean": "rush update --recheck && rush rebuild && npm run build", + "build:browser": "tsc -p . && dev-tool run bundle", + "build:node": "tsc -p . && dev-tool run bundle", + "build:samples": "dev-tool samples publish --force", + "build:test": "tsc -p . && dev-tool run bundle", + "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", + "clean": "rimraf dist dist-* types *.tgz *.log", + "execute:samples": "dev-tool samples run samples-dev", + "extract-api": "tsc -p . && api-extractor run --local", + "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", + "integration-test:browser": "dev-tool run test:browser", + "integration-test:node": "dev-tool run test:node-js-input -- --timeout 300000 'dist-esm/test/public/*.spec.js'", + "integration-test": "npm run integration-test:node && npm run integration-test:browser", + "lint:fix": "eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js --fix --fix-type [problem,suggestion]", + "lint": "eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js", + "pack": "npm pack 2>&1", + "test": "rimraf dist-test && npm run build:test && npm run unit-test && npm run integration-test", + "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", + "unit-test:browser": "dev-tool run test:browser", + "unit-test:node": "dev-tool run test:node-ts-input -- --exclude 'test/**/browser/*.spec.ts' 'test/**/*.spec.ts'", + "unit-test": "npm run unit-test:node && npm run unit-test:browser" + }, + "files": [ + "dist/", + "dist-esm/src/", + "types/communication-tiering.d.ts", + "README.md", + "LICENSE" + ], + "keywords": [ + "azure", + "cloud", + "communication" + ], + "author": "Microsoft Corporation", + "license": "MIT", + "engines": { + "node": ">=14.0.0" + }, + "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-tiering/", + "repository": "github:Azure/azure-sdk-for-js", + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "sideEffects": false, + "prettier": "@azure/eslint-plugin-azure-sdk/prettier.json", + "dependencies": { + "@azure/abort-controller": "^1.0.0", + "@azure/communication-common": "^2.2.0", + "@azure/core-auth": "^1.3.0", + "@azure/core-client": "^1.3.2", + "@azure/core-lro": "^2.2.0", + "@azure/core-paging": "^1.1.1", + "@azure/core-rest-pipeline": "^1.3.2", + "@azure/core-tracing": "^1.0.0", + "@azure/logger": "^1.0.0", + "events": "^3.0.0", + "tslib": "^2.2.0", + "uuid": "^8.3.2" + }, + "devDependencies": { + "@azure-tools/test-recorder": "^3.0.0", + "@azure/dev-tool": "^1.0.0", + "@azure/eslint-plugin-azure-sdk": "^3.0.0", + "@azure/identity": "^2.0.1", + "@azure/test-utils": "^1.0.0", + "@microsoft/api-extractor": "^7.31.1", + "@types/chai": "^4.1.6", + "@types/mocha": "^7.0.2", + "@types/node": "^14.0.0", + "@types/sinon": "^9.0.4", + "@types/uuid": "^8.3.2", + "chai": "^4.2.0", + "cross-env": "^7.0.2", + "dotenv": "^16.0.0", + "eslint": "^8.0.0", + "inherits": "^2.0.3", + "karma": "^6.2.0", + "karma-chrome-launcher": "^3.0.0", + "karma-coverage": "^2.0.0", + "karma-env-preprocessor": "^0.1.1", + "karma-firefox-launcher": "^1.1.0", + "karma-junit-reporter": "^2.0.1", + "karma-mocha": "^2.0.1", + "karma-mocha-reporter": "^2.2.5", + "karma-sourcemap-loader": "^0.3.8", + "mocha": "^7.1.1", + "mocha-junit-reporter": "^2.0.0", + "nyc": "^15.0.0", + "prettier": "^2.5.1", + "rimraf": "^3.0.0", + "sinon": "^9.0.2", + "typescript": "~5.0.0" + }, + "//metadata": { + "constantPaths": [ + { + "path": "src/generated/src/tieringClient.ts", + "prefix": "packageDetails" + }, + { + "path": "src/generated/src/tracing.ts", + "prefix": "packageVersion" + }, + { + "path": "src/utils/constants.ts", + "prefix": "SDK_VERSION" + }, + { + "path": "swagger/README.md", + "prefix": "package-version" + } + ] + }, + "//sampleConfiguration": { + "productName": "Azure Communication Services - Tiering", + "productSlugs": [ + "azure", + "azure-communication-services" + ], + "requiredResources": { + "Azure Communication Services account": "https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource" + } + } +} diff --git a/sdk/communication/communication-tiering/recordings/browsers/tieringclient__get_acquired_number_limits/recording_get_acquired_number_limits.json b/sdk/communication/communication-tiering/recordings/browsers/tieringclient__get_acquired_number_limits/recording_get_acquired_number_limits.json new file mode 100644 index 000000000000..df6bc2f36616 --- /dev/null +++ b/sdk/communication/communication-tiering/recordings/browsers/tieringclient__get_acquired_number_limits/recording_get_acquired_number_limits.json @@ -0,0 +1,78 @@ +{ + "Entries": [ + { + "RequestUri": "https://endpoint/administration/resources/9d787bd6-07fc-4c7b-8e57-17f1fee41298/telephone-number-summary?api-version=2023-06-15", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "en-US", + "Authorization": "Sanitized", + "Connection": "keep-alive", + "Referer": "http://localhost:9876/", + "sec-ch-ua": "", + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": "\u0022\u0022", + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-site", + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/112.0.5614.0 Safari/537.36", + "x-ms-client-request-id": "9d787bd6-07fc-4c7b-8e57-17f1fee41298", + "x-ms-content-sha256": "47DEQpj8HBSa\u002B/TImW\u002B5JCeuQeRkm5NMpJWZG3hSuFU=", + "x-ms-date": "Mon, 05 Jun 2023 17:37:52 GMT", + "x-ms-useragent": "azsdk-js-communication-tiering/1.0.0-beta.0 core-rest-pipeline/1.10.4 OS" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Accept-Ranges": "bytes", + "Connection": "keep-alive", + "Content-Length": "464", + "Content-Type": "application/json; charset=utf-8", + "Date": "Mon, 05 Jun 2023 17:37:51 GMT", + "MS-CV": "cwBI4BflqkSis2czSHDs6w.0", + "Strict-Transport-Security": "max-age=2592000", + "x-azure-ref": "20230605T173749Z-knytndh8m91dh5apppub1spe1g00000007b000000000ff86", + "X-Cache": "CONFIG_NOCACHE", + "X-Processing-Time": "1679ms" + }, + "ResponseBody": { + "AssetDetails": [ + { + "NumberType": [ + "Geographic", + "TollFree", + "Mobile" + ], + "ResourceAcquiredCount": 0, + "SubscriptionAcquiredCount": 43, + "AadTenantAcquiredCount": 65, + "TierInfo": { + "Scope": "Tenant", + "Allowed": 1, + "Acquired": 65, + "Balance": 0, + "Limit": "AcquisitionAboveLimit" + } + }, + { + "NumberType": [ + "ShortCode" + ], + "ResourceAcquiredCount": 0, + "SubscriptionAcquiredCount": 2, + "AadTenantAcquiredCount": 2, + "TierInfo": { + "Scope": "Tenant", + "Allowed": 0, + "Acquired": 2, + "Balance": 0, + "Limit": "AcquisitionAboveLimit" + } + } + ] + } + } + ], + "Variables": {} +} diff --git a/sdk/communication/communication-tiering/recordings/browsers/tieringclient__get_tier_info/recording_get_tier_info.json b/sdk/communication/communication-tiering/recordings/browsers/tieringclient__get_tier_info/recording_get_tier_info.json new file mode 100644 index 000000000000..034e12c6ae9b --- /dev/null +++ b/sdk/communication/communication-tiering/recordings/browsers/tieringclient__get_tier_info/recording_get_tier_info.json @@ -0,0 +1,176 @@ +{ + "Entries": [ + { + "RequestUri": "https://endpoint/administration/tiers/resources/9d787bd6-07fc-4c7b-8e57-17f1fee41298?api-version=2023-06-15", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "en-US", + "Authorization": "Sanitized", + "Connection": "keep-alive", + "Referer": "http://localhost:9876/", + "sec-ch-ua": "", + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": "\u0022\u0022", + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-site", + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/112.0.5614.0 Safari/537.36", + "x-ms-client-request-id": "9d787bd6-07fc-4c7b-8e57-17f1fee41298", + "x-ms-content-sha256": "47DEQpj8HBSa\u002B/TImW\u002B5JCeuQeRkm5NMpJWZG3hSuFU=", + "x-ms-date": "Mon, 05 Jun 2023 17:37:55 GMT", + "x-ms-useragent": "azsdk-js-communication-tiering/1.0.0-beta.0 core-rest-pipeline/1.10.4 OS" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Accept-Ranges": "bytes", + "api-supported-versions": "2023-06-15", + "Connection": "keep-alive", + "Content-Length": "1516", + "Content-Type": "application/json; charset=utf-8", + "Date": "Mon, 05 Jun 2023 17:37:52 GMT", + "MS-CV": "Bj7tREFaCEmI9GYy/x9K7Q.0", + "Strict-Transport-Security": "max-age=2592000", + "x-azure-ref": "20230605T173752Z-knytndh8m91dh5apppub1spe1g00000007b000000000ffpd", + "X-Cache": "CONFIG_NOCACHE", + "X-Processing-Time": "225ms" + }, + "ResponseBody": { + "tierId": "9d787bd6-07fc-4c7b-8e57-17f1fee41298", + "tierType": "Basic", + "capabilities": { + "sms": { + "outbound": [ + { + "type": "SMS", + "scope": "PhoneNumber", + "smsPerMin": 200, + "geographicLimitations": "Domestic" + }, + { + "type": "ShortCode", + "scope": "PhoneNumber", + "smsPerMin": 0, + "geographicLimitations": "Domestic" + }, + { + "type": "AlphaDynamic", + "scope": "Resource", + "smsPerMin": 0, + "geographicLimitations": "Domestic" + } + ], + "inbound": [] + }, + "calling": { + "outbound": [ + { + "type": "Call", + "scope": "PhoneNumber", + "concurrentCalls": 2, + "geographicLimitations": "Domestic" + } + ], + "inbound": [ + { + "type": "Call", + "scope": "PhoneNumber", + "concurrentCalls": 2, + "geographicLimitations": "Domestic" + } + ] + }, + "phoneNumberPurchase": [ + { + "numberType": [ + "TollFree", + "Geographic", + "Mobile" + ], + "scope": "Tenant", + "totalNumbers": 1 + }, + { + "numberType": [ + "ShortCode" + ], + "scope": "Tenant", + "totalNumbers": 0 + }, + { + "numberType": [ + "AlphaDynamic" + ], + "scope": "Tenant", + "totalNumbers": 0 + } + ], + "trialPhoneNumberPurchase": [ + { + "numberType": [ + "TollFree" + ], + "scope": "Subscription", + "totalNumbers": 3, + "trialPeriodDays": 30 + }, + { + "numberType": [ + "TollFree" + ], + "scope": "Resource", + "totalNumbers": 1, + "trialPeriodDays": 30 + } + ], + "trialPhoneNumberUsage": [ + { + "numberType": "TollFree", + "calling": { + "outbound": [ + { + "type": "Call", + "scope": "PhoneNumber", + "totalMinutes": 60, + "maximumCallDurationMinutes": 5, + "concurrentCalls": 0 + } + ], + "inbound": [ + { + "type": "Call", + "scope": "PhoneNumber", + "totalMinutes": 60, + "maximumCallDurationMinutes": 5, + "concurrentCalls": 0 + } + ] + }, + "sms": { + "outbound": [ + { + "type": "SMS", + "scope": "PhoneNumber", + "total": 100, + "smsPerMin": 5 + } + ], + "inbound": [ + { + "type": "SMS", + "scope": "PhoneNumber", + "total": 100, + "smsPerMin": 5 + } + ] + } + } + ] + } + } + } + ], + "Variables": {} +} diff --git a/sdk/communication/communication-tiering/recordings/node/tieringclient__get_acquired_number_limits/recording_get_acquired_number_limits.json b/sdk/communication/communication-tiering/recordings/node/tieringclient__get_acquired_number_limits/recording_get_acquired_number_limits.json new file mode 100644 index 000000000000..7cfe78c14c23 --- /dev/null +++ b/sdk/communication/communication-tiering/recordings/node/tieringclient__get_acquired_number_limits/recording_get_acquired_number_limits.json @@ -0,0 +1,69 @@ +{ + "Entries": [ + { + "RequestUri": "https://endpoint/administration/resources/9d787bd6-07fc-4c7b-8e57-17f1fee41298/telephone-number-summary?api-version=2023-06-15", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json", + "Accept-Encoding": "gzip,deflate", + "Authorization": "Sanitized", + "Connection": "keep-alive", + "User-Agent": "azsdk-js-communication-tiering/1.0.0-beta.0 core-rest-pipeline/1.10.4 Node/v18.12.1 OS/(x64-Linux-5.15.90.1-microsoft-standard-WSL2)", + "x-ms-client-request-id": "9d787bd6-07fc-4c7b-8e57-17f1fee41298", + "x-ms-content-sha256": "47DEQpj8HBSa\u002B/TImW\u002B5JCeuQeRkm5NMpJWZG3hSuFU=", + "x-ms-date": "Mon, 05 Jun 2023 17:37:38 GMT" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Accept-Ranges": "bytes", + "Connection": "keep-alive", + "Content-Length": "464", + "Content-Type": "application/json; charset=utf-8", + "Date": "Mon, 05 Jun 2023 17:37:37 GMT", + "MS-CV": "F/MpbJ2zlkOlFy16J/H14g.0", + "Strict-Transport-Security": "max-age=2592000", + "x-azure-ref": "20230605T173735Z-pbnsyacqb97s5787bax4emxtw800000001g0000000011vb8", + "X-Cache": "CONFIG_NOCACHE", + "X-Processing-Time": "1679ms" + }, + "ResponseBody": { + "AssetDetails": [ + { + "NumberType": [ + "Geographic", + "TollFree", + "Mobile" + ], + "ResourceAcquiredCount": 0, + "SubscriptionAcquiredCount": 43, + "AadTenantAcquiredCount": 65, + "TierInfo": { + "Scope": "Tenant", + "Allowed": 1, + "Acquired": 65, + "Balance": 0, + "Limit": "AcquisitionAboveLimit" + } + }, + { + "NumberType": [ + "ShortCode" + ], + "ResourceAcquiredCount": 0, + "SubscriptionAcquiredCount": 2, + "AadTenantAcquiredCount": 2, + "TierInfo": { + "Scope": "Tenant", + "Allowed": 0, + "Acquired": 2, + "Balance": 0, + "Limit": "AcquisitionAboveLimit" + } + } + ] + } + } + ], + "Variables": {} +} diff --git a/sdk/communication/communication-tiering/recordings/node/tieringclient__get_tier_info/recording_get_tier_info.json b/sdk/communication/communication-tiering/recordings/node/tieringclient__get_tier_info/recording_get_tier_info.json new file mode 100644 index 000000000000..5291dda86c1b --- /dev/null +++ b/sdk/communication/communication-tiering/recordings/node/tieringclient__get_tier_info/recording_get_tier_info.json @@ -0,0 +1,167 @@ +{ + "Entries": [ + { + "RequestUri": "https://endpoint/administration/tiers/resources/9d787bd6-07fc-4c7b-8e57-17f1fee41298?api-version=2023-06-15", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json", + "Accept-Encoding": "gzip,deflate", + "Authorization": "Sanitized", + "Connection": "keep-alive", + "User-Agent": "azsdk-js-communication-tiering/1.0.0-beta.0 core-rest-pipeline/1.10.4 Node/v18.12.1 OS/(x64-Linux-5.15.90.1-microsoft-standard-WSL2)", + "x-ms-client-request-id": "9d787bd6-07fc-4c7b-8e57-17f1fee41298", + "x-ms-content-sha256": "47DEQpj8HBSa\u002B/TImW\u002B5JCeuQeRkm5NMpJWZG3hSuFU=", + "x-ms-date": "Mon, 05 Jun 2023 17:37:40 GMT" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Accept-Ranges": "bytes", + "api-supported-versions": "2023-06-15", + "Connection": "keep-alive", + "Content-Length": "1516", + "Content-Type": "application/json; charset=utf-8", + "Date": "Mon, 05 Jun 2023 17:37:38 GMT", + "MS-CV": "oATvkZ58LUySDvjom6xQUQ.0", + "Strict-Transport-Security": "max-age=2592000", + "x-azure-ref": "20230605T173737Z-pbnsyacqb97s5787bax4emxtw800000001g0000000011vp1", + "X-Cache": "CONFIG_NOCACHE", + "X-Processing-Time": "544ms" + }, + "ResponseBody": { + "tierId": "9d787bd6-07fc-4c7b-8e57-17f1fee41298", + "tierType": "Basic", + "capabilities": { + "sms": { + "outbound": [ + { + "type": "SMS", + "scope": "PhoneNumber", + "smsPerMin": 200, + "geographicLimitations": "Domestic" + }, + { + "type": "ShortCode", + "scope": "PhoneNumber", + "smsPerMin": 0, + "geographicLimitations": "Domestic" + }, + { + "type": "AlphaDynamic", + "scope": "Resource", + "smsPerMin": 0, + "geographicLimitations": "Domestic" + } + ], + "inbound": [] + }, + "calling": { + "outbound": [ + { + "type": "Call", + "scope": "PhoneNumber", + "concurrentCalls": 2, + "geographicLimitations": "Domestic" + } + ], + "inbound": [ + { + "type": "Call", + "scope": "PhoneNumber", + "concurrentCalls": 2, + "geographicLimitations": "Domestic" + } + ] + }, + "phoneNumberPurchase": [ + { + "numberType": [ + "TollFree", + "Geographic", + "Mobile" + ], + "scope": "Tenant", + "totalNumbers": 1 + }, + { + "numberType": [ + "ShortCode" + ], + "scope": "Tenant", + "totalNumbers": 0 + }, + { + "numberType": [ + "AlphaDynamic" + ], + "scope": "Tenant", + "totalNumbers": 0 + } + ], + "trialPhoneNumberPurchase": [ + { + "numberType": [ + "TollFree" + ], + "scope": "Subscription", + "totalNumbers": 3, + "trialPeriodDays": 30 + }, + { + "numberType": [ + "TollFree" + ], + "scope": "Resource", + "totalNumbers": 1, + "trialPeriodDays": 30 + } + ], + "trialPhoneNumberUsage": [ + { + "numberType": "TollFree", + "calling": { + "outbound": [ + { + "type": "Call", + "scope": "PhoneNumber", + "totalMinutes": 60, + "maximumCallDurationMinutes": 5, + "concurrentCalls": 0 + } + ], + "inbound": [ + { + "type": "Call", + "scope": "PhoneNumber", + "totalMinutes": 60, + "maximumCallDurationMinutes": 5, + "concurrentCalls": 0 + } + ] + }, + "sms": { + "outbound": [ + { + "type": "SMS", + "scope": "PhoneNumber", + "total": 100, + "smsPerMin": 5 + } + ], + "inbound": [ + { + "type": "SMS", + "scope": "PhoneNumber", + "total": 100, + "smsPerMin": 5 + } + ] + } + } + ] + } + } + } + ], + "Variables": {} +} diff --git a/sdk/communication/communication-tiering/review/communication-tiering.api.md b/sdk/communication/communication-tiering/review/communication-tiering.api.md new file mode 100644 index 000000000000..e87824782856 --- /dev/null +++ b/sdk/communication/communication-tiering/review/communication-tiering.api.md @@ -0,0 +1,183 @@ +## API Report File for "@azure-tools/communication-tiering" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +/// + +import { CommonClientOptions } from '@azure/core-client'; +import * as coreClient from '@azure/core-client'; +import { KeyCredential } from '@azure/core-auth'; +import { TokenCredential } from '@azure/core-auth'; + +// @public +export interface AcsTier { + capabilities?: AcsTierCapabilities; + tierId?: string; + tierType?: string; +} + +// @public +export interface AcsTierCapabilities { + calling?: AcsTierCapabilitiesCalling; + phoneNumberPurchase?: PhoneNumberPurchase[]; + sms?: AcsTierCapabilitiesSms; + trialPhoneNumberPurchase?: TrialPhoneNumberPurchase[]; + trialPhoneNumberUsage?: TrialPhoneNumberUsage[]; +} + +// @public +export interface AcsTierCapabilitiesCalling { + inbound?: CallingInbound[]; + outbound?: CallingOutbound[]; +} + +// @public +export interface AcsTierCapabilitiesSms { + inbound?: SmsInbound[]; + outbound?: SmsOutbound[]; +} + +// @public +export interface AssetDetails { + aadTenantAcquiredCount?: number; + numberType?: string[]; + resourceAcquiredCount?: number; + subscriptionAcquiredCount?: number; + tierInfo?: AssetDetailsTierInfo; +} + +// @public (undocumented) +export interface AssetDetailsModel { + assetDetails: AssetDetails[]; +} + +// @public +export interface AssetDetailsTierInfo { + acquired?: number; + allowed?: number; + balance?: number; + limit?: string; + scope?: string; +} + +// @public +export interface CallingInbound { + concurrentCalls?: number; + geographicLimitations?: string; + scope?: string; + type?: string; +} + +// @public +export interface CallingOutbound { + concurrentCalls?: number; + geographicLimitations?: string; + scope?: string; + type?: string; +} + +// @public +export interface NumberAllotmentGetAcquiredNumberLimitsOptionalParams extends coreClient.OperationOptions { +} + +// @public +export type NumberAllotmentGetAcquiredNumberLimitsResponse = AssetDetailsModel; + +// @public +export interface PhoneNumberPurchase { + numberType?: string[]; + scope?: string; + totalNumbers?: number; +} + +// @public +export interface SmsInbound { + geographicLimitations?: string; + scope?: string; + smsPerMin?: number; + type?: string; +} + +// @public +export interface SmsOutbound { + geographicLimitations?: string; + scope?: string; + smsPerMin?: number; + type?: string; +} + +// @public +export class TieringClient { + constructor(connectionString: string, options?: TieringClientOptions); + constructor(endpoint: string, credential: KeyCredential, options?: TieringClientOptions); + constructor(endpoint: string, credential: TokenCredential, options?: TieringClientOptions); + getAcquiredNumberLimits(resourceId: string, options?: NumberAllotmentGetAcquiredNumberLimitsOptionalParams): Promise; + getTierByResourceId(resourceId: string, options?: TieringGetByResourceIdOptionalParams): Promise; +} + +// @public +export interface TieringClientOptionalParams extends coreClient.ServiceClientOptions { + apiVersion?: string; + endpoint?: string; +} + +// @public +export interface TieringClientOptions extends CommonClientOptions { +} + +// @public +export interface TieringGetByResourceIdOptionalParams extends coreClient.OperationOptions { +} + +// @public +export type TieringGetByResourceIdResponse = AcsTier; + +// @public +export interface TrialPhoneNumberPurchase { + numberType?: string[]; + scope?: string; + totalNumbers?: number; + trialPeriodDays?: number; +} + +// @public +export interface TrialPhoneNumberUsage { + calling?: TrialPhoneNumberUsageCalling; + numberType?: string; + sms?: TrialPhoneNumberUsageSms; +} + +// @public +export interface TrialPhoneNumberUsageCalling { + inbound?: TrialPhoneNumberUsageCallingBounds[]; + outbound?: TrialPhoneNumberUsageCallingBounds[]; +} + +// @public +export interface TrialPhoneNumberUsageCallingBounds { + concurrentCalls?: number; + maximumCallDurationMinutes?: number; + scope?: string; + totalMinutes?: number; + type?: string; +} + +// @public +export interface TrialPhoneNumberUsageSms { + inbound?: TrialPhoneNumberUsageSmsBounds[]; + outbound?: TrialPhoneNumberUsageSmsBounds[]; +} + +// @public +export interface TrialPhoneNumberUsageSmsBounds { + scope?: string; + smsPerMin?: number; + total?: number; + type?: string; +} + +// (No @packageDocumentation comment for this package) + +``` diff --git a/sdk/communication/communication-tiering/sample.env b/sdk/communication/communication-tiering/sample.env new file mode 100644 index 000000000000..ecc5467f2006 --- /dev/null +++ b/sdk/communication/communication-tiering/sample.env @@ -0,0 +1,3 @@ +# Used in most samples. Retrieve these values from a Communication Services instance +# in the Azure Portal. +COMMUNICATION_SAMPLES_CONNECTION_STRING="endpoint=https://.communication.azure.net/;accessKey=" diff --git a/sdk/communication/communication-tiering/samples-dev/getAcquiredNumberLimits.ts b/sdk/communication/communication-tiering/samples-dev/getAcquiredNumberLimits.ts new file mode 100644 index 000000000000..3515d60f7dcc --- /dev/null +++ b/sdk/communication/communication-tiering/samples-dev/getAcquiredNumberLimits.ts @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * @summary Get acquired numbers and limits for a resource + */ + +import { TieringClient } from "@azure-tools/communication-tiering"; + +// Load the .env file if it exists +import * as dotenv from "dotenv"; +dotenv.config(); + +export async function main() { + console.log("\n== Get acquired numbers and limits for a resource ==\n"); + + // You will need to set this environment variable or edit the following values + const connectionString = + process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING || + "endpoint=https://resourceName.communication.azure.net/;accessKey=test-key"; + + // create new client + const client = new TieringClient(connectionString); + + const resourceId = "5d41e908-de88-4bbf-94dc-fe9a1b51029b"; + + // Get acquired numbers and limits for a resource + var acquiredNumberLimits = await client.getAcquiredNumberLimits(resourceId); + + // print all number limits + console.log(acquiredNumberLimits); +} + +main().catch((error) => { + console.log("The sample getAcquiredNumberLimits encountered an error:", error); + process.exit(1); +}); diff --git a/sdk/communication/communication-tiering/samples-dev/getTierInfo.ts b/sdk/communication/communication-tiering/samples-dev/getTierInfo.ts new file mode 100644 index 000000000000..d4f5bc2d578f --- /dev/null +++ b/sdk/communication/communication-tiering/samples-dev/getTierInfo.ts @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * @summary Get tiering info for a resource. + */ + +import { TieringClient } from "@azure-tools/communication-tiering"; + +// Load the .env file if it exists +import * as dotenv from "dotenv"; +dotenv.config(); + +export async function main() { + console.log("\n== Get tiering info for a resource ==\n"); + + // You will need to set this environment variable or edit the following values + const connectionString = + process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING || + "endpoint=https://resourceName.communication.azure.net/;accessKey=test-key"; + + // create new client + const client = new TieringClient(connectionString); + + const resourceId = "5d41e908-de88-4bbf-94dc-fe9a1b51029b"; + + // Get tier info for a resource + var tierInfo = await client.getTierByResourceId(resourceId); + + // print all tier info + console.log(tierInfo); +} + +main().catch((error) => { + console.log("The sample getTierByResourceId encountered an error:", error); + process.exit(1); +}); diff --git a/sdk/communication/communication-tiering/samples/v1-beta/javascript/README.md b/sdk/communication/communication-tiering/samples/v1-beta/javascript/README.md new file mode 100644 index 000000000000..a66e9dfee0b6 --- /dev/null +++ b/sdk/communication/communication-tiering/samples/v1-beta/javascript/README.md @@ -0,0 +1,64 @@ +--- +page_type: sample +languages: + - javascript +products: + - azure + - azure-communication-services +urlFragment: communication-tiering-javascript-beta +--- + +# Azure Communication Services - Tiering client library samples for JavaScript (Beta) + +These sample programs show how to use the JavaScript client libraries for Azure Communication Services - Tiering in some common scenarios. + +| **File Name** | **Description** | +| ----------------------------------------------------- | ---------------------------------------------- | +| [getAcquiredNumberLimits.js][getacquirednumberlimits] | Get acquired numbers and limits for a resource | +| [getTierInfo.js][gettierinfo] | Get tiering info for a resource. | + +## Prerequisites + +The sample programs are compatible with [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule). + +You need [an Azure subscription][freesub] and the following Azure resources to run these sample programs: + +- [Azure Communication Services account][createinstance_azurecommunicationservicesaccount] + +Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function. + +Adapting the samples to run in the browser may require some additional consideration. For details, please see the [package README][package]. + +## Setup + +To run the samples using the published version of the package: + +1. Install the dependencies using `npm`: + +```bash +npm install +``` + +2. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically. + +3. Run whichever samples you like (note that some samples may require additional setup, see the table above): + +```bash +node getAcquiredNumberLimits.js +``` + +Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform): + +```bash +npx cross-env COMMUNICATION_SAMPLES_CONNECTION_STRING="" node getAcquiredNumberLimits.js +``` + +## Next Steps + +Here are some [samples] to look at. + +[getacquirednumberlimits]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/communication/communication-tiering/samples/v1-beta/javascript/getAcquiredNumberLimits.js +[gettierinfo]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/communication/communication-tiering/samples/v1-beta/javascript/getTierInfo.js +[freesub]: https://azure.microsoft.com/free/ +[createinstance_azurecommunicationservicesaccount]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource +[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-tiering/README.md diff --git a/sdk/communication/communication-tiering/samples/v1-beta/javascript/getAcquiredNumberLimits.js b/sdk/communication/communication-tiering/samples/v1-beta/javascript/getAcquiredNumberLimits.js new file mode 100644 index 000000000000..df497c33ec66 --- /dev/null +++ b/sdk/communication/communication-tiering/samples/v1-beta/javascript/getAcquiredNumberLimits.js @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * @summary Get acquired numbers and limits for a resource + */ + +const { TieringClient } = require("@azure-tools/communication-tiering"); + +// Load the .env file if it exists +require("dotenv").config(); + +async function main() { + console.log("\n== Get acquired numbers and limits for a resource ==\n"); + + // You will need to set this environment variable or edit the following values + const connectionString = + process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING || + "endpoint=https://resourceName.communication.azure.net/;accessKey=test-key"; + + // create new client + const client = new TieringClient(connectionString); + + const resourceId = "5d41e908-de88-4bbf-94dc-fe9a1b51029b"; + + // Get acquired numbers and limits for a resource + var acquiredNumberLimits = await client.getAcquiredNumberLimits(resourceId); + + // print all number limits + console.log(acquiredNumberLimits); +} + +main().catch((error) => { + console.log("The sample getAcquiredNumberLimits encountered an error:", error); + process.exit(1); +}); + +module.exports = { main }; diff --git a/sdk/communication/communication-tiering/samples/v1-beta/javascript/getTierInfo.js b/sdk/communication/communication-tiering/samples/v1-beta/javascript/getTierInfo.js new file mode 100644 index 000000000000..340a16cece5d --- /dev/null +++ b/sdk/communication/communication-tiering/samples/v1-beta/javascript/getTierInfo.js @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * @summary Get tiering info for a resource. + */ + +const { TieringClient } = require("@azure-tools/communication-tiering"); + +// Load the .env file if it exists +require("dotenv").config(); + +async function main() { + console.log("\n== Get tiering info for a resource ==\n"); + + // You will need to set this environment variable or edit the following values + const connectionString = + process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING || + "endpoint=https://resourceName.communication.azure.net/;accessKey=test-key"; + + // create new client + const client = new TieringClient(connectionString); + + const resourceId = "5d41e908-de88-4bbf-94dc-fe9a1b51029b"; + + // Get tier info for a resource + var tierInfo = await client.getTierByResourceId(resourceId); + + // print all tier info + console.log(tierInfo); +} + +main().catch((error) => { + console.log("The sample getTierByResourceId encountered an error:", error); + process.exit(1); +}); + +module.exports = { main }; diff --git a/sdk/communication/communication-tiering/samples/v1-beta/javascript/package.json b/sdk/communication/communication-tiering/samples/v1-beta/javascript/package.json new file mode 100644 index 000000000000..679d3a30ba9c --- /dev/null +++ b/sdk/communication/communication-tiering/samples/v1-beta/javascript/package.json @@ -0,0 +1,29 @@ +{ + "name": "@azure-samples/communication-tiering-js-beta", + "private": true, + "version": "1.0.0", + "description": "Azure Communication Services - Tiering client library samples for JavaScript (Beta)", + "engines": { + "node": ">=14.0.0" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Azure/azure-sdk-for-js.git", + "directory": "sdk/communication/communication-tiering" + }, + "keywords": [ + "azure", + "cloud", + "communication" + ], + "author": "Microsoft Corporation", + "license": "MIT", + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-tiering", + "dependencies": { + "@azure-tools/communication-tiering": "next", + "dotenv": "latest" + } +} diff --git a/sdk/communication/communication-tiering/samples/v1-beta/javascript/sample.env b/sdk/communication/communication-tiering/samples/v1-beta/javascript/sample.env new file mode 100644 index 000000000000..ecc5467f2006 --- /dev/null +++ b/sdk/communication/communication-tiering/samples/v1-beta/javascript/sample.env @@ -0,0 +1,3 @@ +# Used in most samples. Retrieve these values from a Communication Services instance +# in the Azure Portal. +COMMUNICATION_SAMPLES_CONNECTION_STRING="endpoint=https://.communication.azure.net/;accessKey=" diff --git a/sdk/communication/communication-tiering/samples/v1-beta/typescript/README.md b/sdk/communication/communication-tiering/samples/v1-beta/typescript/README.md new file mode 100644 index 000000000000..2b9c74e37b17 --- /dev/null +++ b/sdk/communication/communication-tiering/samples/v1-beta/typescript/README.md @@ -0,0 +1,77 @@ +--- +page_type: sample +languages: + - typescript +products: + - azure + - azure-communication-services +urlFragment: communication-tiering-typescript-beta +--- + +# Azure Communication Services - Tiering client library samples for TypeScript (Beta) + +These sample programs show how to use the TypeScript client libraries for Azure Communication Services - Tiering in some common scenarios. + +| **File Name** | **Description** | +| ----------------------------------------------------- | ---------------------------------------------- | +| [getAcquiredNumberLimits.ts][getacquirednumberlimits] | Get acquired numbers and limits for a resource | +| [getTierInfo.ts][gettierinfo] | Get tiering info for a resource. | + +## Prerequisites + +The sample programs are compatible with [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule). + +Before running the samples in Node, they must be compiled to JavaScript using the TypeScript compiler. For more information on TypeScript, see the [TypeScript documentation][typescript]. Install the TypeScript compiler using: + +```bash +npm install -g typescript +``` + +You need [an Azure subscription][freesub] and the following Azure resources to run these sample programs: + +- [Azure Communication Services account][createinstance_azurecommunicationservicesaccount] + +Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function. + +Adapting the samples to run in the browser may require some additional consideration. For details, please see the [package README][package]. + +## Setup + +To run the samples using the published version of the package: + +1. Install the dependencies using `npm`: + +```bash +npm install +``` + +2. Compile the samples: + +```bash +npm run build +``` + +3. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically. + +4. Run whichever samples you like (note that some samples may require additional setup, see the table above): + +```bash +node dist/getAcquiredNumberLimits.js +``` + +Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform): + +```bash +npx cross-env COMMUNICATION_SAMPLES_CONNECTION_STRING="" node dist/getAcquiredNumberLimits.js +``` + +## Next Steps + +Here are some [samples] to look at. + +[getacquirednumberlimits]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/communication/communication-tiering/samples/v1-beta/typescript/src/getAcquiredNumberLimits.ts +[gettierinfo]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/communication/communication-tiering/samples/v1-beta/typescript/src/getTierInfo.ts +[freesub]: https://azure.microsoft.com/free/ +[createinstance_azurecommunicationservicesaccount]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource +[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-tiering/README.md +[typescript]: https://www.typescriptlang.org/docs/home.html diff --git a/sdk/communication/communication-tiering/samples/v1-beta/typescript/package.json b/sdk/communication/communication-tiering/samples/v1-beta/typescript/package.json new file mode 100644 index 000000000000..f85a2c56c316 --- /dev/null +++ b/sdk/communication/communication-tiering/samples/v1-beta/typescript/package.json @@ -0,0 +1,38 @@ +{ + "name": "@azure-samples/communication-tiering-ts-beta", + "private": true, + "version": "1.0.0", + "description": "Azure Communication Services - Tiering client library samples for TypeScript (Beta)", + "engines": { + "node": ">=14.0.0" + }, + "scripts": { + "build": "tsc", + "prebuild": "rimraf dist/" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Azure/azure-sdk-for-js.git", + "directory": "sdk/communication/communication-tiering" + }, + "keywords": [ + "azure", + "cloud", + "communication" + ], + "author": "Microsoft Corporation", + "license": "MIT", + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-tiering", + "dependencies": { + "@azure-tools/communication-tiering": "next", + "dotenv": "latest" + }, + "devDependencies": { + "@types/node": "^14.0.0", + "typescript": "~5.0.0", + "rimraf": "latest" + } +} diff --git a/sdk/communication/communication-tiering/samples/v1-beta/typescript/sample.env b/sdk/communication/communication-tiering/samples/v1-beta/typescript/sample.env new file mode 100644 index 000000000000..ecc5467f2006 --- /dev/null +++ b/sdk/communication/communication-tiering/samples/v1-beta/typescript/sample.env @@ -0,0 +1,3 @@ +# Used in most samples. Retrieve these values from a Communication Services instance +# in the Azure Portal. +COMMUNICATION_SAMPLES_CONNECTION_STRING="endpoint=https://.communication.azure.net/;accessKey=" diff --git a/sdk/communication/communication-tiering/samples/v1-beta/typescript/src/getAcquiredNumberLimits.ts b/sdk/communication/communication-tiering/samples/v1-beta/typescript/src/getAcquiredNumberLimits.ts new file mode 100644 index 000000000000..3515d60f7dcc --- /dev/null +++ b/sdk/communication/communication-tiering/samples/v1-beta/typescript/src/getAcquiredNumberLimits.ts @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * @summary Get acquired numbers and limits for a resource + */ + +import { TieringClient } from "@azure-tools/communication-tiering"; + +// Load the .env file if it exists +import * as dotenv from "dotenv"; +dotenv.config(); + +export async function main() { + console.log("\n== Get acquired numbers and limits for a resource ==\n"); + + // You will need to set this environment variable or edit the following values + const connectionString = + process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING || + "endpoint=https://resourceName.communication.azure.net/;accessKey=test-key"; + + // create new client + const client = new TieringClient(connectionString); + + const resourceId = "5d41e908-de88-4bbf-94dc-fe9a1b51029b"; + + // Get acquired numbers and limits for a resource + var acquiredNumberLimits = await client.getAcquiredNumberLimits(resourceId); + + // print all number limits + console.log(acquiredNumberLimits); +} + +main().catch((error) => { + console.log("The sample getAcquiredNumberLimits encountered an error:", error); + process.exit(1); +}); diff --git a/sdk/communication/communication-tiering/samples/v1-beta/typescript/src/getTierInfo.ts b/sdk/communication/communication-tiering/samples/v1-beta/typescript/src/getTierInfo.ts new file mode 100644 index 000000000000..d4f5bc2d578f --- /dev/null +++ b/sdk/communication/communication-tiering/samples/v1-beta/typescript/src/getTierInfo.ts @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * @summary Get tiering info for a resource. + */ + +import { TieringClient } from "@azure-tools/communication-tiering"; + +// Load the .env file if it exists +import * as dotenv from "dotenv"; +dotenv.config(); + +export async function main() { + console.log("\n== Get tiering info for a resource ==\n"); + + // You will need to set this environment variable or edit the following values + const connectionString = + process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING || + "endpoint=https://resourceName.communication.azure.net/;accessKey=test-key"; + + // create new client + const client = new TieringClient(connectionString); + + const resourceId = "5d41e908-de88-4bbf-94dc-fe9a1b51029b"; + + // Get tier info for a resource + var tierInfo = await client.getTierByResourceId(resourceId); + + // print all tier info + console.log(tierInfo); +} + +main().catch((error) => { + console.log("The sample getTierByResourceId encountered an error:", error); + process.exit(1); +}); diff --git a/sdk/communication/communication-tiering/samples/v1-beta/typescript/tsconfig.json b/sdk/communication/communication-tiering/samples/v1-beta/typescript/tsconfig.json new file mode 100644 index 000000000000..e26ce2a6d8f7 --- /dev/null +++ b/sdk/communication/communication-tiering/samples/v1-beta/typescript/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "commonjs", + "moduleResolution": "node", + "resolveJsonModule": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "alwaysStrict": true, + "outDir": "dist", + "rootDir": "src" + }, + "include": [ + "src/**.ts" + ] +} diff --git a/sdk/communication/communication-tiering/src/generated/src/index.ts b/sdk/communication/communication-tiering/src/generated/src/index.ts new file mode 100644 index 000000000000..8302fcac886c --- /dev/null +++ b/sdk/communication/communication-tiering/src/generated/src/index.ts @@ -0,0 +1,11 @@ +/* + * 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. + */ + +export * from "./models"; +export { TieringClient } from "./tieringClient"; +export * from "./operationsInterfaces"; diff --git a/sdk/communication/communication-tiering/src/generated/src/models/index.ts b/sdk/communication/communication-tiering/src/generated/src/models/index.ts new file mode 100644 index 000000000000..9955b659a18a --- /dev/null +++ b/sdk/communication/communication-tiering/src/generated/src/models/index.ts @@ -0,0 +1,256 @@ +/* + * 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. + */ + +import * as coreClient from "@azure/core-client"; + +export interface Paths190FnhrAdministrationResourcesResourceidTelephoneNumberSummaryGetResponses200ContentApplicationJsonSchema { + /** AssetDetails Array */ + assetDetails: AssetDetails[]; +} + +/** Model response for acquired number and limits. */ +export interface AssetDetails { + /** Array defining the number type of the phone number. */ + numberType?: string[]; + /** Number of phone numbers that the resource has. */ + resourceAcquiredCount?: number; + /** Number of phone numbers that the subscription that the resource belongs to has. */ + subscriptionAcquiredCount?: number; + /** Number of phone numbers that the AAD tenant that the resource belongs to has. */ + aadTenantAcquiredCount?: number; + /** Tier specific info. */ + tierInfo?: AssetDetailsTierInfo; +} + +/** Tier specific info. */ +export interface AssetDetailsTierInfo { + /** The level at which the tiering properties in the TierInfo are for */ + scope?: string; + /** Number of phone numbers allowed that can change based on scope where scope can be (resource, subscription or tenant). */ + allowed?: number; + /** Number of phone numbers acquired that can change based on scope where scope can be (resource, subscription or tenant). */ + acquired?: number; + /** Difference between allowed and acquired amount. */ + balance?: number; + /** The standing of a customer to determine if they able to purchase more phone numbers. */ + limit?: string; +} + +/** The Communication Services error. */ +export interface CommunicationErrorResponse { + /** The Communication Services error. */ + error: CommunicationError; +} + +/** The Communication Services error. */ +export interface CommunicationError { + /** The error code. */ + code: string; + /** The error message. */ + message: string; + /** + * The error target. + * NOTE: This property will not be serialized. It can only be populated by the server. + */ + readonly target?: string; + /** + * Further details about specific errors that led to this error. + * NOTE: This property will not be serialized. It can only be populated by the server. + */ + readonly details?: CommunicationError[]; + /** + * The inner error if any. + * NOTE: This property will not be serialized. It can only be populated by the server. + */ + readonly innerError?: CommunicationError; +} + +/** Represents an ACS Tier resource. */ +export interface AcsTier { + /** Tier Id. */ + tierId?: string; + /** Tier Type */ + tierType?: string; + /** Capabilities for the resource */ + capabilities?: AcsTierCapabilities; +} + +/** Capabilities for the resource */ +export interface AcsTierCapabilities { + /** Phone number purchase capabilities of the tier. */ + phoneNumberPurchase?: PhoneNumberPurchase[]; + /** SMS capabilities of the tier. */ + sms?: AcsTierCapabilitiesSms; + /** Calling capabilities of the tier. */ + calling?: AcsTierCapabilitiesCalling; + /** Trial phone number purchase capability details. */ + trialPhoneNumberPurchase?: TrialPhoneNumberPurchase[]; + /** Trial phone number usage of the tier. */ + trialPhoneNumberUsage?: TrialPhoneNumberUsage[]; +} + +/** Phone number purchase capability details. */ +export interface PhoneNumberPurchase { + /** Types to apply the limit to. */ + numberType?: string[]; + /** The scope to apply the limits. */ + scope?: string; + /** The limit of numbers allowed for purchase for the number type. */ + totalNumbers?: number; +} + +/** SMS capabilities of the tier. */ +export interface AcsTierCapabilitiesSms { + /** SMS Outbound capabilities of the tier. */ + outbound?: SmsOutbound[]; + /** SMS Inbound capabilities of the tier. */ + inbound?: SmsInbound[]; +} + +/** Sms Outbound Capabilities for the tier. */ +export interface SmsOutbound { + /** Type of number. */ + type?: string; + /** The scope to apply the limits. */ + scope?: string; + /** The limit of SMSs a customer can send per minute. */ + smsPerMin?: number; + /** The areas where an SMS is allowed to be sent. */ + geographicLimitations?: string; +} + +/** Sms Inbound Capabilities for the tier. */ +export interface SmsInbound { + /** Type of number. */ + type?: string; + /** The scope to apply the limits. */ + scope?: string; + /** The limit of SMSs a customer can send per minute. */ + smsPerMin?: number; + /** The areas where an SMS is allowed to be sent. */ + geographicLimitations?: string; +} + +/** Calling capabilities of the tier. */ +export interface AcsTierCapabilitiesCalling { + /** Calling Outbound capabilities of the tier. */ + outbound?: CallingOutbound[]; + /** Calling Inbound capabilities of the tier. */ + inbound?: CallingInbound[]; +} + +/** Calling Outbound Capabilities for the tier. */ +export interface CallingOutbound { + /** Type of calling. */ + type?: string; + /** The scope to apply the limits. */ + scope?: string; + /** The number of concurrent calls allowed. */ + concurrentCalls?: number; + /** The areas where calls are allowed to take place. */ + geographicLimitations?: string; +} + +/** Calling Outbound Capabilities for the tier. */ +export interface CallingInbound { + /** Type of calling. */ + type?: string; + /** The scope to apply the limits. */ + scope?: string; + /** The number of concurrent calls allowed. */ + concurrentCalls?: number; + /** The areas where calls are allowed to take place. */ + geographicLimitations?: string; +} + +/** Trial phone number purchase capability details. */ +export interface TrialPhoneNumberPurchase { + /** Types to apply the limit to. */ + numberType?: string[]; + /** The scope to apply the limits. */ + scope?: string; + /** The limit of numbers allowed for purchase for the number type. */ + totalNumbers?: number; + /** The number of days in the trial period for the number type. */ + trialPeriodDays?: number; +} + +/** Trial phone number usage capability details. */ +export interface TrialPhoneNumberUsage { + /** The number type. */ + numberType?: string; + /** The capabilities for calling. */ + calling?: TrialPhoneNumberUsageCalling; + /** The SMS capabilities for the trial phone number. */ + sms?: TrialPhoneNumberUsageSms; +} + +/** The capabilities for calling. */ +export interface TrialPhoneNumberUsageCalling { + /** The Outbound capabilities for calling. */ + outbound?: TrialPhoneNumberUsageCallingBounds[]; + /** The Inbound capabilities for calling. */ + inbound?: TrialPhoneNumberUsageCallingBounds[]; +} + +/** Trial phone number capability details. */ +export interface TrialPhoneNumberUsageCallingBounds { + /** Type of calling. */ + type?: string; + /** The scope to apply the limits to. */ + scope?: string; + /** The total calling minutes allowed for a tial number. */ + totalMinutes?: number; + /** The total call duration in minutes allowed for a trial number. */ + maximumCallDurationMinutes?: number; + /** The number of concurrent calls allowed. */ + concurrentCalls?: number; +} + +/** The SMS capabilities for the trial phone number. */ +export interface TrialPhoneNumberUsageSms { + /** Outbound trial phone number SMS capabilities. */ + outbound?: TrialPhoneNumberUsageSmsBounds[]; + /** Inbound trial phone number SMS capabilities. */ + inbound?: TrialPhoneNumberUsageSmsBounds[]; +} + +/** Trial phone number SMS capability details. */ +export interface TrialPhoneNumberUsageSmsBounds { + /** The type of SMS. */ + type?: string; + /** The scope to apply the limits to. */ + scope?: string; + /** Total */ + total?: number; + /** The total SMSs allowed to be sent in a minute. */ + smsPerMin?: number; +} + +/** Optional parameters. */ +export interface NumberAllotmentGetAcquiredNumberLimitsOptionalParams + extends coreClient.OperationOptions {} + +/** Contains response data for the getAcquiredNumberLimits operation. */ +export type NumberAllotmentGetAcquiredNumberLimitsResponse = Paths190FnhrAdministrationResourcesResourceidTelephoneNumberSummaryGetResponses200ContentApplicationJsonSchema; + +/** Optional parameters. */ +export interface TieringGetByResourceIdOptionalParams + extends coreClient.OperationOptions {} + +/** Contains response data for the getByResourceId operation. */ +export type TieringGetByResourceIdResponse = AcsTier; + +/** Optional parameters. */ +export interface TieringClientOptionalParams + extends coreClient.ServiceClientOptions { + /** Api Version */ + apiVersion?: string; + /** Overrides client endpoint. */ + endpoint?: string; +} diff --git a/sdk/communication/communication-tiering/src/generated/src/models/mappers.ts b/sdk/communication/communication-tiering/src/generated/src/models/mappers.ts new file mode 100644 index 000000000000..eacaa6298fdf --- /dev/null +++ b/sdk/communication/communication-tiering/src/generated/src/models/mappers.ts @@ -0,0 +1,704 @@ +/* + * 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. + */ + +import * as coreClient from "@azure/core-client"; + +export const Paths190FnhrAdministrationResourcesResourceidTelephoneNumberSummaryGetResponses200ContentApplicationJsonSchema: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: + "Paths190FnhrAdministrationResourcesResourceidTelephoneNumberSummaryGetResponses200ContentApplicationJsonSchema", + modelProperties: { + assetDetails: { + serializedName: "assetDetails", + required: true, + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "AssetDetails" + } + } + } + } + } + } +}; + +export const AssetDetails: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "AssetDetails", + modelProperties: { + numberType: { + serializedName: "numberType", + type: { + name: "Sequence", + element: { + type: { + name: "String" + } + } + } + }, + resourceAcquiredCount: { + serializedName: "resourceAcquiredCount", + type: { + name: "Number" + } + }, + subscriptionAcquiredCount: { + serializedName: "subscriptionAcquiredCount", + type: { + name: "Number" + } + }, + aadTenantAcquiredCount: { + serializedName: "aadTenantAcquiredCount", + type: { + name: "Number" + } + }, + tierInfo: { + serializedName: "tierInfo", + type: { + name: "Composite", + className: "AssetDetailsTierInfo" + } + } + } + } +}; + +export const AssetDetailsTierInfo: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "AssetDetailsTierInfo", + modelProperties: { + scope: { + serializedName: "scope", + type: { + name: "String" + } + }, + allowed: { + serializedName: "allowed", + type: { + name: "Number" + } + }, + acquired: { + serializedName: "acquired", + type: { + name: "Number" + } + }, + balance: { + serializedName: "balance", + type: { + name: "Number" + } + }, + limit: { + serializedName: "limit", + type: { + name: "String" + } + } + } + } +}; + +export const CommunicationErrorResponse: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "CommunicationErrorResponse", + modelProperties: { + error: { + serializedName: "error", + type: { + name: "Composite", + className: "CommunicationError" + } + } + } + } +}; + +export const CommunicationError: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "CommunicationError", + modelProperties: { + code: { + serializedName: "code", + required: true, + type: { + name: "String" + } + }, + message: { + serializedName: "message", + required: true, + type: { + name: "String" + } + }, + target: { + serializedName: "target", + readOnly: true, + type: { + name: "String" + } + }, + details: { + serializedName: "details", + readOnly: true, + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "CommunicationError" + } + } + } + }, + innerError: { + serializedName: "innererror", + type: { + name: "Composite", + className: "CommunicationError" + } + } + } + } +}; + +export const AcsTier: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "AcsTier", + modelProperties: { + tierId: { + serializedName: "tierId", + type: { + name: "String" + } + }, + tierType: { + serializedName: "tierType", + type: { + name: "String" + } + }, + capabilities: { + serializedName: "capabilities", + type: { + name: "Composite", + className: "AcsTierCapabilities" + } + } + } + } +}; + +export const AcsTierCapabilities: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "AcsTierCapabilities", + modelProperties: { + phoneNumberPurchase: { + serializedName: "phoneNumberPurchase", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "PhoneNumberPurchase" + } + } + } + }, + sms: { + serializedName: "sms", + type: { + name: "Composite", + className: "AcsTierCapabilitiesSms" + } + }, + calling: { + serializedName: "calling", + type: { + name: "Composite", + className: "AcsTierCapabilitiesCalling" + } + }, + trialPhoneNumberPurchase: { + serializedName: "trialPhoneNumberPurchase", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "TrialPhoneNumberPurchase" + } + } + } + }, + trialPhoneNumberUsage: { + serializedName: "trialPhoneNumberUsage", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "TrialPhoneNumberUsage" + } + } + } + } + } + } +}; + +export const PhoneNumberPurchase: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "PhoneNumberPurchase", + modelProperties: { + numberType: { + serializedName: "numberType", + type: { + name: "Sequence", + element: { + type: { + name: "String" + } + } + } + }, + scope: { + serializedName: "scope", + type: { + name: "String" + } + }, + totalNumbers: { + serializedName: "totalNumbers", + type: { + name: "Number" + } + } + } + } +}; + +export const AcsTierCapabilitiesSms: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "AcsTierCapabilitiesSms", + modelProperties: { + outbound: { + serializedName: "outbound", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "SmsOutbound" + } + } + } + }, + inbound: { + serializedName: "inbound", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "SmsInbound" + } + } + } + } + } + } +}; + +export const SmsOutbound: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "SmsOutbound", + modelProperties: { + type: { + serializedName: "type", + type: { + name: "String" + } + }, + scope: { + serializedName: "scope", + type: { + name: "String" + } + }, + smsPerMin: { + serializedName: "smsPerMin", + type: { + name: "Number" + } + }, + geographicLimitations: { + serializedName: "geographicLimitations", + type: { + name: "String" + } + } + } + } +}; + +export const SmsInbound: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "SmsInbound", + modelProperties: { + type: { + serializedName: "type", + type: { + name: "String" + } + }, + scope: { + serializedName: "scope", + type: { + name: "String" + } + }, + smsPerMin: { + serializedName: "smsPerMin", + type: { + name: "Number" + } + }, + geographicLimitations: { + serializedName: "geographicLimitations", + type: { + name: "String" + } + } + } + } +}; + +export const AcsTierCapabilitiesCalling: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "AcsTierCapabilitiesCalling", + modelProperties: { + outbound: { + serializedName: "outbound", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "CallingOutbound" + } + } + } + }, + inbound: { + serializedName: "inbound", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "CallingInbound" + } + } + } + } + } + } +}; + +export const CallingOutbound: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "CallingOutbound", + modelProperties: { + type: { + serializedName: "type", + type: { + name: "String" + } + }, + scope: { + serializedName: "scope", + type: { + name: "String" + } + }, + concurrentCalls: { + serializedName: "concurrentCalls", + type: { + name: "Number" + } + }, + geographicLimitations: { + serializedName: "geographicLimitations", + type: { + name: "String" + } + } + } + } +}; + +export const CallingInbound: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "CallingInbound", + modelProperties: { + type: { + serializedName: "type", + type: { + name: "String" + } + }, + scope: { + serializedName: "scope", + type: { + name: "String" + } + }, + concurrentCalls: { + serializedName: "concurrentCalls", + type: { + name: "Number" + } + }, + geographicLimitations: { + serializedName: "geographicLimitations", + type: { + name: "String" + } + } + } + } +}; + +export const TrialPhoneNumberPurchase: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "TrialPhoneNumberPurchase", + modelProperties: { + numberType: { + serializedName: "numberType", + type: { + name: "Sequence", + element: { + type: { + name: "String" + } + } + } + }, + scope: { + serializedName: "scope", + type: { + name: "String" + } + }, + totalNumbers: { + serializedName: "totalNumbers", + type: { + name: "Number" + } + }, + trialPeriodDays: { + serializedName: "trialPeriodDays", + type: { + name: "Number" + } + } + } + } +}; + +export const TrialPhoneNumberUsage: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "TrialPhoneNumberUsage", + modelProperties: { + numberType: { + serializedName: "numberType", + type: { + name: "String" + } + }, + calling: { + serializedName: "calling", + type: { + name: "Composite", + className: "TrialPhoneNumberUsageCalling" + } + }, + sms: { + serializedName: "sms", + type: { + name: "Composite", + className: "TrialPhoneNumberUsageSms" + } + } + } + } +}; + +export const TrialPhoneNumberUsageCalling: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "TrialPhoneNumberUsageCalling", + modelProperties: { + outbound: { + serializedName: "outbound", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "TrialPhoneNumberUsageCallingBounds" + } + } + } + }, + inbound: { + serializedName: "inbound", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "TrialPhoneNumberUsageCallingBounds" + } + } + } + } + } + } +}; + +export const TrialPhoneNumberUsageCallingBounds: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "TrialPhoneNumberUsageCallingBounds", + modelProperties: { + type: { + serializedName: "type", + type: { + name: "String" + } + }, + scope: { + serializedName: "scope", + type: { + name: "String" + } + }, + totalMinutes: { + serializedName: "totalMinutes", + type: { + name: "Number" + } + }, + maximumCallDurationMinutes: { + serializedName: "maximumCallDurationMinutes", + type: { + name: "Number" + } + }, + concurrentCalls: { + serializedName: "concurrentCalls", + type: { + name: "Number" + } + } + } + } +}; + +export const TrialPhoneNumberUsageSms: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "TrialPhoneNumberUsageSms", + modelProperties: { + outbound: { + serializedName: "outbound", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "TrialPhoneNumberUsageSmsBounds" + } + } + } + }, + inbound: { + serializedName: "inbound", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "TrialPhoneNumberUsageSmsBounds" + } + } + } + } + } + } +}; + +export const TrialPhoneNumberUsageSmsBounds: coreClient.CompositeMapper = { + type: { + name: "Composite", + className: "TrialPhoneNumberUsageSmsBounds", + modelProperties: { + type: { + serializedName: "type", + type: { + name: "String" + } + }, + scope: { + serializedName: "scope", + type: { + name: "String" + } + }, + total: { + serializedName: "total", + type: { + name: "Number" + } + }, + smsPerMin: { + serializedName: "smsPerMin", + type: { + name: "Number" + } + } + } + } +}; diff --git a/sdk/communication/communication-tiering/src/generated/src/models/parameters.ts b/sdk/communication/communication-tiering/src/generated/src/models/parameters.ts new file mode 100644 index 000000000000..96d67aaabdb0 --- /dev/null +++ b/sdk/communication/communication-tiering/src/generated/src/models/parameters.ts @@ -0,0 +1,60 @@ +/* + * 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. + */ + +import { + OperationParameter, + OperationURLParameter, + OperationQueryParameter +} from "@azure/core-client"; + +export const accept: OperationParameter = { + parameterPath: "accept", + mapper: { + defaultValue: "application/json", + isConstant: true, + serializedName: "Accept", + type: { + name: "String" + } + } +}; + +export const endpoint: OperationURLParameter = { + parameterPath: "endpoint", + mapper: { + serializedName: "endpoint", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; + +export const resourceId: OperationURLParameter = { + parameterPath: "resourceId", + mapper: { + serializedName: "resourceId", + required: true, + type: { + name: "Uuid" + } + } +}; + +export const apiVersion: OperationQueryParameter = { + parameterPath: "apiVersion", + mapper: { + defaultValue: "2023-06-15", + isConstant: true, + serializedName: "api-version", + type: { + name: "String" + } + } +}; diff --git a/sdk/communication/communication-tiering/src/generated/src/operations/index.ts b/sdk/communication/communication-tiering/src/generated/src/operations/index.ts new file mode 100644 index 000000000000..6e187b6a22c2 --- /dev/null +++ b/sdk/communication/communication-tiering/src/generated/src/operations/index.ts @@ -0,0 +1,10 @@ +/* + * 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. + */ + +export * from "./numberAllotment"; +export * from "./tiering"; diff --git a/sdk/communication/communication-tiering/src/generated/src/operations/numberAllotment.ts b/sdk/communication/communication-tiering/src/generated/src/operations/numberAllotment.ts new file mode 100644 index 000000000000..026ca61ab667 --- /dev/null +++ b/sdk/communication/communication-tiering/src/generated/src/operations/numberAllotment.ts @@ -0,0 +1,72 @@ +/* + * 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. + */ + +import { tracingClient } from "../tracing"; +import { NumberAllotment } from "../operationsInterfaces"; +import * as coreClient from "@azure/core-client"; +import * as Mappers from "../models/mappers"; +import * as Parameters from "../models/parameters"; +import { TieringClient } from "../tieringClient"; +import { + NumberAllotmentGetAcquiredNumberLimitsOptionalParams, + NumberAllotmentGetAcquiredNumberLimitsResponse +} from "../models"; + +/** Class containing NumberAllotment operations. */ +export class NumberAllotmentImpl implements NumberAllotment { + private readonly client: TieringClient; + + /** + * Initialize a new instance of the class NumberAllotment class. + * @param client Reference to the service client + */ + constructor(client: TieringClient) { + this.client = client; + } + + /** + * Get acquired numbers and limits for a resource. + * @param resourceId Resource Id. Must be a valid GUID + * @param options The options parameters. + */ + async getAcquiredNumberLimits( + resourceId: string, + options?: NumberAllotmentGetAcquiredNumberLimitsOptionalParams + ): Promise { + return tracingClient.withSpan( + "TieringClient.getAcquiredNumberLimits", + options ?? {}, + async (options) => { + return this.client.sendOperationRequest( + { resourceId, options }, + getAcquiredNumberLimitsOperationSpec + ) as Promise; + } + ); + } +} +// Operation Specifications +const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); + +const getAcquiredNumberLimitsOperationSpec: coreClient.OperationSpec = { + path: "/administration/resources/{resourceId}/telephone-number-summary", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: + Mappers.Paths190FnhrAdministrationResourcesResourceidTelephoneNumberSummaryGetResponses200ContentApplicationJsonSchema + }, + default: { + bodyMapper: Mappers.CommunicationErrorResponse + } + }, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint, Parameters.resourceId], + headerParameters: [Parameters.accept], + serializer +}; diff --git a/sdk/communication/communication-tiering/src/generated/src/operations/tiering.ts b/sdk/communication/communication-tiering/src/generated/src/operations/tiering.ts new file mode 100644 index 000000000000..e5b5702162be --- /dev/null +++ b/sdk/communication/communication-tiering/src/generated/src/operations/tiering.ts @@ -0,0 +1,71 @@ +/* + * 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. + */ + +import { tracingClient } from "../tracing"; +import { Tiering } from "../operationsInterfaces"; +import * as coreClient from "@azure/core-client"; +import * as Mappers from "../models/mappers"; +import * as Parameters from "../models/parameters"; +import { TieringClient } from "../tieringClient"; +import { + TieringGetByResourceIdOptionalParams, + TieringGetByResourceIdResponse +} from "../models"; + +/** Class containing Tiering operations. */ +export class TieringImpl implements Tiering { + private readonly client: TieringClient; + + /** + * Initialize a new instance of the class Tiering class. + * @param client Reference to the service client + */ + constructor(client: TieringClient) { + this.client = client; + } + + /** + * Get the tiering data for a given resource + * @param resourceId Resource Id. Must be a valid GUID + * @param options The options parameters. + */ + async getByResourceId( + resourceId: string, + options?: TieringGetByResourceIdOptionalParams + ): Promise { + return tracingClient.withSpan( + "TieringClient.getByResourceId", + options ?? {}, + async (options) => { + return this.client.sendOperationRequest( + { resourceId, options }, + getByResourceIdOperationSpec + ) as Promise; + } + ); + } +} +// Operation Specifications +const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); + +const getByResourceIdOperationSpec: coreClient.OperationSpec = { + path: "/administration/tiers/resources/{resourceId}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.AcsTier + }, + default: { + bodyMapper: Mappers.CommunicationErrorResponse + } + }, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint, Parameters.resourceId], + headerParameters: [Parameters.accept], + serializer +}; diff --git a/sdk/communication/communication-tiering/src/generated/src/operationsInterfaces/index.ts b/sdk/communication/communication-tiering/src/generated/src/operationsInterfaces/index.ts new file mode 100644 index 000000000000..6e187b6a22c2 --- /dev/null +++ b/sdk/communication/communication-tiering/src/generated/src/operationsInterfaces/index.ts @@ -0,0 +1,10 @@ +/* + * 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. + */ + +export * from "./numberAllotment"; +export * from "./tiering"; diff --git a/sdk/communication/communication-tiering/src/generated/src/operationsInterfaces/numberAllotment.ts b/sdk/communication/communication-tiering/src/generated/src/operationsInterfaces/numberAllotment.ts new file mode 100644 index 000000000000..a4928b1575e2 --- /dev/null +++ b/sdk/communication/communication-tiering/src/generated/src/operationsInterfaces/numberAllotment.ts @@ -0,0 +1,25 @@ +/* + * 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. + */ + +import { + NumberAllotmentGetAcquiredNumberLimitsOptionalParams, + NumberAllotmentGetAcquiredNumberLimitsResponse +} from "../models"; + +/** Interface representing a NumberAllotment. */ +export interface NumberAllotment { + /** + * Get acquired numbers and limits for a resource. + * @param resourceId Resource Id. Must be a valid GUID + * @param options The options parameters. + */ + getAcquiredNumberLimits( + resourceId: string, + options?: NumberAllotmentGetAcquiredNumberLimitsOptionalParams + ): Promise; +} diff --git a/sdk/communication/communication-tiering/src/generated/src/operationsInterfaces/tiering.ts b/sdk/communication/communication-tiering/src/generated/src/operationsInterfaces/tiering.ts new file mode 100644 index 000000000000..24f017e78404 --- /dev/null +++ b/sdk/communication/communication-tiering/src/generated/src/operationsInterfaces/tiering.ts @@ -0,0 +1,25 @@ +/* + * 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. + */ + +import { + TieringGetByResourceIdOptionalParams, + TieringGetByResourceIdResponse +} from "../models"; + +/** Interface representing a Tiering. */ +export interface Tiering { + /** + * Get the tiering data for a given resource + * @param resourceId Resource Id. Must be a valid GUID + * @param options The options parameters. + */ + getByResourceId( + resourceId: string, + options?: TieringGetByResourceIdOptionalParams + ): Promise; +} diff --git a/sdk/communication/communication-tiering/src/generated/src/tieringClient.ts b/sdk/communication/communication-tiering/src/generated/src/tieringClient.ts new file mode 100644 index 000000000000..98c89d356085 --- /dev/null +++ b/sdk/communication/communication-tiering/src/generated/src/tieringClient.ts @@ -0,0 +1,96 @@ +/* + * 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. + */ + +import * as coreClient from "@azure/core-client"; +import { + PipelineRequest, + PipelineResponse, + SendRequest +} from "@azure/core-rest-pipeline"; +import { NumberAllotmentImpl, TieringImpl } from "./operations"; +import { NumberAllotment, Tiering } from "./operationsInterfaces"; +import { TieringClientOptionalParams } from "./models"; + +export class TieringClient extends coreClient.ServiceClient { + endpoint: string; + apiVersion: string; + + /** + * Initializes a new instance of the TieringClient class. + * @param endpoint The communication resource, for example https://resourcename.communication.azure.com + * @param options The parameter options + */ + constructor(endpoint: string, options?: TieringClientOptionalParams) { + if (endpoint === undefined) { + throw new Error("'endpoint' cannot be null"); + } + + // Initializing default values for options + if (!options) { + options = {}; + } + const defaults: TieringClientOptionalParams = { + requestContentType: "application/json; charset=utf-8" + }; + + const packageDetails = `azsdk-js-communication-tiering/1.0.0-beta.1`; + const userAgentPrefix = + options.userAgentOptions && options.userAgentOptions.userAgentPrefix + ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}` + : `${packageDetails}`; + + const optionsWithDefaults = { + ...defaults, + ...options, + userAgentOptions: { + userAgentPrefix + }, + endpoint: options.endpoint ?? options.baseUri ?? "{endpoint}" + }; + super(optionsWithDefaults); + // Parameter assignments + this.endpoint = endpoint; + + // Assigning values to Constant parameters + this.apiVersion = options.apiVersion || "2023-06-15"; + this.numberAllotment = new NumberAllotmentImpl(this); + this.tiering = new TieringImpl(this); + this.addCustomApiVersionPolicy(options.apiVersion); + } + + /** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */ + private addCustomApiVersionPolicy(apiVersion?: string) { + if (!apiVersion) { + return; + } + const apiVersionPolicy = { + name: "CustomApiVersionPolicy", + async sendRequest( + request: PipelineRequest, + next: SendRequest + ): Promise { + const param = request.url.split("?"); + if (param.length > 1) { + const newParams = param[1].split("&").map((item) => { + if (item.indexOf("api-version") > -1) { + return "api-version=" + apiVersion; + } else { + return item; + } + }); + request.url = param[0] + "?" + newParams.join("&"); + } + return next(request); + } + }; + this.pipeline.addPolicy(apiVersionPolicy); + } + + numberAllotment: NumberAllotment; + tiering: Tiering; +} diff --git a/sdk/communication/communication-tiering/src/generated/src/tracing.ts b/sdk/communication/communication-tiering/src/generated/src/tracing.ts new file mode 100644 index 000000000000..74dd2864a8f4 --- /dev/null +++ b/sdk/communication/communication-tiering/src/generated/src/tracing.ts @@ -0,0 +1,15 @@ +/* + * 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. + */ + +import { createTracingClient } from "@azure/core-tracing"; + +export const tracingClient = createTracingClient({ + namespace: "Microsoft.Communication", + packageName: "@azure/communication-tiering", + packageVersion: "1.0.0-beta.1" +}); diff --git a/sdk/communication/communication-tiering/src/index.ts b/sdk/communication/communication-tiering/src/index.ts new file mode 100644 index 000000000000..05cc6140f07c --- /dev/null +++ b/sdk/communication/communication-tiering/src/index.ts @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +export * from "./models"; +export * from "./tieringClient"; diff --git a/sdk/communication/communication-tiering/src/models.ts b/sdk/communication/communication-tiering/src/models.ts new file mode 100644 index 000000000000..9efd727f5a8d --- /dev/null +++ b/sdk/communication/communication-tiering/src/models.ts @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +export { + NumberAllotmentGetAcquiredNumberLimitsOptionalParams, + NumberAllotmentGetAcquiredNumberLimitsResponse, + AssetDetails, + AssetDetailsTierInfo, + TieringClientOptionalParams, + AcsTier, + AcsTierCapabilities, + AcsTierCapabilitiesCalling, + AcsTierCapabilitiesSms, + TieringGetByResourceIdOptionalParams, + TieringGetByResourceIdResponse, + TrialPhoneNumberUsage, + TrialPhoneNumberPurchase, + TrialPhoneNumberUsageSms, + PhoneNumberPurchase, + SmsInbound, + SmsOutbound, + CallingInbound, + CallingOutbound, + TrialPhoneNumberUsageCalling, + TrialPhoneNumberUsageSmsBounds, + TrialPhoneNumberUsageCallingBounds, + Paths190FnhrAdministrationResourcesResourceidTelephoneNumberSummaryGetResponses200ContentApplicationJsonSchema as AssetDetailsModel, +} from "./generated/src/models"; diff --git a/sdk/communication/communication-tiering/src/tieringClient.ts b/sdk/communication/communication-tiering/src/tieringClient.ts new file mode 100644 index 000000000000..6aceeca7f7bb --- /dev/null +++ b/sdk/communication/communication-tiering/src/tieringClient.ts @@ -0,0 +1,117 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +/// + +import { + NumberAllotmentGetAcquiredNumberLimitsOptionalParams, + TieringGetByResourceIdOptionalParams, + AcsTier, + AssetDetailsModel, +} from "./models"; +import { CommonClientOptions, InternalClientPipelineOptions } from "@azure/core-client"; +import { KeyCredential, TokenCredential, isTokenCredential } from "@azure/core-auth"; +import { createCommunicationAuthPolicy } from "@azure/communication-common"; +import { isKeyCredential, parseClientArguments } from "@azure/communication-common"; +import { TieringClient as TieringGeneratedClient } from "./generated/src"; +import { logger } from "./utils"; +import { tracingClient } from "./generated/src/tracing"; + +/** + * Client options used to configure the TieringGeneratedClient API requests. + */ +export interface TieringClientOptions extends CommonClientOptions {} + +const isTieringClientOptions = (options: any): options is TieringClientOptions => + options && !isKeyCredential(options) && !isTokenCredential(options); + +/** + * Client class for interacting with Azure Communication Services Tiering. + */ +export class TieringClient { + /** + * A reference to the auto-generated TieringClient HTTP client. + */ + private readonly client: TieringGeneratedClient; + + /** + * Initializes a new instance of the TieringClient class using a connection string. + * + * @param connectionString - Connection string to connect to an Azure Communication Service resource. (eg: endpoint=https://contoso.eastus.communications.azure.net/;accesskey=secret) + * @param options - Optional. Options to configure the HTTP pipeline. + */ + public constructor(connectionString: string, options?: TieringClientOptions); + + /** + * Initializes a new instance of the TieringClient class using an Azure KeyCredential. + * + * @param endpoint - The endpoint of the service (eg: https://contoso.eastus.communications.azure.net) + * @param credential - An object that is used to authenticate requests to the service. Use the Azure KeyCredential or `@azure/identity` to create a credential. + * @param options - Optional. Options to configure the HTTP pipeline. + */ + public constructor(endpoint: string, credential: KeyCredential, options?: TieringClientOptions); + + /** + * Initializes a new instance of the TieringClient class using an Azure KeyCredential. + * + * @param endpoint - The endpoint of the service (eg: https://contoso.eastus.communications.azure.net) + * @param credential - An object that is used to authenticate requests to the service. Use the Azure KeyCredential or `@azure/identity` to create a credential. + * @param options - Optional. Options to configure the HTTP pipeline. + */ + public constructor(endpoint: string, credential: TokenCredential, options?: TieringClientOptions); + + public constructor( + connectionStringOrUrl: string, + credentialOrOptions?: KeyCredential | TokenCredential | TieringClientOptions, + maybeOptions: TieringClientOptions = {} + ) { + const { url, credential } = parseClientArguments(connectionStringOrUrl, credentialOrOptions); + const options = isTieringClientOptions(credentialOrOptions) + ? credentialOrOptions + : maybeOptions; + + const internalPipelineOptions: InternalClientPipelineOptions = { + ...options, + ...{ + loggingOptions: { + logger: logger.info, + }, + }, + }; + + this.client = new TieringGeneratedClient(url, internalPipelineOptions); + const authPolicy = createCommunicationAuthPolicy(credential); + this.client.pipeline.addPolicy(authPolicy); + } + + /** + * Get acquired numbers and limits for a resource. + * + * @param options - Additional request options. + */ + public getAcquiredNumberLimits( + resourceId: string, + options: NumberAllotmentGetAcquiredNumberLimitsOptionalParams = {} + ): Promise { + return tracingClient.withSpan( + "numberAllotment.getAcquiredNumberLimits", + options, + (updatedOptions) => { + return this.client.numberAllotment.getAcquiredNumberLimits(resourceId, updatedOptions); + } + ); + } + + /** + * Get tiering info for a resource. + * + * @param options - Additional request options. + */ + public getTierByResourceId( + resourceId: string, + options: TieringGetByResourceIdOptionalParams = {} + ): Promise { + return tracingClient.withSpan("tiering.getTierByResourceId", options, (updatedOptions) => { + return this.client.tiering.getByResourceId(resourceId, updatedOptions); + }); + } +} diff --git a/sdk/communication/communication-tiering/src/utils/constants.ts b/sdk/communication/communication-tiering/src/utils/constants.ts new file mode 100644 index 000000000000..cb3ec97d1326 --- /dev/null +++ b/sdk/communication/communication-tiering/src/utils/constants.ts @@ -0,0 +1,4 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +export const SDK_VERSION: string = "1.0.0-beta.0"; diff --git a/sdk/communication/communication-tiering/src/utils/index.ts b/sdk/communication/communication-tiering/src/utils/index.ts new file mode 100644 index 000000000000..996de929a1d3 --- /dev/null +++ b/sdk/communication/communication-tiering/src/utils/index.ts @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +export * from "./logger"; +export * from "./constants"; diff --git a/sdk/communication/communication-tiering/src/utils/logger.ts b/sdk/communication/communication-tiering/src/utils/logger.ts new file mode 100644 index 000000000000..91298ea93e50 --- /dev/null +++ b/sdk/communication/communication-tiering/src/utils/logger.ts @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { createClientLogger } from "@azure/logger"; + +/** + * The \@azure\/logger configuration for this package. + */ +export const logger = createClientLogger("communication-tiering"); diff --git a/sdk/communication/communication-tiering/swagger/README.md b/sdk/communication/communication-tiering/swagger/README.md new file mode 100644 index 000000000000..7dd5c0e82f73 --- /dev/null +++ b/sdk/communication/communication-tiering/swagger/README.md @@ -0,0 +1,50 @@ +# Azure Communication Services Tiering Module + +> see https://aka.ms/autorest + +## Configuration + +```yaml +package-name: "@azure/communication-tiering" +description: The tiering client library retrieves limits for each capability (SMS/PSTN Calling/Phone Number purchase) for a specific resource/tier. +package-version: 1.0.0-beta.1 +license-header: MICROSOFT_MIT_NO_VERSION +output-folder: ../src/generated +input-file: ./swagger.json +model-date-time-as-string: false +optional-response-headers: true +payload-flattening-threshold: 10 +add-credentials: false +skip-enum-validation: true +v3: true +title: Tiering Client +use-extension: + "@autorest/typescript": "6.0.0" +tracing-info: + namespace: "Microsoft.Communication" + packagePrefix: "Azure.Communication" + +typescript: + generate-metadata: false + azure-arm: false +``` + +## Customizations + +### Disable extensible enums + +```yaml +directive: + - from: swagger-document + where: $.definitions[*].properties[*]["x-ms-enum"] + transform: > + if ($.modelAsString) { + $.modelAsString = false + } + - from: swagger-document + where: $.definitions[*].properties[*].items["x-ms-enum"] + transform: > + if ($.modelAsString) { + $.modelAsString = false + } +``` diff --git a/sdk/communication/communication-tiering/swagger/swagger.json b/sdk/communication/communication-tiering/swagger/swagger.json new file mode 100644 index 000000000000..887b536f2614 --- /dev/null +++ b/sdk/communication/communication-tiering/swagger/swagger.json @@ -0,0 +1,562 @@ +{ + "swagger": "2.0", + "info": { + "title": "TieringClient", + "description": "The tiering client library retrieves limits for each capability (SMS/PSTN Calling/Phone Number purchase) for a specific resource/tier.", + "version": "2023-06-15" + }, + "paths": { + "/administration/resources/{resourceId}/telephone-number-summary": { + "get": { + "tags": [ + "ACS Tiering" + ], + "summary": "Get acquired numbers and limits for a resource.", + "operationId": "NumberAllotment_GetAcquiredNumberLimits", + "produces": [ + "application/json" + ], + "parameters": [ + { + "in": "path", + "name": "resourceId", + "description": "Resource Id. Must be a valid GUID", + "required": true, + "type": "string", + "format": "uuid" + }, + { + "$ref": "#/parameters/ApiVersionParameter" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "object", + "properties": { + "assetDetails": { + "description": "AssetDetails Array", + "type": "array", + "items": { + "$ref": "#/definitions/assetDetails" + } + } + }, + "required":["assetDetails"] + } + }, + "default": { + "description": "Failure", + "schema": { + "$ref": "#/definitions/CommunicationErrorResponse" + } + } + }, + "x-ms-examples": { + "Get acquired numbers and limits for a resource": { + "$ref": "./examples/GetAcquiredNumberLimits.json" + } + } + } + }, + "/administration/tiers/resources/{resourceId}": { + "get": { + "tags": [ + "ACS Tiering" + ], + "summary": " Get the tiering data for a given resource", + "operationId": "Tiering_GetByResourceId", + "produces": [ + "application/json" + ], + "parameters": [ + { + "in": "path", + "name": "resourceId", + "description": "Resource Id. Must be a valid GUID", + "required": true, + "type": "string", + "format": "uuid" + }, + { + "$ref": "#/parameters/ApiVersionParameter" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "$ref": "#/definitions/acsTier" + } + }, + "default": { + "description": "Failure", + "schema": { + "$ref": "#/definitions/CommunicationErrorResponse" + } + } + }, + "x-ms-examples": { + "Get tier info for a resource": { + "$ref": "./examples/GetTierInfo.json" + } + } + } + } + }, + "definitions": { + "assetDetails": { + "description": "Model response for acquired number and limits.", + "type": "object", + "properties": { + "numberType": { + "description": "Array defining the number type of the phone number.", + "type": "array", + "items": { + "type": "string" + } + }, + "resourceAcquiredCount": { + "description": "Number of phone numbers that the resource has.", + "type": "integer" + }, + "subscriptionAcquiredCount": { + "description": "Number of phone numbers that the subscription that the resource belongs to has.", + "type": "integer" + }, + "aadTenantAcquiredCount": { + "description": "Number of phone numbers that the AAD tenant that the resource belongs to has.", + "type": "integer" + }, + "tierInfo": { + "description": "Tier specific info.", + "type": "object", + "properties": { + "scope": { + "description": "The level at which the tiering properties in the TierInfo are for", + "type": "string" + }, + "allowed": { + "description": "Number of phone numbers allowed that can change based on scope where scope can be (resource, subscription or tenant).", + "type": "integer" + }, + "acquired": { + "description": "Number of phone numbers acquired that can change based on scope where scope can be (resource, subscription or tenant).", + "type": "integer" + }, + "balance": { + "description": "Difference between allowed and acquired amount.", + "type": "integer" + }, + "limit": { + "description": "The standing of a customer to determine if they able to purchase more phone numbers.", + "type": "string" + } + } + } + } + }, + "acsTier": { + "description": "Represents an ACS Tier resource.", + "type": "object", + "properties": { + "tierId": { + "description": "Tier Id.", + "type": "string" + }, + "tierType": { + "description": "Tier Type", + "type": "string" + }, + "capabilities": { + "description": "Capabilities for the resource", + "type": "object", + "properties": { + "phoneNumberPurchase": { + "description": "Phone number purchase capabilities of the tier.", + "type": "array", + "items": { + "$ref": "#/definitions/phoneNumberPurchase" + } + }, + "sms": { + "description": "SMS capabilities of the tier.", + "type": "object", + "properties": { + "outbound": { + "description": "SMS Outbound capabilities of the tier.", + "type": "array", + "items": { + "$ref": "#/definitions/smsOutbound" + } + }, + "inbound": { + "description": "SMS Inbound capabilities of the tier.", + "type": "array", + "items": { + "$ref": "#/definitions/smsInbound" + } + } + } + }, + "calling": { + "description": "Calling capabilities of the tier.", + "type": "object", + "properties": { + "outbound": { + "description": "Calling Outbound capabilities of the tier.", + "type": "array", + "items": { + "$ref": "#/definitions/callingOutbound" + } + }, + "inbound": { + "description": "Calling Inbound capabilities of the tier.", + "type": "array", + "items": { + "$ref": "#/definitions/callingInbound" + } + } + } + }, + "trialPhoneNumberPurchase": { + "description": "Trial phone number purchase capability details.", + "type": "array", + "items": { + "$ref": "#/definitions/trialPhoneNumberPurchase" + } + }, + "trialPhoneNumberUsage": { + "description": "Trial phone number usage of the tier.", + "type": "array", + "items": { + "$ref": "#/definitions/trialPhoneNumberUsage" + } + } + } + } + } + }, + "phoneNumberPurchase":{ + "description": "Phone number purchase capability details.", + "type":"object", + "properties": { + "numberType": { + "description": "Types to apply the limit to.", + "type": "array", + "items": { + "type": "string" + } + }, + "scope": { + "description": "The scope to apply the limits.", + "type": "string" + }, + "totalNumbers": { + "description": "The limit of numbers allowed for purchase for the number type.", + "type": "integer" + } + } + }, + "smsOutbound":{ + "description": "Sms Outbound Capabilities for the tier.", + "type":"object", + "properties": { + "type": { + "description": "Type of number.", + "type": "string" + }, + "scope": { + "description": "The scope to apply the limits.", + "type": "string" + }, + "smsPerMin": { + "description": "The limit of SMSs a customer can send per minute.", + "type": "integer" + }, + "geographicLimitations": { + "description": "The areas where an SMS is allowed to be sent.", + "type": "string" + } + } + }, + "smsInbound":{ + "description": "Sms Inbound Capabilities for the tier.", + "type":"object", + "properties": { + "type": { + "description": "Type of number.", + "type": "string" + }, + "scope": { + "description": "The scope to apply the limits.", + "type": "string" + }, + "smsPerMin": { + "description": "The limit of SMSs a customer can send per minute.", + "type": "integer" + }, + "geographicLimitations": { + "description": "The areas where an SMS is allowed to be sent.", + "type": "string" + } + } + }, + "callingOutbound":{ + "description": "Calling Outbound Capabilities for the tier.", + "type":"object", + "properties": { + "type": { + "description": "Type of calling.", + "type": "string" + }, + "scope": { + "description": "The scope to apply the limits.", + "type": "string" + }, + "concurrentCalls": { + "description": "The number of concurrent calls allowed.", + "type": "integer" + }, + "geographicLimitations": { + "description": "The areas where calls are allowed to take place.", + "type": "string" + } + } + }, + "callingInbound":{ + "description": "Calling Outbound Capabilities for the tier.", + "type":"object", + "properties": { + "type": { + "description": "Type of calling.", + "type": "string" + }, + "scope": { + "description": "The scope to apply the limits.", + "type": "string" + }, + "concurrentCalls": { + "description": "The number of concurrent calls allowed.", + "type": "integer" + }, + "geographicLimitations": { + "description": "The areas where calls are allowed to take place.", + "type": "string" + } + } + }, + "trialPhoneNumberUsageCallingBounds":{ + "description": "Trial phone number capability details.", + "type":"object", + "properties": { + "type": { + "description": " Type of calling.", + "type": "string" + }, + "scope": { + "description": "The scope to apply the limits to.", + "type": "string" + }, + "totalMinutes": { + "description": "The total calling minutes allowed for a tial number.", + "type": "integer" + }, + "maximumCallDurationMinutes": { + "description": "The total call duration in minutes allowed for a trial number.", + "type": "integer" + }, + "concurrentCalls": { + "description": "The number of concurrent calls allowed.", + "type": "integer" + } + } + }, + "trialPhoneNumberUsageSmsBounds":{ + "description": "Trial phone number SMS capability details.", + "type":"object", + "properties": { + "type": { + "description": "The type of SMS.", + "type": "string" + }, + "scope": { + "description": "The scope to apply the limits to.", + "type": "string" + }, + "total": { + "description": "Total", + "type": "integer" + }, + "smsPerMin": { + "description": "The total SMSs allowed to be sent in a minute.", + "type": "integer" + } + } + }, + "trialPhoneNumberPurchase":{ + "description": "Trial phone number purchase capability details.", + "type":"object", + "properties": { + "numberType": { + "description": "Types to apply the limit to.", + "type": "array", + "items": { + "type": "string" + } + }, + "scope": { + "description": "The scope to apply the limits.", + "type": "string" + }, + "totalNumbers": { + "description": "The limit of numbers allowed for purchase for the number type.", + "type": "integer" + }, + "trialPeriodDays": { + "description": "The number of days in the trial period for the number type.", + "type": "integer" + } + } + }, + "trialPhoneNumberUsage":{ + "description": "Trial phone number usage capability details.", + "type":"object", + "properties": { + "numberType": { + "description": "The number type.", + "type": "string" + }, + "calling": { + "description": "The capabilities for calling.", + "type": "object", + "properties": { + "outbound": { + "description": "The Outbound capabilities for calling.", + "type": "array", + "items": { + "$ref": "#/definitions/trialPhoneNumberUsageCallingBounds" + } + }, + "inbound": { + "description": "The Inbound capabilities for calling.", + "type": "array", + "items": { + "$ref": "#/definitions/trialPhoneNumberUsageCallingBounds" + } + } + } + }, + "sms": { + "description": "The SMS capabilities for the trial phone number.", + "type": "object", + "properties": { + "outbound": { + "description": "Outbound trial phone number SMS capabilities.", + "type": "array", + "items": { + "$ref": "#/definitions/trialPhoneNumberUsageSmsBounds" + } + }, + "inbound": { + "description": "Inbound trial phone number SMS capabilities.", + "type": "array", + "items": { + "$ref": "#/definitions/trialPhoneNumberUsageSmsBounds" + } + } + } + } + } + }, + "CommunicationErrorResponse": { + "description": "The Communication Services error.", + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "description": "The Communication Services error.", + "$ref": "#/definitions/CommunicationError" + } + } + }, + "CommunicationError": { + "description": "The Communication Services error.", + "type": "object", + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "string", + "description": "The error code." + }, + "message": { + "type": "string", + "description": "The error message." + }, + "target": { + "type": "string", + "readOnly": true, + "description": "The error target." + }, + "details": { + "type": "array", + "items": { + "$ref": "#/definitions/CommunicationError" + }, + "readOnly": true, + "description": "Further details about specific errors that led to this error." + }, + "innererror": { + "x-ms-client-name": "innerError", + "readOnly": true, + "$ref": "#/definitions/CommunicationError", + "description": "The inner error if any." + } + } + } + }, + "parameters": { + "ApiVersionParameter": { + "in": "query", + "name": "api-version", + "description": "Version of API to invoke", + "required": true, + "type": "string" + }, + "Endpoint": { + "in": "path", + "name": "endpoint", + "description": "The communication resource, for example https://resourcename.communication.azure.com", + "required": true, + "type": "string", + "x-ms-skip-url-encoding": true, + "x-ms-parameter-location": "client" + } + }, + "securityDefinitions": { + "azure_auth": { + "type": "oauth2", + "flow": "implicit", + "authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize", + "scopes": { + "user_impersonation": "impersonate your user account" + }, + "description": "Azure Active Directory OAuth2 Flow" + } + }, + "x-ms-parameterized-host": { + "hostTemplate": "{endpoint}", + "useSchemePrefix": false, + "parameters": [ + { + "$ref": "#/parameters/Endpoint" + } + ] + } +} diff --git a/sdk/communication/communication-tiering/test/public/ctor.spec.ts b/sdk/communication/communication-tiering/test/public/ctor.spec.ts new file mode 100644 index 000000000000..6e991b3071f6 --- /dev/null +++ b/sdk/communication/communication-tiering/test/public/ctor.spec.ts @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import { Context } from "mocha"; +import { TieringClient } from "../../src"; +import { assert } from "chai"; +import { createMockToken } from "./utils/recordedClient"; + +describe("RecipientVerificationClient - constructor", function () { + const endpoint = "https://contoso.spool.azure.local"; + const accessKey = "banana"; + + it("successfully instantiates with valid connection string", function () { + const client = new TieringClient(`endpoint=${endpoint};accesskey=${accessKey}`); + assert.instanceOf(client, TieringClient); + }); + + it("throws with invalid connection string", function () { + assert.throws(() => { + new TieringClient(`endpoints=${endpoint};accesskey=${accessKey}`); + }); + }); + + it("successfully instantiates with with endpoint and access key", function () { + const client = new TieringClient(endpoint, new AzureKeyCredential(accessKey)); + assert.instanceOf(client, TieringClient); + }); + + it("successfully instantiates with with endpoint and managed identity", function (this: Context) { + const client = new TieringClient(endpoint, createMockToken()); + assert.instanceOf(client, TieringClient); + }); +}); diff --git a/sdk/communication/communication-tiering/test/public/getAcquiredNumberLimit.spec.ts b/sdk/communication/communication-tiering/test/public/getAcquiredNumberLimit.spec.ts new file mode 100644 index 000000000000..7be84e3eaa38 --- /dev/null +++ b/sdk/communication/communication-tiering/test/public/getAcquiredNumberLimit.spec.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { Context } from "mocha"; +import { Recorder, env } from "@azure-tools/test-recorder"; +import { TieringClient } from "../../src"; +import { assert } from "chai"; +import { createRecordedClient } from "./utils/recordedClient"; + +describe(`TieringClient - Get Acquired Number Limits`, function () { + let recorder: Recorder; + let client: TieringClient; + + beforeEach(async function (this: Context) { + ({ client, recorder } = await createRecordedClient(this)); + }); + + afterEach(async function (this: Context) { + if (!this.currentTest?.isPending()) { + await recorder.stop(); + } + }); + + it("get acquired number limits", async function () { + // print all acquire number limits + const resourceId = env.RESOURCE_ID!; + const acquiredNumberLimits = await client.getAcquiredNumberLimits(resourceId); + assert.isNotNull(acquiredNumberLimits); + }).timeout(10000); +}); diff --git a/sdk/communication/communication-tiering/test/public/getTierInfo.spec.ts b/sdk/communication/communication-tiering/test/public/getTierInfo.spec.ts new file mode 100644 index 000000000000..c2958bdbcf75 --- /dev/null +++ b/sdk/communication/communication-tiering/test/public/getTierInfo.spec.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { Context } from "mocha"; +import { Recorder, env } from "@azure-tools/test-recorder"; +import { TieringClient } from "../../src"; +import { assert } from "chai"; +import { createRecordedClient } from "./utils/recordedClient"; + +describe(`TieringClient - Get Tier Info`, function () { + let recorder: Recorder; + let client: TieringClient; + + beforeEach(async function (this: Context) { + ({ client, recorder } = await createRecordedClient(this)); + }); + + afterEach(async function (this: Context) { + if (!this.currentTest?.isPending()) { + await recorder.stop(); + } + }); + + it("get tier info", async function () { + // print all tier info + const resourceId = env.RESOURCE_ID!; + const tierInfo = await client.getTierByResourceId(resourceId); + assert.isNotNull(tierInfo); + }).timeout(10000); +}); diff --git a/sdk/communication/communication-tiering/test/public/utils/recordedClient.ts b/sdk/communication/communication-tiering/test/public/utils/recordedClient.ts new file mode 100644 index 000000000000..4860bde55b9b --- /dev/null +++ b/sdk/communication/communication-tiering/test/public/utils/recordedClient.ts @@ -0,0 +1,126 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +import * as dotenv from "dotenv"; + +import { ClientSecretCredential, DefaultAzureCredential, TokenCredential } from "@azure/identity"; +import { + Recorder, + RecorderStartOptions, + assertEnvironmentVariable, + env, + isPlaybackMode, +} from "@azure-tools/test-recorder"; +import { Context } from "mocha"; +import { TieringClient } from "../../../src"; +import { isNode } from "@azure/test-utils"; +import { parseConnectionString } from "@azure/communication-common"; + +if (isNode) { + dotenv.config(); +} + +export interface RecordedClient { + client: T; + recorder: Recorder; +} + +const envSetupForPlayback: { [k: string]: string } = { + COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING: "endpoint=https://endpoint/;accesskey=banana", + AZURE_CLIENT_ID: "SomeClientId", + AZURE_CLIENT_SECRET: "azure_client_secret", + AZURE_TENANT_ID: "SomeTenantId", + RESOURCE_ID: "9d787bd6-07fc-4c7b-8e57-17f1fee41298" +}; + +export const recorderOptions: RecorderStartOptions = { + envSetupForPlayback, + sanitizerOptions: { + connectionStringSanitizers: [ + { + actualConnString: env.COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING, + fakeConnString: envSetupForPlayback["COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING"], + }, + ], + generalSanitizers: [ + { + regex: true, + target: `[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}`, + value: "9d787bd6-07fc-4c7b-8e57-17f1fee41298", + }, + ], + }, +}; + +export async function createRecordedClient( + context: Context +): Promise> { + const recorder = new Recorder(context.currentTest); + await recorder.start(recorderOptions); + await recorder.setMatcher("CustomDefaultMatcher", { + excludedHeaders: [ + "Accept-Language", // This is env-dependent + "x-ms-content-sha256", // This is dependent on the current datetime + ], + }); + + // casting is a workaround to enable min-max testing + return { + client: new TieringClient( + assertEnvironmentVariable("COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING"), + recorder.configureClientOptions({}) + ), + recorder, + }; +} + +export function createMockToken(): { + getToken: (_scopes: string) => Promise<{ token: string; expiresOnTimestamp: number }>; +} { + return { + getToken: async (_scopes: string) => { + return { token: "testToken", expiresOnTimestamp: 11111 }; + }, + }; +} + +export async function createRecordedClientWithToken( + context: Context +): Promise | undefined> { + const recorder = new Recorder(context.currentTest); + await recorder.start(recorderOptions); + + let credential: TokenCredential; + const endpoint = parseConnectionString( + assertEnvironmentVariable("COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING") + ).endpoint; + + if (isPlaybackMode()) { + credential = createMockToken(); + + // casting is a workaround to enable min-max testing + return { + client: new TieringClient(endpoint, credential, recorder.configureClientOptions({})), + recorder, + }; + } + + if (isNode) { + credential = new DefaultAzureCredential(); + } else { + credential = new ClientSecretCredential( + assertEnvironmentVariable("AZURE_TENANT_ID"), + assertEnvironmentVariable("AZURE_CLIENT_ID"), + assertEnvironmentVariable("AZURE_CLIENT_SECRET") + ); + } + + // casting is a workaround to enable min-max testing + return { + client: new TieringClient(endpoint, credential, recorder.configureClientOptions({})), + recorder, + }; +} + +export const testPollerOptions = { + pollInterval: isPlaybackMode() ? 0 : undefined, +}; diff --git a/sdk/communication/communication-tiering/tests.yml b/sdk/communication/communication-tiering/tests.yml new file mode 100644 index 000000000000..9a0f31550477 --- /dev/null +++ b/sdk/communication/communication-tiering/tests.yml @@ -0,0 +1,22 @@ +trigger: none + +stages: + - template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml + parameters: + PackageName: "@azure-tools/communication-tiering" + ServiceDirectory: communication + CloudConfig: + Public: + SubscriptionConfigurations: + - $(sub-config-azure-cloud-test-resources) + - $(sub-config-communication-services-cloud-test-resources-common) + - $(sub-config-communication-services-cloud-test-resources-js) + Int: + SubscriptionConfigurations: + - $(sub-config-communication-int-test-resources-common) + - $(sub-config-communication-int-test-resources-js) + MatrixFilters: + - TestType=^(?!(browser|sample)).* + Clouds: Public,Int + TestResourceDirectories: + - communication/test-resources/ diff --git a/sdk/communication/communication-tiering/tsconfig.json b/sdk/communication/communication-tiering/tsconfig.json new file mode 100644 index 000000000000..0c646b07da44 --- /dev/null +++ b/sdk/communication/communication-tiering/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../../tsconfig.package", + "compilerOptions": { + "outDir": "./dist-esm", + "declarationDir": "./types", + "paths": { + "@azure-tools/communication-tiering": ["./src/index"] + } + }, + "include": ["src/**/*.ts", "test/**/*.ts", "samples-dev/**/*.ts"] +}