diff --git a/.scripts/automation_generate.sh b/.scripts/automation_generate.sh index 789f6f9a53b2..9e838ef0d214 100644 --- a/.scripts/automation_generate.sh +++ b/.scripts/automation_generate.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -code-gen-pipeline --inputJsonPath=$1 --outputJsonPath=$2 --use=@autorest/typescript@6.0.0-rc.2 +code-gen-pipeline --inputJsonPath=$1 --outputJsonPath=$2 --use=@autorest/typescript@6.0.0-rc.2 --cadlEmitter=@azure-tools/cadl-typescript diff --git a/.scripts/automation_init.sh b/.scripts/automation_init.sh index 914705cf72a0..5097275e0f8b 100644 --- a/.scripts/automation_init.sh +++ b/.scripts/automation_init.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash npm install -g @microsoft/rush@5.75.0 -npm install -g @azure-tools/js-sdk-release-tools +npm install -g azure-tools-js-sdk-release-tools diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 5e2a03b46900..7a49b5b1c90f 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -220,6 +220,7 @@ specifiers: '@rush-temp/communication-short-codes': file:./projects/communication-short-codes.tgz '@rush-temp/communication-sms': file:./projects/communication-sms.tgz '@rush-temp/confidential-ledger': file:./projects/confidential-ledger.tgz + '@rush-temp/confidentialledger-test': file:./projects/confidentialledger-test.tgz '@rush-temp/container-registry': file:./projects/container-registry.tgz '@rush-temp/core-amqp': file:./projects/core-amqp.tgz '@rush-temp/core-auth': file:./projects/core-auth.tgz @@ -541,6 +542,7 @@ dependencies: '@rush-temp/communication-short-codes': file:projects/communication-short-codes.tgz '@rush-temp/communication-sms': file:projects/communication-sms.tgz '@rush-temp/confidential-ledger': file:projects/confidential-ledger.tgz + '@rush-temp/confidentialledger-test': file:projects/confidentialledger-test.tgz '@rush-temp/container-registry': file:projects/container-registry.tgz '@rush-temp/core-amqp': file:projects/core-amqp.tgz '@rush-temp/core-auth': file:projects/core-auth.tgz @@ -4132,7 +4134,7 @@ packages: dependencies: semver: 7.3.7 shelljs: 0.8.5 - typescript: 4.9.0-dev.20221025 + typescript: 5.0.0-dev.20221103 dev: false /downlevel-dts/0.8.0: @@ -9209,8 +9211,8 @@ packages: hasBin: true dev: false - /typescript/4.9.0-dev.20221025: - resolution: {integrity: sha512-3TZlt+3jGBjPRVFcNX6BmlajqwNExRm4rhG4llSH5WSMX/eQ54PSueTJ5UhLn9+6/byL31/WRmJJ/7W0j+gCtQ==} + /typescript/5.0.0-dev.20221103: + resolution: {integrity: sha512-hfqcsmiJ+5ktli1OAkwu4PyDDJ3kWW3tiUofd2t1uxwmni3ZT3Mrv1m2dZFg9VNDKqHrkt49izB3tAtD2bsyGw==} engines: {node: '>=4.2.0'} hasBin: true dev: false @@ -16461,6 +16463,50 @@ packages: - utf-8-validate dev: false + file:projects/confidentialledger-test.tgz: + resolution: {integrity: sha512-uMr1b47NtPuR3q5F9jj7TBnE03OZeoaCDYObhEz7Mh/d+Wc2MZSBszGZdFWTXNJ/IsyoOZ6nJKi1TqtXbryTWA==, tarball: file:projects/confidentialledger-test.tgz} + name: '@rush-temp/confidentialledger-test' + version: 0.0.0 + dependencies: + '@azure-rest/core-client': 1.0.0-beta.10 + '@azure/identity': 2.1.0 + '@microsoft/api-extractor': 7.31.2 + '@types/chai': 4.3.1 + '@types/mocha': 7.0.2 + '@types/node': 14.18.32 + autorest: 3.6.2 + chai: 4.3.6 + cross-env: 7.0.3 + dotenv: 8.6.0 + eslint: 8.20.0 + karma: 6.4.0 + karma-chrome-launcher: 3.1.1 + karma-coverage: 2.2.0 + karma-edge-launcher: 0.4.2_karma@6.4.0 + karma-env-preprocessor: 0.1.1 + karma-firefox-launcher: 1.3.0 + karma-ie-launcher: 1.0.0_karma@6.4.0 + karma-junit-reporter: 2.0.1_karma@6.4.0 + karma-mocha: 2.0.1 + karma-mocha-reporter: 2.2.5_karma@6.4.0 + karma-source-map-support: 1.4.0 + karma-sourcemap-loader: 0.3.8 + mkdirp: 1.0.4 + mocha: 7.2.0 + mocha-junit-reporter: 1.23.3_mocha@7.2.0 + nyc: 14.1.1 + prettier: 2.2.1 + rimraf: 3.0.2 + source-map-support: 0.5.21 + tslib: 2.4.0 + typescript: 4.6.4 + transitivePeerDependencies: + - bufferutil + - debug + - supports-color + - utf-8-validate + dev: false + file:projects/container-registry.tgz: resolution: {integrity: sha512-N51gV3rlyAoO0ave5nPXZt0QtbH2RHQwCQpA/RKl3+HyOTWCT+2tMl3P3t6EI85fR5f7npqkfesGtxH0KKPJKg==, tarball: file:projects/container-registry.tgz} name: '@rush-temp/container-registry' diff --git a/rush.json b/rush.json index df99897f671b..a2257aaebea9 100644 --- a/rush.json +++ b/rush.json @@ -1,7 +1,7 @@ /** * This is the main configuration file for Rush. * For full documentation, please see https://rushjs.io - */ { + */{ "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush.schema.json", /** * (Required) This specifies the version of the Rush engine to be used in this repo. @@ -1915,6 +1915,11 @@ "packageName": "@azure/arm-elasticsan", "projectFolder": "sdk/elasticsans/arm-elasticsan", "versionPolicyName": "management" + }, + { + "packageName": "@azure-rest/confidentialledger-test", + "projectFolder": "sdk/confidentialledger/azure-confidentialledger-rest", + "versionPolicyName": "client" } ] -} +} \ No newline at end of file diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/.eslintrc.json b/sdk/confidentialledger/azure-confidentialledger-rest/.eslintrc.json new file mode 100644 index 000000000000..619797ac39b6 --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/.eslintrc.json @@ -0,0 +1,11 @@ +{ + "plugins": ["@azure/azure-sdk"], + "extends": ["plugin:@azure/azure-sdk/azure-sdk-base"], + "rules": { + "@azure/azure-sdk/ts-modules-only-named": "warn", + "@azure/azure-sdk/ts-apiextractor-json-types": "warn", + "@azure/azure-sdk/ts-package-json-types": "warn", + "@azure/azure-sdk/ts-package-json-engine-is-present": "warn", + "tsdoc/syntax": "warn" + } +} diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/CHANGELOG.md b/sdk/confidentialledger/azure-confidentialledger-rest/CHANGELOG.md new file mode 100644 index 000000000000..6f9b39c5577b --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0-beta.1 (2022-11-04) + + - Initial Release diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/README.md b/sdk/confidentialledger/azure-confidentialledger-rest/README.md new file mode 100644 index 000000000000..bf4927d6c00d --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/README.md @@ -0,0 +1,57 @@ +# Azure Confidential Ledger REST client library for JavaScript + +Cadl Test Service + +**Please rely heavily on our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library** + +Key links: + +- [Package (NPM)](https://www.npmjs.com/package/@azure-rest/confidentialledger-test) +- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure-rest/confidentialledger-test?view=azure-node-preview) + +## Getting started + +### Currently supported environments + +- LTS versions of Node.js + +### Prerequisites + +- You must have an [Azure subscription](https://azure.microsoft.com/free/) to use this package. + +### Install the `@azure-rest/confidentialledger-test` package + +Install the Azure Confidential Ledger REST client REST client library for JavaScript with `npm`: + +```bash +npm install @azure-rest/confidentialledger-test +``` + +### Create and authenticate a `ConfidentialLedgerServiceClient` + +To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token), +provide an instance of the desired credential type obtained from the +[@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library. + +To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity) + +After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use. +As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential) +can be used to authenticate the client. + +Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: +AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET + +## Troubleshooting + +### Logging + +Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`: + +```javascript +const { setLogLevel } = require("@azure/logger"); + +setLogLevel("info"); +``` + +For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger). diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/api-extractor.json b/sdk/confidentialledger/azure-confidentialledger-rest/api-extractor.json new file mode 100644 index 000000000000..b395712b12f9 --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/api-extractor.json @@ -0,0 +1,31 @@ +{ + "$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/confidentialledger-test.d.ts" + }, + "messages": { + "tsdocMessageReporting": { + "default": { + "logLevel": "none" + } + }, + "extractorMessageReporting": { + "ae-missing-release-tag": { + "logLevel": "none" + }, + "ae-unresolved-link": { + "logLevel": "none" + } + } + } +} \ No newline at end of file diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/karma.conf.js b/sdk/confidentialledger/azure-confidentialledger-rest/karma.conf.js new file mode 100644 index 000000000000..49810149b85c --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/karma.conf.js @@ -0,0 +1,131 @@ +// 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: ["source-map-support", "mocha"], + + plugins: [ + "karma-mocha", + "karma-mocha-reporter", + "karma-chrome-launcher", + "karma-edge-launcher", + "karma-firefox-launcher", + "karma-ie-launcher", + "karma-env-preprocessor", + "karma-coverage", + "karma-sourcemap-loader", + "karma-junit-reporter", + "karma-source-map-support", + ], + + // list of files / patterns to load in the browser + files: [ + "dist-test/index.browser.js", + { + pattern: "dist-test/index.browser.js.map", + type: "html", + included: false, + served: true, + }, + ], + + // 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.js": ["coverage"] + }, + + envPreprocessor: [ + "TEST_MODE", + "ENDPOINT", + "AZURE_CLIENT_SECRET", + "AZURE_CLIENT_ID", + "AZURE_TENANT_ID", + "SUBSCRIPTION_ID", + ], + + // 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, + + // --no-sandbox allows our tests to run in Linux without having to change the system. + // --disable-web-security allows us to authenticate from the browser without having to write tests using interactive auth, which would be far more complex. + browsers: ["ChromeHeadlessNoSandbox"], + customLaunchers: { + ChromeHeadlessNoSandbox: { + base: "ChromeHeadless", + flags: ["--no-sandbox", "--disable-web-security"], + }, + }, + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: 1, + + browserNoActivityTimeout: 60000000, + browserDisconnectTimeout: 10000, + browserDisconnectTolerance: 3, + + client: { + mocha: { + // change Karma's debug.html to the mocha web reporter + reporter: "html", + timeout: "600000", + }, + }, + }); +}; diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/package.json b/sdk/confidentialledger/azure-confidentialledger-rest/package.json new file mode 100644 index 000000000000..90e0aef24a6a --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/package.json @@ -0,0 +1,118 @@ +{ + "name": "@azure-rest/confidentialledger-test", + "sdk-type": "client", + "author": "Microsoft Corporation", + "version": "1.0.0-beta.1", + "description": "Cadl Test Service", + "keywords": [ + "node", + "azure", + "cloud", + "typescript", + "browser", + "isomorphic" + ], + "license": "MIT", + "main": "dist/index.js", + "module": "./dist-esm/src/index.js", + "types": "./types/confidentialledger-test.d.ts", + "repository": "github:Azure/azure-sdk-for-js", + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "files": [ + "dist/", + "dist-esm/src/", + "types/confidentialledger-test.d.ts", + "README.md", + "LICENSE", + "review/*" + ], + "engines": { + "node": ">=14.0.0" + }, + "scripts": { + "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", + "build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", + "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", + "build:samples": "echo skipped.", + "build:test": "tsc -p . && dev-tool run bundle", + "build:debug": "tsc -p . && dev-tool run bundle && api-extractor run --local", + "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", + "clean": "rimraf dist dist-browser dist-esm test-dist temp types *.tgz *.log", + "execute:samples": "echo skipped", + "extract-api": "rimraf review && mkdirp ./review && api-extractor run --local", + "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", + "generate:client": "autorest --typescript swagger/README.md && npm run format", + "integration-test:browser": "dev-tool run test:browser", + "integration-test:node": "dev-tool run test:node-js-input -- --timeout 5000000 'dist-esm/test/**/*.spec.js'", + "integration-test": "npm run integration-test:node && npm run integration-test:browser", + "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]", + "lint": "eslint package.json api-extractor.json src test --ext .ts", + "pack": "npm pack 2>&1", + "test:browser": "npm run clean && npm run build:test && npm run unit-test:browser", + "test:node": "npm run clean && npm run build:test && npm run unit-test:node", + "test": "npm run clean && npm run build:test && npm run unit-test", + "unit-test": "npm run unit-test:node && npm run unit-test:browser", + "unit-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/*.spec.ts'", + "unit-test:browser": "dev-tool run test:browser", + "build": "npm run clean && tsc -p . && dev-tool run bundle && mkdirp ./review && api-extractor run --local" + }, + "sideEffects": false, + "autoPublish": false, + "dependencies": { + "@azure/core-auth": "^1.3.0", + "@azure-rest/core-client": "1.0.0-beta.10", + "@azure/core-rest-pipeline": "^1.8.0", + "@azure/logger": "^1.0.0", + "tslib": "^2.2.0", + "@azure/core-paging": "^1.2.0" + }, + "devDependencies": { + "@microsoft/api-extractor": "^7.31.1", + "autorest": "latest", + "@types/node": "^14.0.0", + "dotenv": "^8.2.0", + "eslint": "^8.0.0", + "mkdirp": "^1.0.4", + "prettier": "2.2.1", + "rimraf": "^3.0.0", + "source-map-support": "^0.5.9", + "typescript": "~4.6.0", + "@azure/dev-tool": "^1.0.0", + "@azure/eslint-plugin-azure-sdk": "^3.0.0", + "@azure-tools/test-credential": "^1.0.0", + "@azure/identity": "^2.0.1", + "@azure-tools/test-recorder": "^2.0.0", + "mocha": "^7.1.1", + "@types/mocha": "^7.0.2", + "mocha-junit-reporter": "^1.18.0", + "cross-env": "^7.0.2", + "@types/chai": "^4.2.8", + "chai": "^4.2.0", + "karma-chrome-launcher": "^3.0.0", + "karma-coverage": "^2.0.0", + "karma-edge-launcher": "^0.4.2", + "karma-env-preprocessor": "^0.1.1", + "karma-firefox-launcher": "^1.1.0", + "karma-ie-launcher": "^1.0.0", + "karma-junit-reporter": "^2.0.1", + "karma-mocha-reporter": "^2.2.5", + "karma-mocha": "^2.0.1", + "karma-source-map-support": "~1.4.0", + "karma-sourcemap-loader": "^0.3.8", + "karma": "^6.2.0", + "nyc": "^14.0.0" + }, + "//metadata": { + "constantPaths": [ + { + "path": "swagger/README.md", + "prefix": "package-version" + } + ] + }, + "browser": { + "./dist-esm/test/public/utils/env.js": "./dist-esm/test/public/utils/env.browser.js" + } +} \ No newline at end of file diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/review/confidentialledger-test.api.md b/sdk/confidentialledger/azure-confidentialledger-rest/review/confidentialledger-test.api.md new file mode 100644 index 000000000000..5763c00a9a3e --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/review/confidentialledger-test.api.md @@ -0,0 +1,563 @@ +## API Report File for "@azure-rest/confidentialledger-test" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import { Client } from '@azure-rest/core-client'; +import { ClientOptions } from '@azure-rest/core-client'; +import { HttpResponse } from '@azure-rest/core-client'; +import { PagedAsyncIterableIterator } from '@azure/core-paging'; +import { PathUncheckedResponse } from '@azure-rest/core-client'; +import { RawHttpHeaders } from '@azure/core-rest-pipeline'; +import { RequestParameters } from '@azure-rest/core-client'; +import { StreamableMethod } from '@azure-rest/core-client'; +import { TokenCredential } from '@azure/core-auth'; + +// @public +export interface CollectionModelOutput { + // (undocumented) + collectionId: string; +} + +// @public (undocumented) +export interface ConfidentialLedgerCreateLedgerEntry201Headers { + // (undocumented) + location: string; +} + +// @public +export interface ConfidentialLedgerCreateLedgerEntry201Response extends HttpResponse { + // (undocumented) + headers: RawHttpHeaders & ConfidentialLedgerCreateLedgerEntry201Headers; + // (undocumented) + status: "201"; +} + +// @public (undocumented) +export interface ConfidentialLedgerCreateLedgerEntryBodyParam { + // (undocumented) + body?: LedgerEntry; +} + +// @public (undocumented) +export interface ConfidentialLedgerCreateLedgerEntryDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponseOutput; + // (undocumented) + status: string; +} + +// @public (undocumented) +export type ConfidentialLedgerCreateLedgerEntryParameters = ConfidentialLedgerCreateLedgerEntryQueryParam & ConfidentialLedgerCreateLedgerEntryBodyParam & RequestParameters; + +// @public (undocumented) +export interface ConfidentialLedgerCreateLedgerEntryQueryParam { + // (undocumented) + queryParameters?: ConfidentialLedgerCreateLedgerEntryQueryParamProperties; +} + +// @public (undocumented) +export interface ConfidentialLedgerCreateLedgerEntryQueryParamProperties { + collectionId?: string; +} + +// @public +export interface ConfidentialLedgerCreateOrUpdateUser200Response extends HttpResponse { + // (undocumented) + body: LedgerUserOutput; + // (undocumented) + status: "200"; +} + +// @public +export interface ConfidentialLedgerCreateOrUpdateUser201Response extends HttpResponse { + // (undocumented) + body: LedgerUserOutput; + // (undocumented) + status: "201"; +} + +// @public (undocumented) +export interface ConfidentialLedgerCreateOrUpdateUserBodyParam { + // (undocumented) + body?: LedgerUser; +} + +// @public (undocumented) +export interface ConfidentialLedgerCreateOrUpdateUserDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponseOutput; + // (undocumented) + status: string; +} + +// @public (undocumented) +export interface ConfidentialLedgerCreateOrUpdateUserMediaTypesParam { + // (undocumented) + contentType: "application/merge-patch+json"; +} + +// @public (undocumented) +export type ConfidentialLedgerCreateOrUpdateUserParameters = ConfidentialLedgerCreateOrUpdateUserMediaTypesParam & ConfidentialLedgerCreateOrUpdateUserBodyParam & RequestParameters; + +// @public +export interface ConfidentialLedgerDeleteUser204Response extends HttpResponse { + // (undocumented) + status: "204"; +} + +// @public (undocumented) +export interface ConfidentialLedgerDeleteUserDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponseOutput; + // (undocumented) + status: string; +} + +// @public (undocumented) +export type ConfidentialLedgerDeleteUserParameters = RequestParameters; + +// @public +export interface ConfidentialLedgerGetConsortiumMembers200Response extends HttpResponse { + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface ConfidentialLedgerGetConsortiumMembersDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponseOutput; + // (undocumented) + status: string; +} + +// @public (undocumented) +export type ConfidentialLedgerGetConsortiumMembersParameters = RequestParameters; + +// @public +export interface ConfidentialLedgerGetConstitution200Response extends HttpResponse { + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface ConfidentialLedgerGetConstitutionDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponseOutput; + // (undocumented) + status: string; +} + +// @public (undocumented) +export type ConfidentialLedgerGetConstitutionParameters = RequestParameters; + +// @public +export interface ConfidentialLedgerGetCurrentLedgerEntry200Response extends HttpResponse { + // (undocumented) + body: LedgerEntryOutput; + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface ConfidentialLedgerGetCurrentLedgerEntryDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponseOutput; + // (undocumented) + status: string; +} + +// @public (undocumented) +export type ConfidentialLedgerGetCurrentLedgerEntryParameters = ConfidentialLedgerGetCurrentLedgerEntryQueryParam & RequestParameters; + +// @public (undocumented) +export interface ConfidentialLedgerGetCurrentLedgerEntryQueryParam { + // (undocumented) + queryParameters?: ConfidentialLedgerGetCurrentLedgerEntryQueryParamProperties; +} + +// @public (undocumented) +export interface ConfidentialLedgerGetCurrentLedgerEntryQueryParamProperties { + collectionId?: string; +} + +// @public +export interface ConfidentialLedgerGetEnclaveQuotes200Response extends HttpResponse { + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface ConfidentialLedgerGetEnclaveQuotesDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponseOutput; + // (undocumented) + status: string; +} + +// @public (undocumented) +export type ConfidentialLedgerGetEnclaveQuotesParameters = RequestParameters; + +// @public +export interface ConfidentialLedgerGetLedgerEntry200Response extends HttpResponse { + // (undocumented) + body: LedgerEntryOutput; + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface ConfidentialLedgerGetLedgerEntryDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponseOutput; + // (undocumented) + status: string; +} + +// @public (undocumented) +export type ConfidentialLedgerGetLedgerEntryParameters = ConfidentialLedgerGetLedgerEntryQueryParam & RequestParameters; + +// @public (undocumented) +export interface ConfidentialLedgerGetLedgerEntryQueryParam { + // (undocumented) + queryParameters?: ConfidentialLedgerGetLedgerEntryQueryParamProperties; +} + +// @public (undocumented) +export interface ConfidentialLedgerGetLedgerEntryQueryParamProperties { + collectionId?: string; +} + +// @public +export interface ConfidentialLedgerGetReceipt200Response extends HttpResponse { + // (undocumented) + body: TransactionReceiptOutput; + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface ConfidentialLedgerGetReceiptDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponseOutput; + // (undocumented) + status: string; +} + +// @public (undocumented) +export type ConfidentialLedgerGetReceiptParameters = RequestParameters; + +// @public +export interface ConfidentialLedgerGetTransactionStatus200Response extends HttpResponse { + // (undocumented) + body: TransactionStatusOutput; + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface ConfidentialLedgerGetTransactionStatusDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponseOutput; + // (undocumented) + status: string; +} + +// @public (undocumented) +export type ConfidentialLedgerGetTransactionStatusParameters = RequestParameters; + +// @public +export interface ConfidentialLedgerGetUser200Response extends HttpResponse { + // (undocumented) + body: LedgerUserOutput; + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface ConfidentialLedgerGetUserDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponseOutput; + // (undocumented) + status: string; +} + +// @public (undocumented) +export type ConfidentialLedgerGetUserParameters = RequestParameters; + +// @public +export interface ConfidentialLedgerListCollections200Response extends HttpResponse { + // (undocumented) + body: Array; + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface ConfidentialLedgerListCollectionsDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponseOutput; + // (undocumented) + status: string; +} + +// @public (undocumented) +export type ConfidentialLedgerListCollectionsParameters = RequestParameters; + +// @public +export interface ConfidentialLedgerListLedgerEntries200Response extends HttpResponse { + // (undocumented) + body: PagedLedgerEntriesOutput; + // (undocumented) + status: "200"; +} + +// @public (undocumented) +export interface ConfidentialLedgerListLedgerEntriesDefaultResponse extends HttpResponse { + // (undocumented) + body: ErrorResponseOutput; + // (undocumented) + status: string; +} + +// @public (undocumented) +export type ConfidentialLedgerListLedgerEntriesParameters = RequestParameters; + +// @public +export interface ConfidentialLedgerOperations { + createLedgerEntry(options?: ConfidentialLedgerCreateLedgerEntryParameters): StreamableMethod; + createOrUpdateUser(userId: string, options: ConfidentialLedgerCreateOrUpdateUserParameters): StreamableMethod; + deleteUser(userId: string, options?: ConfidentialLedgerDeleteUserParameters): StreamableMethod; + getConsortiumMembers(options?: ConfidentialLedgerGetConsortiumMembersParameters): StreamableMethod; + getConstitution(options?: ConfidentialLedgerGetConstitutionParameters): StreamableMethod; + getCurrentLedgerEntry(options?: ConfidentialLedgerGetCurrentLedgerEntryParameters): StreamableMethod; + getEnclaveQuotes(options?: ConfidentialLedgerGetEnclaveQuotesParameters): StreamableMethod; + getLedgerEntry(transactionId: string, options?: ConfidentialLedgerGetLedgerEntryParameters): StreamableMethod; + getReceipt(transactionId: string, options?: ConfidentialLedgerGetReceiptParameters): StreamableMethod; + getTransactionStatus(transactionId: string, options?: ConfidentialLedgerGetTransactionStatusParameters): StreamableMethod; + getUser(userId: string, options?: ConfidentialLedgerGetUserParameters): StreamableMethod; + listCollections(options?: ConfidentialLedgerListCollectionsParameters): StreamableMethod; + listLedgerEntries(options?: ConfidentialLedgerListLedgerEntriesParameters): StreamableMethod; +} + +// @public (undocumented) +export type ConfidentialLedgerServiceClient = Client & { + path: Routes; + confidentialLedger: ConfidentialLedgerOperations; +}; + +// @public +function createClient(ledgerUri: string, credentials: TokenCredential, options?: ClientOptions): ConfidentialLedgerServiceClient; +export default createClient; + +// @public (undocumented) +export interface DeleteUser { + delete(options?: ConfidentialLedgerDeleteUserParameters): StreamableMethod; + get(options?: ConfidentialLedgerGetUserParameters): StreamableMethod; + patch(options: ConfidentialLedgerCreateOrUpdateUserParameters): StreamableMethod; +} + +// @public +export interface ErrorModelOutput { + code: string; + details: Array; + innererror?: InnerErrorOutput; + message: string; + target?: string; +} + +// @public +export interface ErrorResponseOutput { + error: ErrorModelOutput; +} + +// @public +export type GetArrayType = T extends Array ? TData : never; + +// @public (undocumented) +export interface GetConsortiumMembers { + get(options?: ConfidentialLedgerGetConsortiumMembersParameters): StreamableMethod; +} + +// @public (undocumented) +export interface GetConstitution { + get(options?: ConfidentialLedgerGetConstitutionParameters): StreamableMethod; +} + +// @public (undocumented) +export interface GetCurrentLedgerEntry { + get(options?: ConfidentialLedgerGetCurrentLedgerEntryParameters): StreamableMethod; +} + +// @public (undocumented) +export interface GetEnclaveQuotes { + get(options?: ConfidentialLedgerGetEnclaveQuotesParameters): StreamableMethod; +} + +// @public (undocumented) +export interface GetLedgerEntry { + get(options?: ConfidentialLedgerGetLedgerEntryParameters): StreamableMethod; +} + +// @public +export type GetPage = (pageLink: string, maxPageSize?: number) => Promise<{ + page: TPage; + nextPageLink?: string; +}>; + +// @public (undocumented) +export interface GetReceipt { + get(options?: ConfidentialLedgerGetReceiptParameters): StreamableMethod; +} + +// @public (undocumented) +export interface GetTransactionStatus { + get(options?: ConfidentialLedgerGetTransactionStatusParameters): StreamableMethod; +} + +// @public +export interface InnerErrorOutput { + code: string; + innererror?: InnerErrorOutput; +} + +// @public (undocumented) +export function isUnexpected(response: ConfidentialLedgerListCollections200Response | ConfidentialLedgerListCollectionsDefaultResponse): response is ConfidentialLedgerListCollectionsDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: ConfidentialLedgerGetEnclaveQuotes200Response | ConfidentialLedgerGetEnclaveQuotesDefaultResponse): response is ConfidentialLedgerGetEnclaveQuotesDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: ConfidentialLedgerGetConstitution200Response | ConfidentialLedgerGetConstitutionDefaultResponse): response is ConfidentialLedgerGetConstitutionDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: ConfidentialLedgerGetConsortiumMembers200Response | ConfidentialLedgerGetConsortiumMembersDefaultResponse): response is ConfidentialLedgerGetConsortiumMembersDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: ConfidentialLedgerListLedgerEntries200Response | ConfidentialLedgerListLedgerEntriesDefaultResponse): response is ConfidentialLedgerListLedgerEntriesDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: ConfidentialLedgerCreateLedgerEntry201Response | ConfidentialLedgerCreateLedgerEntryDefaultResponse): response is ConfidentialLedgerCreateLedgerEntryDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: ConfidentialLedgerGetLedgerEntry200Response | ConfidentialLedgerGetLedgerEntryDefaultResponse): response is ConfidentialLedgerGetLedgerEntryDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: ConfidentialLedgerGetReceipt200Response | ConfidentialLedgerGetReceiptDefaultResponse): response is ConfidentialLedgerGetReceiptDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: ConfidentialLedgerGetTransactionStatus200Response | ConfidentialLedgerGetTransactionStatusDefaultResponse): response is ConfidentialLedgerGetTransactionStatusDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: ConfidentialLedgerGetCurrentLedgerEntry200Response | ConfidentialLedgerGetCurrentLedgerEntryDefaultResponse): response is ConfidentialLedgerGetCurrentLedgerEntryDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: ConfidentialLedgerDeleteUser204Response | ConfidentialLedgerDeleteUserDefaultResponse): response is ConfidentialLedgerDeleteUserDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: ConfidentialLedgerGetUser200Response | ConfidentialLedgerGetUserDefaultResponse): response is ConfidentialLedgerGetUserDefaultResponse; + +// @public (undocumented) +export function isUnexpected(response: ConfidentialLedgerCreateOrUpdateUser200Response | ConfidentialLedgerCreateOrUpdateUser201Response | ConfidentialLedgerCreateOrUpdateUserDefaultResponse): response is ConfidentialLedgerCreateOrUpdateUserDefaultResponse; + +// @public (undocumented) +export interface LedgerEntry { + // (undocumented) + collectionId: string; + contents: string; + transactionId: string; +} + +// @public (undocumented) +export interface LedgerEntryOutput { + // (undocumented) + collectionId: string; + contents: string; + transactionId: string; +} + +// @public +export interface LedgerUser { + assignedRole: string; + userId: string; +} + +// @public +export interface LedgerUserOutput { + assignedRole: string; + userId: string; +} + +// @public (undocumented) +export interface ListCollections { + get(options?: ConfidentialLedgerListCollectionsParameters): StreamableMethod; +} + +// @public (undocumented) +export interface ListLedgerEntries { + get(options?: ConfidentialLedgerListLedgerEntriesParameters): StreamableMethod; + post(options?: ConfidentialLedgerCreateLedgerEntryParameters): StreamableMethod; +} + +// @public +export interface PagedLedgerEntriesOutput { + entries: Array; + nextLink?: string; + state: string; +} + +// @public +export function paginate(client: Client, initialResponse: TResponse, options?: PagingOptions): PagedAsyncIterableIterator>; + +// @public +export type PaginateReturn = TResult extends { + body: { + value?: infer TPage; + }; +} | { + body: { + entries?: infer TPage; + }; +} ? GetArrayType : Array; + +// @public +export interface PagingOptions { + customGetPage?: GetPage[]>; +} + +// @public (undocumented) +export interface ReceiptContentsOutput { +} + +// @public (undocumented) +export interface Routes { + (path: "/app/collections"): ListCollections; + (path: "/app/enclaveQuotes"): GetEnclaveQuotes; + (path: "/app/governance/constitution"): GetConstitution; + (path: "/app/governance/members"): GetConsortiumMembers; + (path: "/app/transactions"): ListLedgerEntries; + (path: "/app/transactions/{transactionId}", transactionId: string): GetLedgerEntry; + (path: "/app/transactions/{transactionId}/receipt", transactionId: string): GetReceipt; + (path: "/app/transactions/{transactionId}/status", transactionId: string): GetTransactionStatus; + (path: "/app/transactions:getCurrentLedgerEntry"): GetCurrentLedgerEntry; + (path: "/app/users/{userId}", userId: string): DeleteUser; +} + +// @public +export interface TransactionReceiptOutput { + // (undocumented) + receipt: ReceiptContentsOutput; + state: string; + transactionId: string; +} + +// @public +export interface TransactionStatusOutput { + state: string; + transactionId: string; +} + +// (No @packageDocumentation comment for this package) + +``` diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/src/clientDefinitions.ts b/sdk/confidentialledger/azure-confidentialledger-rest/src/clientDefinitions.ts new file mode 100644 index 000000000000..67838edfe369 --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/src/clientDefinitions.ts @@ -0,0 +1,306 @@ +import { + ConfidentialLedgerListCollectionsParameters, + ConfidentialLedgerGetEnclaveQuotesParameters, + ConfidentialLedgerGetConstitutionParameters, + ConfidentialLedgerGetConsortiumMembersParameters, + ConfidentialLedgerListLedgerEntriesParameters, + ConfidentialLedgerCreateLedgerEntryParameters, + ConfidentialLedgerGetLedgerEntryParameters, + ConfidentialLedgerGetReceiptParameters, + ConfidentialLedgerGetTransactionStatusParameters, + ConfidentialLedgerGetCurrentLedgerEntryParameters, + ConfidentialLedgerDeleteUserParameters, + ConfidentialLedgerGetUserParameters, + ConfidentialLedgerCreateOrUpdateUserParameters, +} from "./parameters"; +import { + ConfidentialLedgerListCollections200Response, + ConfidentialLedgerListCollectionsDefaultResponse, + ConfidentialLedgerGetEnclaveQuotes200Response, + ConfidentialLedgerGetEnclaveQuotesDefaultResponse, + ConfidentialLedgerGetConstitution200Response, + ConfidentialLedgerGetConstitutionDefaultResponse, + ConfidentialLedgerGetConsortiumMembers200Response, + ConfidentialLedgerGetConsortiumMembersDefaultResponse, + ConfidentialLedgerListLedgerEntries200Response, + ConfidentialLedgerListLedgerEntriesDefaultResponse, + ConfidentialLedgerCreateLedgerEntry201Response, + ConfidentialLedgerCreateLedgerEntryDefaultResponse, + ConfidentialLedgerGetLedgerEntry200Response, + ConfidentialLedgerGetLedgerEntryDefaultResponse, + ConfidentialLedgerGetReceipt200Response, + ConfidentialLedgerGetReceiptDefaultResponse, + ConfidentialLedgerGetTransactionStatus200Response, + ConfidentialLedgerGetTransactionStatusDefaultResponse, + ConfidentialLedgerGetCurrentLedgerEntry200Response, + ConfidentialLedgerGetCurrentLedgerEntryDefaultResponse, + ConfidentialLedgerDeleteUser204Response, + ConfidentialLedgerDeleteUserDefaultResponse, + ConfidentialLedgerGetUser200Response, + ConfidentialLedgerGetUserDefaultResponse, + ConfidentialLedgerCreateOrUpdateUser200Response, + ConfidentialLedgerCreateOrUpdateUser201Response, + ConfidentialLedgerCreateOrUpdateUserDefaultResponse, +} from "./responses"; +import { Client, StreamableMethod } from "@azure-rest/core-client"; + +/** Contains operations for ConfidentialLedger operations */ +export interface ConfidentialLedgerOperations { + /** Collection ids are user-created collections of ledger entries */ + listCollections( + options?: ConfidentialLedgerListCollectionsParameters + ): StreamableMethod< + | ConfidentialLedgerListCollections200Response + | ConfidentialLedgerListCollectionsDefaultResponse + >; + /** A quote is an SGX enclave measurement that can be used to verify the validity of a node and its enclave. */ + getEnclaveQuotes( + options?: ConfidentialLedgerGetEnclaveQuotesParameters + ): StreamableMethod< + | ConfidentialLedgerGetEnclaveQuotes200Response + | ConfidentialLedgerGetEnclaveQuotesDefaultResponse + >; + /** The constitution is a script that assesses and applies proposals from consortium members. */ + getConstitution( + options?: ConfidentialLedgerGetConstitutionParameters + ): StreamableMethod< + | ConfidentialLedgerGetConstitution200Response + | ConfidentialLedgerGetConstitutionDefaultResponse + >; + /** Consortium members can manage the Confidential Ledger. */ + getConsortiumMembers( + options?: ConfidentialLedgerGetConsortiumMembersParameters + ): StreamableMethod< + | ConfidentialLedgerGetConsortiumMembers200Response + | ConfidentialLedgerGetConsortiumMembersDefaultResponse + >; + /** A collection id may optionally be specified. Only entries in the specified (or default) collection will be returned. */ + listLedgerEntries( + options?: ConfidentialLedgerListLedgerEntriesParameters + ): StreamableMethod< + | ConfidentialLedgerListLedgerEntries200Response + | ConfidentialLedgerListLedgerEntriesDefaultResponse + >; + /** A collection id may optionally be specified. */ + createLedgerEntry( + options?: ConfidentialLedgerCreateLedgerEntryParameters + ): StreamableMethod< + | ConfidentialLedgerCreateLedgerEntry201Response + | ConfidentialLedgerCreateLedgerEntryDefaultResponse + >; + /** Get a LedgerEntry */ + getLedgerEntry( + transactionId: string, + options?: ConfidentialLedgerGetLedgerEntryParameters + ): StreamableMethod< + | ConfidentialLedgerGetLedgerEntry200Response + | ConfidentialLedgerGetLedgerEntryDefaultResponse + >; + /** Runs a custom action on LedgerEntry */ + getReceipt( + transactionId: string, + options?: ConfidentialLedgerGetReceiptParameters + ): StreamableMethod< + | ConfidentialLedgerGetReceipt200Response + | ConfidentialLedgerGetReceiptDefaultResponse + >; + /** Runs a custom action on LedgerEntry */ + getTransactionStatus( + transactionId: string, + options?: ConfidentialLedgerGetTransactionStatusParameters + ): StreamableMethod< + | ConfidentialLedgerGetTransactionStatus200Response + | ConfidentialLedgerGetTransactionStatusDefaultResponse + >; + /** Runs a custom action on LedgerEntry */ + getCurrentLedgerEntry( + options?: ConfidentialLedgerGetCurrentLedgerEntryParameters + ): StreamableMethod< + | ConfidentialLedgerGetCurrentLedgerEntry200Response + | ConfidentialLedgerGetCurrentLedgerEntryDefaultResponse + >; + /** Delete a LedgerUser */ + deleteUser( + userId: string, + options?: ConfidentialLedgerDeleteUserParameters + ): StreamableMethod< + | ConfidentialLedgerDeleteUser204Response + | ConfidentialLedgerDeleteUserDefaultResponse + >; + /** Get a LedgerUser */ + getUser( + userId: string, + options?: ConfidentialLedgerGetUserParameters + ): StreamableMethod< + | ConfidentialLedgerGetUser200Response + | ConfidentialLedgerGetUserDefaultResponse + >; + /** Creates or updates a LedgerUser */ + createOrUpdateUser( + userId: string, + options: ConfidentialLedgerCreateOrUpdateUserParameters + ): StreamableMethod< + | ConfidentialLedgerCreateOrUpdateUser200Response + | ConfidentialLedgerCreateOrUpdateUser201Response + | ConfidentialLedgerCreateOrUpdateUserDefaultResponse + >; +} + +export interface ListCollections { + /** Collection ids are user-created collections of ledger entries */ + get( + options?: ConfidentialLedgerListCollectionsParameters + ): StreamableMethod< + | ConfidentialLedgerListCollections200Response + | ConfidentialLedgerListCollectionsDefaultResponse + >; +} + +export interface GetEnclaveQuotes { + /** A quote is an SGX enclave measurement that can be used to verify the validity of a node and its enclave. */ + get( + options?: ConfidentialLedgerGetEnclaveQuotesParameters + ): StreamableMethod< + | ConfidentialLedgerGetEnclaveQuotes200Response + | ConfidentialLedgerGetEnclaveQuotesDefaultResponse + >; +} + +export interface GetConstitution { + /** The constitution is a script that assesses and applies proposals from consortium members. */ + get( + options?: ConfidentialLedgerGetConstitutionParameters + ): StreamableMethod< + | ConfidentialLedgerGetConstitution200Response + | ConfidentialLedgerGetConstitutionDefaultResponse + >; +} + +export interface GetConsortiumMembers { + /** Consortium members can manage the Confidential Ledger. */ + get( + options?: ConfidentialLedgerGetConsortiumMembersParameters + ): StreamableMethod< + | ConfidentialLedgerGetConsortiumMembers200Response + | ConfidentialLedgerGetConsortiumMembersDefaultResponse + >; +} + +export interface ListLedgerEntries { + /** A collection id may optionally be specified. Only entries in the specified (or default) collection will be returned. */ + get( + options?: ConfidentialLedgerListLedgerEntriesParameters + ): StreamableMethod< + | ConfidentialLedgerListLedgerEntries200Response + | ConfidentialLedgerListLedgerEntriesDefaultResponse + >; + /** A collection id may optionally be specified. */ + post( + options?: ConfidentialLedgerCreateLedgerEntryParameters + ): StreamableMethod< + | ConfidentialLedgerCreateLedgerEntry201Response + | ConfidentialLedgerCreateLedgerEntryDefaultResponse + >; +} + +export interface GetLedgerEntry { + /** Get a LedgerEntry */ + get( + options?: ConfidentialLedgerGetLedgerEntryParameters + ): StreamableMethod< + | ConfidentialLedgerGetLedgerEntry200Response + | ConfidentialLedgerGetLedgerEntryDefaultResponse + >; +} + +export interface GetReceipt { + /** Runs a custom action on LedgerEntry */ + get( + options?: ConfidentialLedgerGetReceiptParameters + ): StreamableMethod< + | ConfidentialLedgerGetReceipt200Response + | ConfidentialLedgerGetReceiptDefaultResponse + >; +} + +export interface GetTransactionStatus { + /** Runs a custom action on LedgerEntry */ + get( + options?: ConfidentialLedgerGetTransactionStatusParameters + ): StreamableMethod< + | ConfidentialLedgerGetTransactionStatus200Response + | ConfidentialLedgerGetTransactionStatusDefaultResponse + >; +} + +export interface GetCurrentLedgerEntry { + /** Runs a custom action on LedgerEntry */ + get( + options?: ConfidentialLedgerGetCurrentLedgerEntryParameters + ): StreamableMethod< + | ConfidentialLedgerGetCurrentLedgerEntry200Response + | ConfidentialLedgerGetCurrentLedgerEntryDefaultResponse + >; +} + +export interface DeleteUser { + /** Delete a LedgerUser */ + delete( + options?: ConfidentialLedgerDeleteUserParameters + ): StreamableMethod< + | ConfidentialLedgerDeleteUser204Response + | ConfidentialLedgerDeleteUserDefaultResponse + >; + /** Get a LedgerUser */ + get( + options?: ConfidentialLedgerGetUserParameters + ): StreamableMethod< + | ConfidentialLedgerGetUser200Response + | ConfidentialLedgerGetUserDefaultResponse + >; + /** Creates or updates a LedgerUser */ + patch( + options: ConfidentialLedgerCreateOrUpdateUserParameters + ): StreamableMethod< + | ConfidentialLedgerCreateOrUpdateUser200Response + | ConfidentialLedgerCreateOrUpdateUser201Response + | ConfidentialLedgerCreateOrUpdateUserDefaultResponse + >; +} + +export interface Routes { + /** Resource for '/app/collections' has methods for the following verbs: get */ + (path: "/app/collections"): ListCollections; + /** Resource for '/app/enclaveQuotes' has methods for the following verbs: get */ + (path: "/app/enclaveQuotes"): GetEnclaveQuotes; + /** Resource for '/app/governance/constitution' has methods for the following verbs: get */ + (path: "/app/governance/constitution"): GetConstitution; + /** Resource for '/app/governance/members' has methods for the following verbs: get */ + (path: "/app/governance/members"): GetConsortiumMembers; + /** Resource for '/app/transactions' has methods for the following verbs: get, post */ + (path: "/app/transactions"): ListLedgerEntries; + /** Resource for '/app/transactions/\{transactionId\}' has methods for the following verbs: get */ + ( + path: "/app/transactions/{transactionId}", + transactionId: string + ): GetLedgerEntry; + /** Resource for '/app/transactions/\{transactionId\}/receipt' has methods for the following verbs: get */ + ( + path: "/app/transactions/{transactionId}/receipt", + transactionId: string + ): GetReceipt; + /** Resource for '/app/transactions/\{transactionId\}/status' has methods for the following verbs: get */ + ( + path: "/app/transactions/{transactionId}/status", + transactionId: string + ): GetTransactionStatus; + /** Resource for '/app/transactions:getCurrentLedgerEntry' has methods for the following verbs: get */ + (path: "/app/transactions:getCurrentLedgerEntry"): GetCurrentLedgerEntry; + /** Resource for '/app/users/\{userId\}' has methods for the following verbs: delete, get, patch */ + (path: "/app/users/{userId}", userId: string): DeleteUser; +} + +export type ConfidentialLedgerServiceClient = Client & { + path: Routes; + confidentialLedger: ConfidentialLedgerOperations; +}; diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/src/confidentialLedgerService.ts b/sdk/confidentialledger/azure-confidentialledger-rest/src/confidentialLedgerService.ts new file mode 100644 index 000000000000..9ae539cc17dc --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/src/confidentialLedgerService.ts @@ -0,0 +1,94 @@ +import { getClient, ClientOptions } from "@azure-rest/core-client"; +import { TokenCredential } from "@azure/core-auth"; +import { ConfidentialLedgerServiceClient } from "./clientDefinitions"; + +/** + * Initialize a new instance of the class ConfidentialLedgerServiceClient class. + * @param ledgerUri type: string + * @param credentials type: TokenCredential + */ +export default function createClient( + ledgerUri: string, + credentials: TokenCredential, + options: ClientOptions = {} +): ConfidentialLedgerServiceClient { + const baseUrl = options.baseUrl ?? `${ledgerUri}`; + options.apiVersion = options.apiVersion ?? "2022-08-13"; + options = { + ...options, + credentials: { + scopes: ["https://confidential-ledger.azure.com/.default"], + }, + }; + + const userAgentInfo = `azsdk-js-confidentialledger-test-rest/1.0.0-beta.1`; + const userAgentPrefix = + options.userAgentOptions && options.userAgentOptions.userAgentPrefix + ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}` + : `${userAgentInfo}`; + options = { + ...options, + userAgentOptions: { + userAgentPrefix, + }, + }; + + const client = getClient( + baseUrl, + credentials, + options + ) as ConfidentialLedgerServiceClient; + + return { + ...client, + confidentialLedger: { + listCollections: (options) => { + return client.path("/app/collections").get(options); + }, + getEnclaveQuotes: (options) => { + return client.path("/app/enclaveQuotes").get(options); + }, + getConstitution: (options) => { + return client.path("/app/governance/constitution").get(options); + }, + getConsortiumMembers: (options) => { + return client.path("/app/governance/members").get(options); + }, + listLedgerEntries: (options) => { + return client.path("/app/transactions").get(options); + }, + createLedgerEntry: (options) => { + return client.path("/app/transactions").post(options); + }, + getLedgerEntry: (transactionId, options) => { + return client + .path("/app/transactions/{transactionId}", transactionId) + .get(options); + }, + getReceipt: (transactionId, options) => { + return client + .path("/app/transactions/{transactionId}/receipt", transactionId) + .get(options); + }, + getTransactionStatus: (transactionId, options) => { + return client + .path("/app/transactions/{transactionId}/status", transactionId) + .get(options); + }, + getCurrentLedgerEntry: (options) => { + return client + .path("/app/transactions:getCurrentLedgerEntry") + .get(options); + }, + deleteUser: (userId, options) => { + return client.path("/app/users/{userId}", userId).delete(options); + }, + getUser: (userId, options) => { + return client.path("/app/users/{userId}", userId).get(options); + }, + createOrUpdateUser: (userId, options) => { + return client.path("/app/users/{userId}", userId).patch(options); + }, + }, + }; +} diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/src/index.ts b/sdk/confidentialledger/azure-confidentialledger-rest/src/index.ts new file mode 100644 index 000000000000..9213bcfeb38e --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/src/index.ts @@ -0,0 +1,12 @@ +import ConfidentialLedgerService from "./confidentialLedgerService"; + +export * from "./confidentialLedgerService"; +export * from "./parameters"; +export * from "./responses"; +export * from "./clientDefinitions"; +export * from "./isUnexpected"; +export * from "./models"; +export * from "./outputModels"; +export * from "./paginateHelper"; + +export default ConfidentialLedgerService; diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/src/isUnexpected.ts b/sdk/confidentialledger/azure-confidentialledger-rest/src/isUnexpected.ts new file mode 100644 index 000000000000..3349d3ce933b --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/src/isUnexpected.ts @@ -0,0 +1,228 @@ +import { + ConfidentialLedgerListCollections200Response, + ConfidentialLedgerListCollectionsDefaultResponse, + ConfidentialLedgerGetEnclaveQuotes200Response, + ConfidentialLedgerGetEnclaveQuotesDefaultResponse, + ConfidentialLedgerGetConstitution200Response, + ConfidentialLedgerGetConstitutionDefaultResponse, + ConfidentialLedgerGetConsortiumMembers200Response, + ConfidentialLedgerGetConsortiumMembersDefaultResponse, + ConfidentialLedgerListLedgerEntries200Response, + ConfidentialLedgerListLedgerEntriesDefaultResponse, + ConfidentialLedgerCreateLedgerEntry201Response, + ConfidentialLedgerCreateLedgerEntryDefaultResponse, + ConfidentialLedgerGetLedgerEntry200Response, + ConfidentialLedgerGetLedgerEntryDefaultResponse, + ConfidentialLedgerGetReceipt200Response, + ConfidentialLedgerGetReceiptDefaultResponse, + ConfidentialLedgerGetTransactionStatus200Response, + ConfidentialLedgerGetTransactionStatusDefaultResponse, + ConfidentialLedgerGetCurrentLedgerEntry200Response, + ConfidentialLedgerGetCurrentLedgerEntryDefaultResponse, + ConfidentialLedgerDeleteUser204Response, + ConfidentialLedgerDeleteUserDefaultResponse, + ConfidentialLedgerGetUser200Response, + ConfidentialLedgerGetUserDefaultResponse, + ConfidentialLedgerCreateOrUpdateUser200Response, + ConfidentialLedgerCreateOrUpdateUser201Response, + ConfidentialLedgerCreateOrUpdateUserDefaultResponse, +} from "./responses"; + +const responseMap: Record = { + "GET /app/collections": ["200"], + "GET /app/enclaveQuotes": ["200"], + "GET /app/governance/constitution": ["200"], + "GET /app/governance/members": ["200"], + "GET /app/transactions": ["200"], + "POST /app/transactions": ["201"], + "GET /app/transactions/{transactionId}": ["200"], + "GET /app/transactions/{transactionId}/receipt": ["200"], + "GET /app/transactions/{transactionId}/status": ["200"], + "GET /app/transactions:getCurrentLedgerEntry": ["200"], + "DELETE /app/users/{userId}": ["204"], + "GET /app/users/{userId}": ["200"], + "PATCH /app/users/{userId}": ["200", "201"], +}; + +export function isUnexpected( + response: + | ConfidentialLedgerListCollections200Response + | ConfidentialLedgerListCollectionsDefaultResponse +): response is ConfidentialLedgerListCollectionsDefaultResponse; +export function isUnexpected( + response: + | ConfidentialLedgerGetEnclaveQuotes200Response + | ConfidentialLedgerGetEnclaveQuotesDefaultResponse +): response is ConfidentialLedgerGetEnclaveQuotesDefaultResponse; +export function isUnexpected( + response: + | ConfidentialLedgerGetConstitution200Response + | ConfidentialLedgerGetConstitutionDefaultResponse +): response is ConfidentialLedgerGetConstitutionDefaultResponse; +export function isUnexpected( + response: + | ConfidentialLedgerGetConsortiumMembers200Response + | ConfidentialLedgerGetConsortiumMembersDefaultResponse +): response is ConfidentialLedgerGetConsortiumMembersDefaultResponse; +export function isUnexpected( + response: + | ConfidentialLedgerListLedgerEntries200Response + | ConfidentialLedgerListLedgerEntriesDefaultResponse +): response is ConfidentialLedgerListLedgerEntriesDefaultResponse; +export function isUnexpected( + response: + | ConfidentialLedgerCreateLedgerEntry201Response + | ConfidentialLedgerCreateLedgerEntryDefaultResponse +): response is ConfidentialLedgerCreateLedgerEntryDefaultResponse; +export function isUnexpected( + response: + | ConfidentialLedgerGetLedgerEntry200Response + | ConfidentialLedgerGetLedgerEntryDefaultResponse +): response is ConfidentialLedgerGetLedgerEntryDefaultResponse; +export function isUnexpected( + response: + | ConfidentialLedgerGetReceipt200Response + | ConfidentialLedgerGetReceiptDefaultResponse +): response is ConfidentialLedgerGetReceiptDefaultResponse; +export function isUnexpected( + response: + | ConfidentialLedgerGetTransactionStatus200Response + | ConfidentialLedgerGetTransactionStatusDefaultResponse +): response is ConfidentialLedgerGetTransactionStatusDefaultResponse; +export function isUnexpected( + response: + | ConfidentialLedgerGetCurrentLedgerEntry200Response + | ConfidentialLedgerGetCurrentLedgerEntryDefaultResponse +): response is ConfidentialLedgerGetCurrentLedgerEntryDefaultResponse; +export function isUnexpected( + response: + | ConfidentialLedgerDeleteUser204Response + | ConfidentialLedgerDeleteUserDefaultResponse +): response is ConfidentialLedgerDeleteUserDefaultResponse; +export function isUnexpected( + response: + | ConfidentialLedgerGetUser200Response + | ConfidentialLedgerGetUserDefaultResponse +): response is ConfidentialLedgerGetUserDefaultResponse; +export function isUnexpected( + response: + | ConfidentialLedgerCreateOrUpdateUser200Response + | ConfidentialLedgerCreateOrUpdateUser201Response + | ConfidentialLedgerCreateOrUpdateUserDefaultResponse +): response is ConfidentialLedgerCreateOrUpdateUserDefaultResponse; +export function isUnexpected( + response: + | ConfidentialLedgerListCollections200Response + | ConfidentialLedgerListCollectionsDefaultResponse + | ConfidentialLedgerGetEnclaveQuotes200Response + | ConfidentialLedgerGetEnclaveQuotesDefaultResponse + | ConfidentialLedgerGetConstitution200Response + | ConfidentialLedgerGetConstitutionDefaultResponse + | ConfidentialLedgerGetConsortiumMembers200Response + | ConfidentialLedgerGetConsortiumMembersDefaultResponse + | ConfidentialLedgerListLedgerEntries200Response + | ConfidentialLedgerListLedgerEntriesDefaultResponse + | ConfidentialLedgerCreateLedgerEntry201Response + | ConfidentialLedgerCreateLedgerEntryDefaultResponse + | ConfidentialLedgerGetLedgerEntry200Response + | ConfidentialLedgerGetLedgerEntryDefaultResponse + | ConfidentialLedgerGetReceipt200Response + | ConfidentialLedgerGetReceiptDefaultResponse + | ConfidentialLedgerGetTransactionStatus200Response + | ConfidentialLedgerGetTransactionStatusDefaultResponse + | ConfidentialLedgerGetCurrentLedgerEntry200Response + | ConfidentialLedgerGetCurrentLedgerEntryDefaultResponse + | ConfidentialLedgerDeleteUser204Response + | ConfidentialLedgerDeleteUserDefaultResponse + | ConfidentialLedgerGetUser200Response + | ConfidentialLedgerGetUserDefaultResponse + | ConfidentialLedgerCreateOrUpdateUser200Response + | ConfidentialLedgerCreateOrUpdateUser201Response + | ConfidentialLedgerCreateOrUpdateUserDefaultResponse +): response is + | ConfidentialLedgerListCollectionsDefaultResponse + | ConfidentialLedgerGetEnclaveQuotesDefaultResponse + | ConfidentialLedgerGetConstitutionDefaultResponse + | ConfidentialLedgerGetConsortiumMembersDefaultResponse + | ConfidentialLedgerListLedgerEntriesDefaultResponse + | ConfidentialLedgerCreateLedgerEntryDefaultResponse + | ConfidentialLedgerGetLedgerEntryDefaultResponse + | ConfidentialLedgerGetReceiptDefaultResponse + | ConfidentialLedgerGetTransactionStatusDefaultResponse + | ConfidentialLedgerGetCurrentLedgerEntryDefaultResponse + | ConfidentialLedgerDeleteUserDefaultResponse + | ConfidentialLedgerGetUserDefaultResponse + | ConfidentialLedgerCreateOrUpdateUserDefaultResponse { + const lroOriginal = response.headers["x-ms-original-url"]; + const url = new URL(lroOriginal ?? response.request.url); + const method = response.request.method; + let pathDetails = responseMap[`${method} ${url.pathname}`]; + if (!pathDetails) { + pathDetails = geParametrizedPathSuccess(method, url.pathname); + } + return !pathDetails.includes(response.status); +} + +function geParametrizedPathSuccess(method: string, path: string): string[] { + const pathParts = path.split("/"); + + // Iterate the responseMap to find a match + for (const [key, value] of Object.entries(responseMap)) { + // Extracting the path from the map key which is in format + // GET /path/foo + if (!key.startsWith(method)) { + continue; + } + const candidatePath = getPathFromMapKey(key); + // Get each part of the url path + const candidateParts = candidatePath.split("/"); + + // If the candidate and actual paths don't match in size + // we move on to the next candidate path + if ( + candidateParts.length === pathParts.length && + hasParametrizedPath(key) + ) { + // track if we have found a match to return the values found. + let found = true; + for (let i = 0; i < candidateParts.length; i++) { + if ( + candidateParts[i]?.startsWith("{") && + candidateParts[i]?.endsWith("}") + ) { + // If the current part of the candidate is a "template" part + // it is a match with the actual path part on hand + // skip as the parameterized part can match anything + continue; + } + + // If the candidate part is not a template and + // the parts don't match mark the candidate as not found + // to move on with the next candidate path. + if (candidateParts[i] !== pathParts[i]) { + found = false; + break; + } + } + + // We finished evaluating the current candidate parts + // if all parts matched we return the success values form + // the path mapping. + if (found) { + return value; + } + } + } + + // No match was found, return an empty array. + return []; +} + +function hasParametrizedPath(path: string): boolean { + return path.includes("/{"); +} + +function getPathFromMapKey(mapKey: string): string { + const pathStart = mapKey.indexOf("/"); + return mapKey.slice(pathStart); +} diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/src/models.ts b/sdk/confidentialledger/azure-confidentialledger-rest/src/models.ts new file mode 100644 index 000000000000..29d0cf5f88cd --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/src/models.ts @@ -0,0 +1,19 @@ +export interface LedgerEntry { + /** Contents of the ledger entry. */ + contents: string; + collectionId: string; + /** A unique identifier for the state of the ledger. If returned as part of a LedgerEntry, it indicates the state from which the entry was read. */ + transactionId: string; +} + +/** Details about a Confidential ledger user. */ +export interface LedgerUser { + /** The user id, either an AAD object ID or certificate fingerprint. */ + userId: string; + /** + * The user's assigned role. + * + * Possible values: Administrator, Contributor, Reader + */ + assignedRole: string; +} diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/src/outputModels.ts b/sdk/confidentialledger/azure-confidentialledger-rest/src/outputModels.ts new file mode 100644 index 000000000000..53d7a0ed561b --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/src/outputModels.ts @@ -0,0 +1,85 @@ +/** Identifier for collections. */ +export interface CollectionModelOutput { + collectionId: string; +} + +/** A response containing error details. */ +export interface ErrorResponseOutput { + /** The error object. */ + error: ErrorModelOutput; +} + +/** The error object. */ +export interface ErrorModelOutput { + /** One of a server-defined set of error codes. */ + code: string; + /** A human-readable representation of the error. */ + message: string; + /** The target of the error. */ + target?: string; + /** An array of details about specific errors that led to this reported error. */ + details: Array; + /** An object containing more specific information than the current object about the error. */ + innererror?: InnerErrorOutput; +} + +/** An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. */ +export interface InnerErrorOutput { + /** One of a server-defined set of error codes. */ + code: string; + /** Inner error. */ + innererror?: InnerErrorOutput; +} + +/** Paginated ledger entries returned in response to a query. */ +export interface PagedLedgerEntriesOutput { + /** Array of ledger entries. */ + entries: Array; + /** + * State of the ledger query. + * + * Possible values: Loading, Ready + */ + state: string; + /** Path from which to retrieve the next page of results. */ + nextLink?: string; +} + +export interface LedgerEntryOutput { + /** Contents of the ledger entry. */ + contents: string; + collectionId: string; + /** A unique identifier for the state of the ledger. If returned as part of a LedgerEntry, it indicates the state from which the entry was read. */ + transactionId: string; +} + +/** A receipt certifying the transaction at the specified id. */ +export interface TransactionReceiptOutput { + receipt: ReceiptContentsOutput; + /** Possible values: Loading, Ready */ + state: string; + /** A unique identifier for the state of the ledger. If returned as part of a LedgerEntry, it indicates the state from which the entry was read. */ + transactionId: string; +} + +export interface ReceiptContentsOutput {} + +/** Response returned to a query for the transaction status. */ +export interface TransactionStatusOutput { + /** Possible values: Committed, Pending */ + state: string; + /** A unique identifier for the state of the ledger. If returned as part of a LedgerEntry, it indicates the state from which the entry was read. */ + transactionId: string; +} + +/** Details about a Confidential ledger user. */ +export interface LedgerUserOutput { + /** The user id, either an AAD object ID or certificate fingerprint. */ + userId: string; + /** + * The user's assigned role. + * + * Possible values: Administrator, Contributor, Reader + */ + assignedRole: string; +} diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/src/paginateHelper.ts b/sdk/confidentialledger/azure-confidentialledger-rest/src/paginateHelper.ts new file mode 100644 index 000000000000..66b3d6583dee --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/src/paginateHelper.ts @@ -0,0 +1,201 @@ +import { + getPagedAsyncIterator, + PagedAsyncIterableIterator, + PagedResult, +} from "@azure/core-paging"; +import { + Client, + createRestError, + PathUncheckedResponse, +} from "@azure-rest/core-client"; + +/** + * Helper type to extract the type of an array + */ +export type GetArrayType = T extends Array ? TData : never; + +/** + * The type of a custom function that defines how to get a page and a link to the next one if any. + */ +export type GetPage = ( + pageLink: string, + maxPageSize?: number +) => Promise<{ + page: TPage; + nextPageLink?: string; +}>; + +/** + * Options for the paging helper + */ +export interface PagingOptions { + /** + * Custom function to extract pagination details for crating the PagedAsyncIterableIterator + */ + customGetPage?: GetPage[]>; +} + +/** + * Helper type to infer the Type of the paged elements from the response type + * This type is generated based on the swagger information for x-ms-pageable + * specifically on the itemName property which indicates the property of the response + * where the page items are found. The default value is `value`. + * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter + */ +export type PaginateReturn = TResult extends + | { + body: { value?: infer TPage }; + } + | { + body: { entries?: infer TPage }; + } + ? GetArrayType + : Array; + +/** + * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension + * @param client - Client to use for sending the next page requests + * @param initialResponse - Initial response containing the nextLink and current page of elements + * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results + * @returns - PagedAsyncIterableIterator to iterate the elements + */ +export function paginate( + client: Client, + initialResponse: TResponse, + options: PagingOptions = {} +): PagedAsyncIterableIterator> { + // Extract element type from initial response + type TElement = PaginateReturn; + let firstRun = true; + // We need to check the response for success before trying to inspect it looking for + // the properties to use for nextLink and itemName + checkPagingRequest(initialResponse); + const { itemName, nextLinkName } = getPaginationProperties(initialResponse); + const { customGetPage } = options; + const pagedResult: PagedResult = { + firstPageLink: "", + getPage: + typeof customGetPage === "function" + ? customGetPage + : async (pageLink: string) => { + const result = firstRun + ? initialResponse + : await client.pathUnchecked(pageLink).get(); + firstRun = false; + checkPagingRequest(result); + const nextLink = getNextLink(result.body, nextLinkName); + const values = getElements(result.body, itemName); + return { + page: values, + nextPageLink: nextLink, + }; + }, + }; + + return getPagedAsyncIterator(pagedResult); +} + +/** + * Gets for the value of nextLink in the body + */ +function getNextLink(body: unknown, nextLinkName?: string): string | undefined { + if (!nextLinkName) { + return undefined; + } + + const nextLink = (body as Record)[nextLinkName]; + + if (typeof nextLink !== "string" && typeof nextLink !== "undefined") { + throw new Error( + `Body Property ${nextLinkName} should be a string or undefined` + ); + } + + return nextLink; +} + +/** + * Gets the elements of the current request in the body. + */ +function getElements(body: unknown, itemName: string): T[] { + const value = (body as Record)[itemName] as T[]; + + // value has to be an array according to the x-ms-pageable extension. + // The fact that this must be an array is used above to calculate the + // type of elements in the page in PaginateReturn + if (!Array.isArray(value)) { + throw new Error( + `Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}` + ); + } + + return value ?? []; +} + +/** + * Checks if a request failed + */ +function checkPagingRequest(response: PathUncheckedResponse): void { + const Http2xxStatusCodes = [ + "200", + "201", + "202", + "203", + "204", + "205", + "206", + "207", + "208", + "226", + ]; + if (!Http2xxStatusCodes.includes(response.status)) { + throw createRestError( + `Pagination failed with unexpected statusCode ${response.status}`, + response + ); + } +} + +/** + * Extracts the itemName and nextLinkName from the initial response to use them for pagination + */ +function getPaginationProperties(initialResponse: PathUncheckedResponse) { + // Build a set with the passed custom nextLinkNames + const nextLinkNames = new Set(["nextLink"]); + + // Build a set with the passed custom set of itemNames + const itemNames = new Set(["value", "entries"]); + + let nextLinkName: string | undefined; + let itemName: string | undefined; + + for (const name of nextLinkNames) { + const nextLink = (initialResponse.body as Record)[ + name + ] as string; + if (nextLink) { + nextLinkName = name; + break; + } + } + + for (const name of itemNames) { + const item = (initialResponse.body as Record)[ + name + ] as string; + if (item) { + itemName = name; + break; + } + } + + if (!itemName) { + throw new Error( + `Couldn't paginate response\n Body doesn't contain an array property with name: ${[ + ...itemNames, + ].join(" OR ")}` + ); + } + + return { itemName, nextLinkName }; +} diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/src/parameters.ts b/sdk/confidentialledger/azure-confidentialledger-rest/src/parameters.ts new file mode 100644 index 000000000000..48be572661fe --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/src/parameters.ts @@ -0,0 +1,69 @@ +import { RequestParameters } from "@azure-rest/core-client"; +import { LedgerEntry, LedgerUser } from "./models"; + +export type ConfidentialLedgerListCollectionsParameters = RequestParameters; +export type ConfidentialLedgerGetEnclaveQuotesParameters = RequestParameters; +export type ConfidentialLedgerGetConstitutionParameters = RequestParameters; +export type ConfidentialLedgerGetConsortiumMembersParameters = + RequestParameters; +export type ConfidentialLedgerListLedgerEntriesParameters = RequestParameters; + +export interface ConfidentialLedgerCreateLedgerEntryBodyParam { + body?: LedgerEntry; +} + +export interface ConfidentialLedgerCreateLedgerEntryQueryParamProperties { + /** The collection id. */ + collectionId?: string; +} + +export interface ConfidentialLedgerCreateLedgerEntryQueryParam { + queryParameters?: ConfidentialLedgerCreateLedgerEntryQueryParamProperties; +} + +export type ConfidentialLedgerCreateLedgerEntryParameters = + ConfidentialLedgerCreateLedgerEntryQueryParam & + ConfidentialLedgerCreateLedgerEntryBodyParam & + RequestParameters; + +export interface ConfidentialLedgerGetLedgerEntryQueryParamProperties { + /** The collection id. */ + collectionId?: string; +} + +export interface ConfidentialLedgerGetLedgerEntryQueryParam { + queryParameters?: ConfidentialLedgerGetLedgerEntryQueryParamProperties; +} + +export type ConfidentialLedgerGetLedgerEntryParameters = + ConfidentialLedgerGetLedgerEntryQueryParam & RequestParameters; +export type ConfidentialLedgerGetReceiptParameters = RequestParameters; +export type ConfidentialLedgerGetTransactionStatusParameters = + RequestParameters; + +export interface ConfidentialLedgerGetCurrentLedgerEntryQueryParamProperties { + /** The collection id. */ + collectionId?: string; +} + +export interface ConfidentialLedgerGetCurrentLedgerEntryQueryParam { + queryParameters?: ConfidentialLedgerGetCurrentLedgerEntryQueryParamProperties; +} + +export type ConfidentialLedgerGetCurrentLedgerEntryParameters = + ConfidentialLedgerGetCurrentLedgerEntryQueryParam & RequestParameters; +export type ConfidentialLedgerDeleteUserParameters = RequestParameters; +export type ConfidentialLedgerGetUserParameters = RequestParameters; + +export interface ConfidentialLedgerCreateOrUpdateUserBodyParam { + body?: LedgerUser; +} + +export interface ConfidentialLedgerCreateOrUpdateUserMediaTypesParam { + contentType: "application/merge-patch+json"; +} + +export type ConfidentialLedgerCreateOrUpdateUserParameters = + ConfidentialLedgerCreateOrUpdateUserMediaTypesParam & + ConfidentialLedgerCreateOrUpdateUserBodyParam & + RequestParameters; diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/src/responses.ts b/sdk/confidentialledger/azure-confidentialledger-rest/src/responses.ts new file mode 100644 index 000000000000..fe6dd379529c --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/src/responses.ts @@ -0,0 +1,183 @@ +import { RawHttpHeaders } from "@azure/core-rest-pipeline"; +import { HttpResponse } from "@azure-rest/core-client"; +import { + CollectionModelOutput, + ErrorResponseOutput, + PagedLedgerEntriesOutput, + LedgerEntryOutput, + TransactionReceiptOutput, + TransactionStatusOutput, + LedgerUserOutput, +} from "./outputModels"; + +/** The request has succeeded. */ +export interface ConfidentialLedgerListCollections200Response + extends HttpResponse { + status: "200"; + body: Array; +} + +export interface ConfidentialLedgerListCollectionsDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The request has succeeded. */ +export interface ConfidentialLedgerGetEnclaveQuotes200Response + extends HttpResponse { + status: "200"; +} + +export interface ConfidentialLedgerGetEnclaveQuotesDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The request has succeeded. */ +export interface ConfidentialLedgerGetConstitution200Response + extends HttpResponse { + status: "200"; +} + +export interface ConfidentialLedgerGetConstitutionDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The request has succeeded. */ +export interface ConfidentialLedgerGetConsortiumMembers200Response + extends HttpResponse { + status: "200"; +} + +export interface ConfidentialLedgerGetConsortiumMembersDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The request has succeeded. */ +export interface ConfidentialLedgerListLedgerEntries200Response + extends HttpResponse { + status: "200"; + body: PagedLedgerEntriesOutput; +} + +export interface ConfidentialLedgerListLedgerEntriesDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +export interface ConfidentialLedgerCreateLedgerEntry201Headers { + location: string; +} + +/** The request has succeeded and a new resource has been created as a result. */ +export interface ConfidentialLedgerCreateLedgerEntry201Response + extends HttpResponse { + status: "201"; + headers: RawHttpHeaders & ConfidentialLedgerCreateLedgerEntry201Headers; +} + +export interface ConfidentialLedgerCreateLedgerEntryDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The request has succeeded. */ +export interface ConfidentialLedgerGetLedgerEntry200Response + extends HttpResponse { + status: "200"; + body: LedgerEntryOutput; +} + +export interface ConfidentialLedgerGetLedgerEntryDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The request has succeeded. */ +export interface ConfidentialLedgerGetReceipt200Response extends HttpResponse { + status: "200"; + body: TransactionReceiptOutput; +} + +export interface ConfidentialLedgerGetReceiptDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The request has succeeded. */ +export interface ConfidentialLedgerGetTransactionStatus200Response + extends HttpResponse { + status: "200"; + body: TransactionStatusOutput; +} + +export interface ConfidentialLedgerGetTransactionStatusDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The request has succeeded. */ +export interface ConfidentialLedgerGetCurrentLedgerEntry200Response + extends HttpResponse { + status: "200"; + body: LedgerEntryOutput; +} + +export interface ConfidentialLedgerGetCurrentLedgerEntryDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** There is no content to send for this request, but the headers may be useful. */ +export interface ConfidentialLedgerDeleteUser204Response extends HttpResponse { + status: "204"; +} + +export interface ConfidentialLedgerDeleteUserDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The request has succeeded. */ +export interface ConfidentialLedgerGetUser200Response extends HttpResponse { + status: "200"; + body: LedgerUserOutput; +} + +export interface ConfidentialLedgerGetUserDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The request has succeeded. */ +export interface ConfidentialLedgerCreateOrUpdateUser200Response + extends HttpResponse { + status: "200"; + body: LedgerUserOutput; +} + +/** The request has succeeded and a new resource has been created as a result. */ +export interface ConfidentialLedgerCreateOrUpdateUser201Response + extends HttpResponse { + status: "201"; + body: LedgerUserOutput; +} + +export interface ConfidentialLedgerCreateOrUpdateUserDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/test/public/sampleTest.spec.ts b/sdk/confidentialledger/azure-confidentialledger-rest/test/public/sampleTest.spec.ts new file mode 100644 index 000000000000..045e8b6b84c0 --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/test/public/sampleTest.spec.ts @@ -0,0 +1,20 @@ +import { Recorder } from "@azure-tools/test-recorder"; +import { assert } from "chai"; +import { createRecorder } from "./utils/recordedClient"; +import { Context } from "mocha"; + +describe("My test", () => { + let recorder: Recorder; + + beforeEach(async function (this: Context) { + recorder = await createRecorder(this); + }); + + afterEach(async function () { + await recorder.stop(); + }); + + it("sample test", async function () { + assert.equal(1, 1); + }); +}); diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/test/public/utils/env.browser.ts b/sdk/confidentialledger/azure-confidentialledger-rest/test/public/utils/env.browser.ts new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/test/public/utils/env.ts b/sdk/confidentialledger/azure-confidentialledger-rest/test/public/utils/env.ts new file mode 100644 index 000000000000..9b227fea7360 --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/test/public/utils/env.ts @@ -0,0 +1,3 @@ +import * as dotenv from "dotenv"; + +dotenv.config(); diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/test/public/utils/recordedClient.ts b/sdk/confidentialledger/azure-confidentialledger-rest/test/public/utils/recordedClient.ts new file mode 100644 index 000000000000..603a473a4d05 --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/test/public/utils/recordedClient.ts @@ -0,0 +1,26 @@ +import { Context } from "mocha"; +import { Recorder, RecorderStartOptions } from "@azure-tools/test-recorder"; +import "./env"; + +const envSetupForPlayback: Record = { + ENDPOINT: "https://endpoint", + AZURE_CLIENT_ID: "azure_client_id", + AZURE_CLIENT_SECRET: "azure_client_secret", + AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888", + SUBSCRIPTION_ID: "azure_subscription_id", +}; + +const recorderEnvSetup: RecorderStartOptions = { + envSetupForPlayback, +}; + +/** + * creates the recorder and reads the environment variables from the `.env` file. + * Should be called first in the test suite to make sure environment variables are + * read before they are being used. + */ +export async function createRecorder(context: Context): Promise { + const recorder = new Recorder(context.currentTest); + await recorder.start(recorderEnvSetup); + return recorder; +} diff --git a/sdk/confidentialledger/azure-confidentialledger-rest/tsconfig.json b/sdk/confidentialledger/azure-confidentialledger-rest/tsconfig.json new file mode 100644 index 000000000000..d5bf593423c9 --- /dev/null +++ b/sdk/confidentialledger/azure-confidentialledger-rest/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../../tsconfig.package", + "compilerOptions": { + "outDir": "./dist-esm", + "declarationDir": "./types" + }, + "include": [ + "src/**/*.ts", + "./test/**/*.ts" + ] +} \ No newline at end of file diff --git a/sdk/confidentialledger/ci.yml b/sdk/confidentialledger/ci.yml index 5a0497df09c9..0902df87234b 100644 --- a/sdk/confidentialledger/ci.yml +++ b/sdk/confidentialledger/ci.yml @@ -19,6 +19,8 @@ pr: - feature/* - release/* - hotfix/* + exclude: + - feature/v4 paths: include: - sdk/confidentialledger/ @@ -32,3 +34,5 @@ extends: Artifacts: - name: azure-rest-confidential-ledger safeName: azurerestconfidentialledger + - name: azure-rest-confidentialledger-test + safeName: azurerestconfidentialledgertest diff --git a/sdk/purview/purview-administration-rest/swagger/README.md b/sdk/purview/purview-administration-rest/swagger/README.md index 10099375fe9a..4f6f98a9c6a9 100644 --- a/sdk/purview/purview-administration-rest/swagger/README.md +++ b/sdk/purview/purview-administration-rest/swagger/README.md @@ -1,35 +1,32 @@ -# Azure Purview Catalog TypeScript Protocol Layer +# JavaScript > see https://aka.ms/autorest ## Configuration -```yaml $(purview-account) == true -title: PurviewAccount -description: Purview Account Client -output-folder: ../src/account -source-code-folder-path: ./ -input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/purview/data-plane/Azure.Analytics.Purview.Account/preview/2019-11-01-preview/account.json -``` - -```yaml $(purview-metadata) == true -title: PurviewMetadataPolicies -description: Purview Metadata Policies Client -output-folder: ../src/metadataPolicies -source-code-folder-path: ./ -input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/purview/data-plane/Azure.Analytics.Purview.MetadataPolicies/preview/2021-07-01-preview/purviewMetadataPolicy.json -``` - - -```yaml -modelerfour.lenient-model-deduplication: true -package-name: "@azure-rest/purview-administration" -generate-metadata: false +```yaml $(multi-client) +package-name: '@azure-rest/purview-administration' +generate-metadata: true license-header: MICROSOFT_MIT_NO_VERSION -package-version: 1.0.0-beta.2 rest-level-client: true add-credentials: true -credential-scopes: "https://purview.azure.net/.default" +credential-scopes: https://purview.azure.net/.default +require: + - https://github.com/Azure/azure-rest-api-specs/blob/9e30496a8803beb5a84909997e5cd7ea0f242fd8/specification/purview/data-plane/administration/readme.md use-extension: - "@autorest/typescript": "latest" + '@autorest/typescript': 6.0.0-beta.20 +tag: false +batch: + - purview-account: true + - purview-metadata: true +``` +```yaml $(purview-account) +output-folder: ../ +source-code-folder-path: ./src/account +title: PurviewAccount +``` +```yaml $(purview-metadata) +output-folder: ../ +source-code-folder-path: ./src/metadataPolicies +title: PurviewMetadataPolicies ```