diff --git a/lib/services/cognitiveServices/qnamaker/LICENSE.txt b/lib/services/cognitiveServices/qnamaker/LICENSE.txt new file mode 100644 index 0000000000..5431ba98b9 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2018 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/lib/services/cognitiveServices/qnamaker/README.md b/lib/services/cognitiveServices/qnamaker/README.md new file mode 100644 index 0000000000..af46fb7df5 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/README.md @@ -0,0 +1,41 @@ +--- +uid: azure-cognitiveservices-qnamaker +summary: *content + +--- +**This SDK will be deprecated next year and will be replaced by a new TypeScript-based isomorphic SDK (found at https://github.com/Azure/azure-sdk-for-js) which works on Node.js and browsers.** +## Microsoft Azure SDK for Node.js - QnAMakerClient +This project provides a Node.js package for accessing Azure. Right now it supports: +- **Node.js version 6.x.x or higher** + +### Features + + +### How to Install + +```bash +npm install azure-cognitiveservices-qnamaker +``` + +### How to use + +#### Authentication, client creation and getKeys endpoint as an example. + +```javascript +const msRest = require("ms-rest"); +const QnAMakerClient = require("azure-cognitiveservices-qnamaker"); +const token = ""; +const creds = new msRest.TokenCredentials(token); +const subscriptionId = ""; +const client = new QnAMakerClient(creds, subscriptionId); +client.endpoint.getKeys().then((result) => { + console.log("The result is:"); + console.log(result); +}).catch((err) => { + console.log('An error occurred:'); + console.dir(err, {depth: null, colors: true}); +}); + +### Related projects + +- [Microsoft Azure SDK for Node.js](https://github.com/Azure/azure-sdk-for-node) diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/alterationsDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/alterationsDTO.js new file mode 100644 index 0000000000..dc52b0836d --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/alterationsDTO.js @@ -0,0 +1,59 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Collection of words that are synonyms. + * + */ +class AlterationsDTO { + /** + * Create a AlterationsDTO. + * @property {array} alterations Words that are synonymous with each other. + */ + constructor() { + } + + /** + * Defines the metadata of AlterationsDTO + * + * @returns {object} metadata of AlterationsDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'AlterationsDTO', + type: { + name: 'Composite', + className: 'AlterationsDTO', + modelProperties: { + alterations: { + required: true, + serializedName: 'alterations', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + } + } + } + }; + } +} + +module.exports = AlterationsDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/createKbDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/createKbDTO.js new file mode 100644 index 0000000000..eafdb34120 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/createKbDTO.js @@ -0,0 +1,104 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Post body schema for CreateKb operation. + * + */ +class CreateKbDTO { + /** + * Create a CreateKbDTO. + * @property {string} name Friendly name for the knowledgebase. + * @property {array} [qnaList] List of Q-A (QnADTO) to be added to the + * knowledgebase. Q-A Ids are assigned by the service and should be omitted. + * @property {array} [urls] List of URLs to be used for extracting Q-A. + * @property {array} [files] List of files from which to Extract Q-A. + */ + constructor() { + } + + /** + * Defines the metadata of CreateKbDTO + * + * @returns {object} metadata of CreateKbDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'CreateKbDTO', + type: { + name: 'Composite', + className: 'CreateKbDTO', + modelProperties: { + name: { + required: true, + serializedName: 'name', + constraints: { + MaxLength: 100, + MinLength: 1 + }, + type: { + name: 'String' + } + }, + qnaList: { + required: false, + serializedName: 'qnaList', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'QnADTOElementType', + type: { + name: 'Composite', + className: 'QnADTO' + } + } + } + }, + urls: { + required: false, + serializedName: 'urls', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + }, + files: { + required: false, + serializedName: 'files', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'FileDTOElementType', + type: { + name: 'Composite', + className: 'FileDTO' + } + } + } + } + } + } + }; + } +} + +module.exports = CreateKbDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/createKbInputDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/createKbInputDTO.js new file mode 100644 index 0000000000..5dea34b93a --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/createKbInputDTO.js @@ -0,0 +1,92 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Input to create KB. + * + */ +class CreateKbInputDTO { + /** + * Create a CreateKbInputDTO. + * @property {array} [qnaList] List of QNA to be added to the index. Ids are + * generated by the service and should be omitted. + * @property {array} [urls] List of URLs to be added to knowledgebase. + * @property {array} [files] List of files to be added to knowledgebase. + */ + constructor() { + } + + /** + * Defines the metadata of CreateKbInputDTO + * + * @returns {object} metadata of CreateKbInputDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'CreateKbInputDTO', + type: { + name: 'Composite', + className: 'CreateKbInputDTO', + modelProperties: { + qnaList: { + required: false, + serializedName: 'qnaList', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'QnADTOElementType', + type: { + name: 'Composite', + className: 'QnADTO' + } + } + } + }, + urls: { + required: false, + serializedName: 'urls', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + }, + files: { + required: false, + serializedName: 'files', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'FileDTOElementType', + type: { + name: 'Composite', + className: 'FileDTO' + } + } + } + } + } + } + }; + } +} + +module.exports = CreateKbInputDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/deleteKbContentsDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/deleteKbContentsDTO.js new file mode 100644 index 0000000000..768bb3463e --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/deleteKbContentsDTO.js @@ -0,0 +1,75 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * PATCH body schema of Delete Operation in UpdateKb + * + */ +class DeleteKbContentsDTO { + /** + * Create a DeleteKbContentsDTO. + * @property {array} [ids] List of Qna Ids to be deleted + * @property {array} [sources] List of sources to be deleted from + * knowledgebase. + */ + constructor() { + } + + /** + * Defines the metadata of DeleteKbContentsDTO + * + * @returns {object} metadata of DeleteKbContentsDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'DeleteKbContentsDTO', + type: { + name: 'Composite', + className: 'DeleteKbContentsDTO', + modelProperties: { + ids: { + required: false, + serializedName: 'ids', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'NumberElementType', + type: { + name: 'Number' + } + } + } + }, + sources: { + required: false, + serializedName: 'sources', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + } + } + } + }; + } +} + +module.exports = DeleteKbContentsDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/endpointKeysDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/endpointKeysDTO.js new file mode 100644 index 0000000000..f38f76c070 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/endpointKeysDTO.js @@ -0,0 +1,76 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Schema for EndpointKeys generate/refresh operations. + * + */ +class EndpointKeysDTO { + /** + * Create a EndpointKeysDTO. + * @property {string} [primaryEndpointKey] Primary Access Key. + * @property {string} [secondaryEndpointKey] Secondary Access Key. + * @property {string} [installedVersion] Current version of runtime. + * @property {string} [lastStableVersion] Latest version of runtime. + */ + constructor() { + } + + /** + * Defines the metadata of EndpointKeysDTO + * + * @returns {object} metadata of EndpointKeysDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'EndpointKeysDTO', + type: { + name: 'Composite', + className: 'EndpointKeysDTO', + modelProperties: { + primaryEndpointKey: { + required: false, + serializedName: 'primaryEndpointKey', + type: { + name: 'String' + } + }, + secondaryEndpointKey: { + required: false, + serializedName: 'secondaryEndpointKey', + type: { + name: 'String' + } + }, + installedVersion: { + required: false, + serializedName: 'installedVersion', + type: { + name: 'String' + } + }, + lastStableVersion: { + required: false, + serializedName: 'lastStableVersion', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = EndpointKeysDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/errorModel.js b/lib/services/cognitiveServices/qnamaker/lib/models/errorModel.js new file mode 100644 index 0000000000..e35537d227 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/errorModel.js @@ -0,0 +1,105 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * The error object. As per Microsoft One API guidelines - + * https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. + * + */ +class ErrorModel { + /** + * Create a ErrorModel. + * @property {string} code One of a server-defined set of error codes. + * Possible values include: 'BadArgument', 'Forbidden', 'NotFound', + * 'KbNotFound', 'Unauthorized', 'Unspecified', 'EndpointKeysError', + * 'QuotaExceeded', 'QnaRuntimeError', 'SKULimitExceeded', + * 'OperationNotFound', 'ServiceError', 'ValidationFailure', + * 'ExtractionFailure' + * @property {string} [message] A human-readable representation of the error. + * @property {string} [target] The target of the error. + * @property {array} [details] An array of details about specific errors that + * led to this reported error. + * @property {object} [innerError] An object containing more specific + * information than the current object about the error. + * @property {string} [innerError.code] A more specific error code than was + * provided by the containing error. + * @property {object} [innerError.innerError] An object containing more + * specific information than the current object about the error. + */ + constructor() { + } + + /** + * Defines the metadata of ErrorModel + * + * @returns {object} metadata of ErrorModel + * + */ + mapper() { + return { + required: false, + serializedName: 'Error', + type: { + name: 'Composite', + className: 'ErrorModel', + modelProperties: { + code: { + required: true, + serializedName: 'code', + type: { + name: 'String' + } + }, + message: { + required: false, + serializedName: 'message', + type: { + name: 'String' + } + }, + target: { + required: false, + serializedName: 'target', + type: { + name: 'String' + } + }, + details: { + required: false, + serializedName: 'details', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'ErrorModelElementType', + type: { + name: 'Composite', + className: 'ErrorModel' + } + } + } + }, + innerError: { + required: false, + serializedName: 'innerError', + type: { + name: 'Composite', + className: 'InnerErrorModel' + } + } + } + } + }; + } +} + +module.exports = ErrorModel; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/errorResponse.js b/lib/services/cognitiveServices/qnamaker/lib/models/errorResponse.js new file mode 100644 index 0000000000..1b381d0ddc --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/errorResponse.js @@ -0,0 +1,54 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Error response. As per Microsoft One API guidelines - + * https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. + * + */ +class ErrorResponse { + /** + * Create a ErrorResponse. + * @property {object} [error] The error object. + */ + constructor() { + } + + /** + * Defines the metadata of ErrorResponse + * + * @returns {object} metadata of ErrorResponse + * + */ + mapper() { + return { + required: false, + serializedName: 'ErrorResponse', + type: { + name: 'Composite', + className: 'ErrorResponse', + modelProperties: { + error: { + required: false, + serializedName: 'error', + type: { + name: 'Composite', + className: 'ErrorResponseError' + } + } + } + } + }; + } +} + +module.exports = ErrorResponse; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/errorResponseError.js b/lib/services/cognitiveServices/qnamaker/lib/models/errorResponseError.js new file mode 100644 index 0000000000..16f5f8146f --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/errorResponseError.js @@ -0,0 +1,92 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +const models = require('./index'); + +/** + * The error object. + * + * @extends models['ErrorModel'] + */ +class ErrorResponseError extends models['ErrorModel'] { + /** + * Create a ErrorResponseError. + */ + constructor() { + super(); + } + + /** + * Defines the metadata of ErrorResponseError + * + * @returns {object} metadata of ErrorResponseError + * + */ + mapper() { + return { + required: false, + serializedName: 'ErrorResponse_error', + type: { + name: 'Composite', + className: 'ErrorResponseError', + modelProperties: { + code: { + required: true, + serializedName: 'code', + type: { + name: 'String' + } + }, + message: { + required: false, + serializedName: 'message', + type: { + name: 'String' + } + }, + target: { + required: false, + serializedName: 'target', + type: { + name: 'String' + } + }, + details: { + required: false, + serializedName: 'details', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'ErrorModelElementType', + type: { + name: 'Composite', + className: 'ErrorModel' + } + } + } + }, + innerError: { + required: false, + serializedName: 'innerError', + type: { + name: 'Composite', + className: 'InnerErrorModel' + } + } + } + } + }; + } +} + +module.exports = ErrorResponseError; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/fileDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/fileDTO.js new file mode 100644 index 0000000000..3e188d7629 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/fileDTO.js @@ -0,0 +1,65 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * DTO to hold details of uploaded files. + * + */ +class FileDTO { + /** + * Create a FileDTO. + * @property {string} fileName File name. Supported file types are ".tsv", + * ".pdf", ".txt", ".docx", ".xlsx". + * @property {string} fileUri Public URI of the file. + */ + constructor() { + } + + /** + * Defines the metadata of FileDTO + * + * @returns {object} metadata of FileDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'FileDTO', + type: { + name: 'Composite', + className: 'FileDTO', + modelProperties: { + fileName: { + required: true, + serializedName: 'fileName', + constraints: { + MaxLength: 200, + MinLength: 1 + }, + type: { + name: 'String' + } + }, + fileUri: { + required: true, + serializedName: 'fileUri', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = FileDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/index.d.ts b/lib/services/cognitiveServices/qnamaker/lib/models/index.d.ts new file mode 100644 index 0000000000..dc5acc9389 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/index.d.ts @@ -0,0 +1,452 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import * as moment from "moment"; + +/** + * Input to create KB. + */ +export interface CreateKbInputDTO { + /** + * List of QNA to be added to the index. Ids are generated by the service and should be omitted. + */ + qnaList?: QnADTO[]; + /** + * List of URLs to be added to knowledgebase. + */ + urls?: string[]; + /** + * List of files to be added to knowledgebase. + */ + files?: FileDTO[]; +} + +/** + * An instance of CreateKbInputDTO for add operation + */ +export interface UpdateKbOperationDTOAdd extends CreateKbInputDTO { +} + +/** + * PATCH body schema of Delete Operation in UpdateKb + */ +export interface DeleteKbContentsDTO { + /** + * List of Qna Ids to be deleted + */ + ids?: number[]; + /** + * List of sources to be deleted from knowledgebase. + */ + sources?: string[]; +} + +/** + * An instance of DeleteKbContentsDTO for delete Operation + */ +export interface UpdateKbOperationDTODelete extends DeleteKbContentsDTO { +} + +/** + * PATCH body schema for Update operation in Update Kb + */ +export interface UpdateKbContentsDTO { + /** + * Friendly name for the knowledgebase. + */ + name?: string; + /** + * List of Q-A (UpdateQnaDTO) to be added to the knowledgebase. + */ + qnaList?: UpdateQnaDTO[]; + /** + * List of existing URLs to be refreshed. The content will be extracted again and re-indexed. + */ + urls?: string[]; +} + +/** + * An instance of UpdateKbContentsDTO for Update Operation + */ +export interface UpdateKbOperationDTOUpdate extends UpdateKbContentsDTO { +} + +/** + * Contains list of QnAs to be updated + */ +export interface UpdateKbOperationDTO { + /** + * An instance of CreateKbInputDTO for add operation + */ + add?: UpdateKbOperationDTOAdd; + /** + * An instance of DeleteKbContentsDTO for delete Operation + */ + deleteProperty?: UpdateKbOperationDTODelete; + /** + * An instance of UpdateKbContentsDTO for Update Operation + */ + update?: UpdateKbOperationDTOUpdate; +} + +/** + * PATCH Body schema for Update Kb which contains list of questions to be added and deleted + */ +export interface UpdateQuestionsDTO { + /** + * List of questions to be added + */ + add?: string[]; + /** + * List of questions to be deleted. + */ + deleteProperty?: string[]; +} + +/** + * List of questions associated with the answer. + */ +export interface UpdateQnaDTOQuestions extends UpdateQuestionsDTO { +} + +/** + * PATCH Body schema to represent list of Metadata to be updated + */ +export interface UpdateMetadataDTO { + /** + * List of Metadata associated with answer to be deleted + */ + deleteProperty?: MetadataDTO[]; + /** + * List of Metadat associated with answer to be added + */ + add?: MetadataDTO[]; +} + +/** + * List of metadata associated with the answer to be updated + */ +export interface UpdateQnaDTOMetadata extends UpdateMetadataDTO { +} + +/** + * PATCH Body schema for Update Qna List + */ +export interface UpdateQnaDTO { + /** + * Unique id for the Q-A + */ + id?: number; + /** + * Answer text + */ + answer?: string; + /** + * Source from which Q-A was indexed. eg. + * https://docs.microsoft.com/en-us/azure/cognitive-services/QnAMaker/FAQs + */ + source?: string; + /** + * List of questions associated with the answer. + */ + questions?: UpdateQnaDTOQuestions; + /** + * List of metadata associated with the answer to be updated + */ + metadata?: UpdateQnaDTOMetadata; +} + +/** + * Name - value pair of metadata. + */ +export interface MetadataDTO { + /** + * Metadata name. + */ + name: string; + /** + * Metadata value. + */ + value: string; +} + +/** + * Q-A object. + */ +export interface QnADTO { + /** + * Unique id for the Q-A. + */ + id?: number; + /** + * Answer text + */ + answer: string; + /** + * Source from which Q-A was indexed. eg. + * https://docs.microsoft.com/en-us/azure/cognitive-services/QnAMaker/FAQs + */ + source?: string; + /** + * List of questions associated with the answer. + */ + questions: string[]; + /** + * List of metadata associated with the answer. + */ + metadata?: MetadataDTO[]; +} + +/** + * DTO to hold details of uploaded files. + */ +export interface FileDTO { + /** + * File name. Supported file types are ".tsv", ".pdf", ".txt", ".docx", ".xlsx". + */ + fileName: string; + /** + * Public URI of the file. + */ + fileUri: string; +} + +/** + * List of QnADTO + */ +export interface QnADocumentsDTO { + /** + * List of answers. + */ + qnaDocuments?: QnADTO[]; +} + +/** + * Post body schema for CreateKb operation. + */ +export interface CreateKbDTO { + /** + * Friendly name for the knowledgebase. + */ + name: string; + /** + * List of Q-A (QnADTO) to be added to the knowledgebase. Q-A Ids are assigned by the service and + * should be omitted. + */ + qnaList?: QnADTO[]; + /** + * List of URLs to be used for extracting Q-A. + */ + urls?: string[]; + /** + * List of files from which to Extract Q-A. + */ + files?: FileDTO[]; +} + +/** + * Post body schema for Replace KB operation. + */ +export interface ReplaceKbDTO { + /** + * List of Q-A (QnADTO) to be added to the knowledgebase. Q-A Ids are assigned by the service and + * should be omitted. + */ + qnAList: QnADTO[]; +} + +/** + * The error object. As per Microsoft One API guidelines - + * https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. + */ +export interface ErrorModel { + /** + * One of a server-defined set of error codes. Possible values include: 'BadArgument', + * 'Forbidden', 'NotFound', 'KbNotFound', 'Unauthorized', 'Unspecified', 'EndpointKeysError', + * 'QuotaExceeded', 'QnaRuntimeError', 'SKULimitExceeded', 'OperationNotFound', 'ServiceError', + * 'ValidationFailure', 'ExtractionFailure' + */ + 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?: ErrorModel[]; + /** + * An object containing more specific information than the current object about the error. + */ + innerError?: InnerErrorModel; +} + +/** + * The error object. + */ +export interface ErrorResponseError extends ErrorModel { +} + +/** + * Error response. As per Microsoft One API guidelines - + * https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. + */ +export interface ErrorResponse { + /** + * The error object. + */ + error?: ErrorResponseError; +} + +/** + * 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 InnerErrorModel { + /** + * A more specific error code than was provided by the containing error. + */ + code?: string; + /** + * An object containing more specific information than the current object about the error. + */ + innerError?: InnerErrorModel; +} + +/** + * Record to track long running operation. + */ +export interface Operation { + /** + * Operation state. Possible values include: 'Failed', 'NotStarted', 'Running', 'Succeeded' + */ + operationState?: string; + /** + * Timestamp when the operation was created. + */ + createdTimestamp?: string; + /** + * Timestamp when the current state was entered. + */ + lastActionTimestamp?: string; + /** + * Relative URI to the target resource location for completed resources. + */ + resourceLocation?: string; + /** + * User Id + */ + userId?: string; + /** + * Operation Id. + */ + operationId?: string; + /** + * Error details in case of failures. + */ + errorResponse?: ErrorResponse; +} + +/** + * Response schema for CreateKb operation. + */ +export interface KnowledgebaseDTO { + /** + * Unique id that identifies a knowledgebase. + */ + id?: string; + /** + * URL host name at which the knowledgebase is hosted. + */ + hostName?: string; + /** + * Time stamp at which the knowledgebase was last accessed (UTC). + */ + lastAccessedTimestamp?: string; + /** + * Time stamp at which the knowledgebase was last modified (UTC). + */ + lastChangedTimestamp?: string; + /** + * Time stamp at which the knowledgebase was last published (UTC). + */ + lastPublishedTimestamp?: string; + /** + * Friendly name of the knowledgebase. + */ + name?: string; + /** + * User who created / owns the knowledgebase. + */ + userId?: string; + /** + * URL sources from which Q-A were extracted and added to the knowledgebase. + */ + urls?: string[]; + /** + * Custom sources from which Q-A were extracted or explicitly added to the knowledgebase. + */ + sources?: string[]; +} + +/** + * Collection of knowledgebases owned by a user. + */ +export interface KnowledgebasesDTO { + /** + * Collection of knowledgebase records. + */ + knowledgebases?: KnowledgebaseDTO[]; +} + +/** + * Collection of words that are synonyms. + */ +export interface AlterationsDTO { + /** + * Words that are synonymous with each other. + */ + alterations: string[]; +} + +/** + * Collection of word alterations. + */ +export interface WordAlterationsDTO { + /** + * Collection of word alterations. + */ + wordAlterations: AlterationsDTO[]; +} + +/** + * Schema for EndpointKeys generate/refresh operations. + */ +export interface EndpointKeysDTO { + /** + * Primary Access Key. + */ + primaryEndpointKey?: string; + /** + * Secondary Access Key. + */ + secondaryEndpointKey?: string; + /** + * Current version of runtime. + */ + installedVersion?: string; + /** + * Latest version of runtime. + */ + lastStableVersion?: string; +} diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/index.js b/lib/services/cognitiveServices/qnamaker/lib/models/index.js new file mode 100644 index 0000000000..8c3f801c29 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/index.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +/* jshint latedef:false */ +/* jshint forin:false */ +/* jshint noempty:false */ + +'use strict'; + +exports.CreateKbInputDTO = require('./createKbInputDTO'); +exports.UpdateKbOperationDTOAdd = require('./updateKbOperationDTOAdd'); +exports.DeleteKbContentsDTO = require('./deleteKbContentsDTO'); +exports.UpdateKbOperationDTODelete = require('./updateKbOperationDTODelete'); +exports.UpdateKbContentsDTO = require('./updateKbContentsDTO'); +exports.UpdateKbOperationDTOUpdate = require('./updateKbOperationDTOUpdate'); +exports.UpdateKbOperationDTO = require('./updateKbOperationDTO'); +exports.UpdateQuestionsDTO = require('./updateQuestionsDTO'); +exports.UpdateQnaDTOQuestions = require('./updateQnaDTOQuestions'); +exports.UpdateMetadataDTO = require('./updateMetadataDTO'); +exports.UpdateQnaDTOMetadata = require('./updateQnaDTOMetadata'); +exports.UpdateQnaDTO = require('./updateQnaDTO'); +exports.MetadataDTO = require('./metadataDTO'); +exports.QnADTO = require('./qnADTO'); +exports.FileDTO = require('./fileDTO'); +exports.QnADocumentsDTO = require('./qnADocumentsDTO'); +exports.CreateKbDTO = require('./createKbDTO'); +exports.ReplaceKbDTO = require('./replaceKbDTO'); +exports.ErrorModel = require('./errorModel'); +exports.ErrorResponseError = require('./errorResponseError'); +exports.ErrorResponse = require('./errorResponse'); +exports.InnerErrorModel = require('./innerErrorModel'); +exports.Operation = require('./operation'); +exports.KnowledgebaseDTO = require('./knowledgebaseDTO'); +exports.KnowledgebasesDTO = require('./knowledgebasesDTO'); +exports.AlterationsDTO = require('./alterationsDTO'); +exports.WordAlterationsDTO = require('./wordAlterationsDTO'); +exports.EndpointKeysDTO = require('./endpointKeysDTO'); diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/innerErrorModel.js b/lib/services/cognitiveServices/qnamaker/lib/models/innerErrorModel.js new file mode 100644 index 0000000000..03f3d857a4 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/innerErrorModel.js @@ -0,0 +1,65 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * 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. + * + */ +class InnerErrorModel { + /** + * Create a InnerErrorModel. + * @property {string} [code] A more specific error code than was provided by + * the containing error. + * @property {object} [innerError] An object containing more specific + * information than the current object about the error. + */ + constructor() { + } + + /** + * Defines the metadata of InnerErrorModel + * + * @returns {object} metadata of InnerErrorModel + * + */ + mapper() { + return { + required: false, + serializedName: 'InnerErrorModel', + type: { + name: 'Composite', + className: 'InnerErrorModel', + modelProperties: { + code: { + required: false, + serializedName: 'code', + type: { + name: 'String' + } + }, + innerError: { + required: false, + serializedName: 'innerError', + type: { + name: 'Composite', + className: 'InnerErrorModel' + } + } + } + } + }; + } +} + +module.exports = InnerErrorModel; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/knowledgebaseDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/knowledgebaseDTO.js new file mode 100644 index 0000000000..7a512c8dbf --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/knowledgebaseDTO.js @@ -0,0 +1,136 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Response schema for CreateKb operation. + * + */ +class KnowledgebaseDTO { + /** + * Create a KnowledgebaseDTO. + * @property {string} [id] Unique id that identifies a knowledgebase. + * @property {string} [hostName] URL host name at which the knowledgebase is + * hosted. + * @property {string} [lastAccessedTimestamp] Time stamp at which the + * knowledgebase was last accessed (UTC). + * @property {string} [lastChangedTimestamp] Time stamp at which the + * knowledgebase was last modified (UTC). + * @property {string} [lastPublishedTimestamp] Time stamp at which the + * knowledgebase was last published (UTC). + * @property {string} [name] Friendly name of the knowledgebase. + * @property {string} [userId] User who created / owns the knowledgebase. + * @property {array} [urls] URL sources from which Q-A were extracted and + * added to the knowledgebase. + * @property {array} [sources] Custom sources from which Q-A were extracted + * or explicitly added to the knowledgebase. + */ + constructor() { + } + + /** + * Defines the metadata of KnowledgebaseDTO + * + * @returns {object} metadata of KnowledgebaseDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'KnowledgebaseDTO', + type: { + name: 'Composite', + className: 'KnowledgebaseDTO', + modelProperties: { + id: { + required: false, + serializedName: 'id', + type: { + name: 'String' + } + }, + hostName: { + required: false, + serializedName: 'hostName', + type: { + name: 'String' + } + }, + lastAccessedTimestamp: { + required: false, + serializedName: 'lastAccessedTimestamp', + type: { + name: 'String' + } + }, + lastChangedTimestamp: { + required: false, + serializedName: 'lastChangedTimestamp', + type: { + name: 'String' + } + }, + lastPublishedTimestamp: { + required: false, + serializedName: 'lastPublishedTimestamp', + type: { + name: 'String' + } + }, + name: { + required: false, + serializedName: 'name', + type: { + name: 'String' + } + }, + userId: { + required: false, + serializedName: 'userId', + type: { + name: 'String' + } + }, + urls: { + required: false, + serializedName: 'urls', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + }, + sources: { + required: false, + serializedName: 'sources', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + } + } + } + }; + } +} + +module.exports = KnowledgebaseDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/knowledgebasesDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/knowledgebasesDTO.js new file mode 100644 index 0000000000..4af86e2074 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/knowledgebasesDTO.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Collection of knowledgebases owned by a user. + * + */ +class KnowledgebasesDTO { + /** + * Create a KnowledgebasesDTO. + * @property {array} [knowledgebases] Collection of knowledgebase records. + */ + constructor() { + } + + /** + * Defines the metadata of KnowledgebasesDTO + * + * @returns {object} metadata of KnowledgebasesDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'KnowledgebasesDTO', + type: { + name: 'Composite', + className: 'KnowledgebasesDTO', + modelProperties: { + knowledgebases: { + required: false, + serializedName: 'knowledgebases', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'KnowledgebaseDTOElementType', + type: { + name: 'Composite', + className: 'KnowledgebaseDTO' + } + } + } + } + } + } + }; + } +} + +module.exports = KnowledgebasesDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/metadataDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/metadataDTO.js new file mode 100644 index 0000000000..60864ce8b9 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/metadataDTO.js @@ -0,0 +1,68 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Name - value pair of metadata. + * + */ +class MetadataDTO { + /** + * Create a MetadataDTO. + * @property {string} name Metadata name. + * @property {string} value Metadata value. + */ + constructor() { + } + + /** + * Defines the metadata of MetadataDTO + * + * @returns {object} metadata of MetadataDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'MetadataDTO', + type: { + name: 'Composite', + className: 'MetadataDTO', + modelProperties: { + name: { + required: true, + serializedName: 'name', + constraints: { + MaxLength: 100, + MinLength: 1 + }, + type: { + name: 'String' + } + }, + value: { + required: true, + serializedName: 'value', + constraints: { + MaxLength: 500, + MinLength: 1 + }, + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = MetadataDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/operation.js b/lib/services/cognitiveServices/qnamaker/lib/models/operation.js new file mode 100644 index 0000000000..4651196d68 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/operation.js @@ -0,0 +1,106 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Record to track long running operation. + * + */ +class Operation { + /** + * Create a Operation. + * @property {string} [operationState] Operation state. Possible values + * include: 'Failed', 'NotStarted', 'Running', 'Succeeded' + * @property {string} [createdTimestamp] Timestamp when the operation was + * created. + * @property {string} [lastActionTimestamp] Timestamp when the current state + * was entered. + * @property {string} [resourceLocation] Relative URI to the target resource + * location for completed resources. + * @property {string} [userId] User Id + * @property {string} [operationId] Operation Id. + * @property {object} [errorResponse] Error details in case of failures. + * @property {object} [errorResponse.error] The error object. + */ + constructor() { + } + + /** + * Defines the metadata of Operation + * + * @returns {object} metadata of Operation + * + */ + mapper() { + return { + required: false, + serializedName: 'Operation', + type: { + name: 'Composite', + className: 'Operation', + modelProperties: { + operationState: { + required: false, + serializedName: 'operationState', + type: { + name: 'String' + } + }, + createdTimestamp: { + required: false, + serializedName: 'createdTimestamp', + type: { + name: 'String' + } + }, + lastActionTimestamp: { + required: false, + serializedName: 'lastActionTimestamp', + type: { + name: 'String' + } + }, + resourceLocation: { + required: false, + serializedName: 'resourceLocation', + type: { + name: 'String' + } + }, + userId: { + required: false, + serializedName: 'userId', + type: { + name: 'String' + } + }, + operationId: { + required: false, + serializedName: 'operationId', + type: { + name: 'String' + } + }, + errorResponse: { + required: false, + serializedName: 'errorResponse', + type: { + name: 'Composite', + className: 'ErrorResponse' + } + } + } + } + }; + } +} + +module.exports = Operation; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/qnADTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/qnADTO.js new file mode 100644 index 0000000000..2c8e72fa9c --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/qnADTO.js @@ -0,0 +1,107 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Q-A object. + * + */ +class QnADTO { + /** + * Create a QnADTO. + * @property {number} [id] Unique id for the Q-A. + * @property {string} answer Answer text + * @property {string} [source] Source from which Q-A was indexed. eg. + * https://docs.microsoft.com/en-us/azure/cognitive-services/QnAMaker/FAQs + * @property {array} questions List of questions associated with the answer. + * @property {array} [metadata] List of metadata associated with the answer. + */ + constructor() { + } + + /** + * Defines the metadata of QnADTO + * + * @returns {object} metadata of QnADTO + * + */ + mapper() { + return { + required: false, + serializedName: 'QnADTO', + type: { + name: 'Composite', + className: 'QnADTO', + modelProperties: { + id: { + required: false, + serializedName: 'id', + type: { + name: 'Number' + } + }, + answer: { + required: true, + serializedName: 'answer', + constraints: { + MaxLength: 25000, + MinLength: 1 + }, + type: { + name: 'String' + } + }, + source: { + required: false, + serializedName: 'source', + constraints: { + MaxLength: 300 + }, + type: { + name: 'String' + } + }, + questions: { + required: true, + serializedName: 'questions', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + }, + metadata: { + required: false, + serializedName: 'metadata', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'MetadataDTOElementType', + type: { + name: 'Composite', + className: 'MetadataDTO' + } + } + } + } + } + } + }; + } +} + +module.exports = QnADTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/qnADocumentsDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/qnADocumentsDTO.js new file mode 100644 index 0000000000..e5cdd23e78 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/qnADocumentsDTO.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * List of QnADTO + * + */ +class QnADocumentsDTO { + /** + * Create a QnADocumentsDTO. + * @property {array} [qnaDocuments] List of answers. + */ + constructor() { + } + + /** + * Defines the metadata of QnADocumentsDTO + * + * @returns {object} metadata of QnADocumentsDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'QnADocumentsDTO', + type: { + name: 'Composite', + className: 'QnADocumentsDTO', + modelProperties: { + qnaDocuments: { + required: false, + serializedName: 'qnaDocuments', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'QnADTOElementType', + type: { + name: 'Composite', + className: 'QnADTO' + } + } + } + } + } + } + }; + } +} + +module.exports = QnADocumentsDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/replaceKbDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/replaceKbDTO.js new file mode 100644 index 0000000000..72e21815e7 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/replaceKbDTO.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Post body schema for Replace KB operation. + * + */ +class ReplaceKbDTO { + /** + * Create a ReplaceKbDTO. + * @property {array} qnAList List of Q-A (QnADTO) to be added to the + * knowledgebase. Q-A Ids are assigned by the service and should be omitted. + */ + constructor() { + } + + /** + * Defines the metadata of ReplaceKbDTO + * + * @returns {object} metadata of ReplaceKbDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'ReplaceKbDTO', + type: { + name: 'Composite', + className: 'ReplaceKbDTO', + modelProperties: { + qnAList: { + required: true, + serializedName: 'qnAList', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'QnADTOElementType', + type: { + name: 'Composite', + className: 'QnADTO' + } + } + } + } + } + } + }; + } +} + +module.exports = ReplaceKbDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/updateKbContentsDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/updateKbContentsDTO.js new file mode 100644 index 0000000000..2343750ffd --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/updateKbContentsDTO.js @@ -0,0 +1,85 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * PATCH body schema for Update operation in Update Kb + * + */ +class UpdateKbContentsDTO { + /** + * Create a UpdateKbContentsDTO. + * @property {string} [name] Friendly name for the knowledgebase. + * @property {array} [qnaList] List of Q-A (UpdateQnaDTO) to be added to the + * knowledgebase. + * @property {array} [urls] List of existing URLs to be refreshed. The + * content will be extracted again and re-indexed. + */ + constructor() { + } + + /** + * Defines the metadata of UpdateKbContentsDTO + * + * @returns {object} metadata of UpdateKbContentsDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'UpdateKbContentsDTO', + type: { + name: 'Composite', + className: 'UpdateKbContentsDTO', + modelProperties: { + name: { + required: false, + serializedName: 'name', + type: { + name: 'String' + } + }, + qnaList: { + required: false, + serializedName: 'qnaList', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'UpdateQnaDTOElementType', + type: { + name: 'Composite', + className: 'UpdateQnaDTO' + } + } + } + }, + urls: { + required: false, + serializedName: 'urls', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + } + } + } + }; + } +} + +module.exports = UpdateKbContentsDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/updateKbOperationDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/updateKbOperationDTO.js new file mode 100644 index 0000000000..8e922a4502 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/updateKbOperationDTO.js @@ -0,0 +1,73 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Contains list of QnAs to be updated + * + */ +class UpdateKbOperationDTO { + /** + * Create a UpdateKbOperationDTO. + * @property {object} [add] An instance of CreateKbInputDTO for add operation + * @property {object} [deleteProperty] An instance of DeleteKbContentsDTO for + * delete Operation + * @property {object} [update] An instance of UpdateKbContentsDTO for Update + * Operation + */ + constructor() { + } + + /** + * Defines the metadata of UpdateKbOperationDTO + * + * @returns {object} metadata of UpdateKbOperationDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'UpdateKbOperationDTO', + type: { + name: 'Composite', + className: 'UpdateKbOperationDTO', + modelProperties: { + add: { + required: false, + serializedName: 'add', + type: { + name: 'Composite', + className: 'UpdateKbOperationDTOAdd' + } + }, + deleteProperty: { + required: false, + serializedName: 'delete', + type: { + name: 'Composite', + className: 'UpdateKbOperationDTODelete' + } + }, + update: { + required: false, + serializedName: 'update', + type: { + name: 'Composite', + className: 'UpdateKbOperationDTOUpdate' + } + } + } + } + }; + } +} + +module.exports = UpdateKbOperationDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/updateKbOperationDTOAdd.js b/lib/services/cognitiveServices/qnamaker/lib/models/updateKbOperationDTOAdd.js new file mode 100644 index 0000000000..27ed1bca98 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/updateKbOperationDTOAdd.js @@ -0,0 +1,92 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +const models = require('./index'); + +/** + * An instance of CreateKbInputDTO for add operation + * + * @extends models['CreateKbInputDTO'] + */ +class UpdateKbOperationDTOAdd extends models['CreateKbInputDTO'] { + /** + * Create a UpdateKbOperationDTOAdd. + */ + constructor() { + super(); + } + + /** + * Defines the metadata of UpdateKbOperationDTOAdd + * + * @returns {object} metadata of UpdateKbOperationDTOAdd + * + */ + mapper() { + return { + required: false, + serializedName: 'UpdateKbOperationDTO_add', + type: { + name: 'Composite', + className: 'UpdateKbOperationDTOAdd', + modelProperties: { + qnaList: { + required: false, + serializedName: 'qnaList', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'QnADTOElementType', + type: { + name: 'Composite', + className: 'QnADTO' + } + } + } + }, + urls: { + required: false, + serializedName: 'urls', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + }, + files: { + required: false, + serializedName: 'files', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'FileDTOElementType', + type: { + name: 'Composite', + className: 'FileDTO' + } + } + } + } + } + } + }; + } +} + +module.exports = UpdateKbOperationDTOAdd; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/updateKbOperationDTODelete.js b/lib/services/cognitiveServices/qnamaker/lib/models/updateKbOperationDTODelete.js new file mode 100644 index 0000000000..fa24b6a168 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/updateKbOperationDTODelete.js @@ -0,0 +1,76 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +const models = require('./index'); + +/** + * An instance of DeleteKbContentsDTO for delete Operation + * + * @extends models['DeleteKbContentsDTO'] + */ +class UpdateKbOperationDTODelete extends models['DeleteKbContentsDTO'] { + /** + * Create a UpdateKbOperationDTODelete. + */ + constructor() { + super(); + } + + /** + * Defines the metadata of UpdateKbOperationDTODelete + * + * @returns {object} metadata of UpdateKbOperationDTODelete + * + */ + mapper() { + return { + required: false, + serializedName: 'UpdateKbOperationDTO_delete', + type: { + name: 'Composite', + className: 'UpdateKbOperationDTODelete', + modelProperties: { + ids: { + required: false, + serializedName: 'ids', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'NumberElementType', + type: { + name: 'Number' + } + } + } + }, + sources: { + required: false, + serializedName: 'sources', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + } + } + } + }; + } +} + +module.exports = UpdateKbOperationDTODelete; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/updateKbOperationDTOUpdate.js b/lib/services/cognitiveServices/qnamaker/lib/models/updateKbOperationDTOUpdate.js new file mode 100644 index 0000000000..6793e83e81 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/updateKbOperationDTOUpdate.js @@ -0,0 +1,84 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +const models = require('./index'); + +/** + * An instance of UpdateKbContentsDTO for Update Operation + * + * @extends models['UpdateKbContentsDTO'] + */ +class UpdateKbOperationDTOUpdate extends models['UpdateKbContentsDTO'] { + /** + * Create a UpdateKbOperationDTOUpdate. + */ + constructor() { + super(); + } + + /** + * Defines the metadata of UpdateKbOperationDTOUpdate + * + * @returns {object} metadata of UpdateKbOperationDTOUpdate + * + */ + mapper() { + return { + required: false, + serializedName: 'UpdateKbOperationDTO_update', + type: { + name: 'Composite', + className: 'UpdateKbOperationDTOUpdate', + modelProperties: { + name: { + required: false, + serializedName: 'name', + type: { + name: 'String' + } + }, + qnaList: { + required: false, + serializedName: 'qnaList', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'UpdateQnaDTOElementType', + type: { + name: 'Composite', + className: 'UpdateQnaDTO' + } + } + } + }, + urls: { + required: false, + serializedName: 'urls', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + } + } + } + }; + } +} + +module.exports = UpdateKbOperationDTOUpdate; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/updateMetadataDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/updateMetadataDTO.js new file mode 100644 index 0000000000..78b3504936 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/updateMetadataDTO.js @@ -0,0 +1,77 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * PATCH Body schema to represent list of Metadata to be updated + * + */ +class UpdateMetadataDTO { + /** + * Create a UpdateMetadataDTO. + * @property {array} [deleteProperty] List of Metadata associated with answer + * to be deleted + * @property {array} [add] List of Metadat associated with answer to be added + */ + constructor() { + } + + /** + * Defines the metadata of UpdateMetadataDTO + * + * @returns {object} metadata of UpdateMetadataDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'UpdateMetadataDTO', + type: { + name: 'Composite', + className: 'UpdateMetadataDTO', + modelProperties: { + deleteProperty: { + required: false, + serializedName: 'delete', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'MetadataDTOElementType', + type: { + name: 'Composite', + className: 'MetadataDTO' + } + } + } + }, + add: { + required: false, + serializedName: 'add', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'MetadataDTOElementType', + type: { + name: 'Composite', + className: 'MetadataDTO' + } + } + } + } + } + } + }; + } +} + +module.exports = UpdateMetadataDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/updateQnaDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/updateQnaDTO.js new file mode 100644 index 0000000000..2bb5280ffe --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/updateQnaDTO.js @@ -0,0 +1,96 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * PATCH Body schema for Update Qna List + * + */ +class UpdateQnaDTO { + /** + * Create a UpdateQnaDTO. + * @property {number} [id] Unique id for the Q-A + * @property {string} [answer] Answer text + * @property {string} [source] Source from which Q-A was indexed. eg. + * https://docs.microsoft.com/en-us/azure/cognitive-services/QnAMaker/FAQs + * @property {object} [questions] List of questions associated with the + * answer. + * @property {object} [metadata] List of metadata associated with the answer + * to be updated + */ + constructor() { + } + + /** + * Defines the metadata of UpdateQnaDTO + * + * @returns {object} metadata of UpdateQnaDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'UpdateQnaDTO', + type: { + name: 'Composite', + className: 'UpdateQnaDTO', + modelProperties: { + id: { + required: false, + serializedName: 'id', + constraints: { + InclusiveMaximum: 2147483647, + InclusiveMinimum: 0 + }, + type: { + name: 'Number' + } + }, + answer: { + required: false, + serializedName: 'answer', + type: { + name: 'String' + } + }, + source: { + required: false, + serializedName: 'source', + constraints: { + MaxLength: 300 + }, + type: { + name: 'String' + } + }, + questions: { + required: false, + serializedName: 'questions', + type: { + name: 'Composite', + className: 'UpdateQnaDTOQuestions' + } + }, + metadata: { + required: false, + serializedName: 'metadata', + type: { + name: 'Composite', + className: 'UpdateQnaDTOMetadata' + } + } + } + } + }; + } +} + +module.exports = UpdateQnaDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/updateQnaDTOMetadata.js b/lib/services/cognitiveServices/qnamaker/lib/models/updateQnaDTOMetadata.js new file mode 100644 index 0000000000..a66f383532 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/updateQnaDTOMetadata.js @@ -0,0 +1,78 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +const models = require('./index'); + +/** + * List of metadata associated with the answer to be updated + * + * @extends models['UpdateMetadataDTO'] + */ +class UpdateQnaDTOMetadata extends models['UpdateMetadataDTO'] { + /** + * Create a UpdateQnaDTOMetadata. + */ + constructor() { + super(); + } + + /** + * Defines the metadata of UpdateQnaDTOMetadata + * + * @returns {object} metadata of UpdateQnaDTOMetadata + * + */ + mapper() { + return { + required: false, + serializedName: 'UpdateQnaDTO_metadata', + type: { + name: 'Composite', + className: 'UpdateQnaDTOMetadata', + modelProperties: { + deleteProperty: { + required: false, + serializedName: 'delete', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'MetadataDTOElementType', + type: { + name: 'Composite', + className: 'MetadataDTO' + } + } + } + }, + add: { + required: false, + serializedName: 'add', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'MetadataDTOElementType', + type: { + name: 'Composite', + className: 'MetadataDTO' + } + } + } + } + } + } + }; + } +} + +module.exports = UpdateQnaDTOMetadata; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/updateQnaDTOQuestions.js b/lib/services/cognitiveServices/qnamaker/lib/models/updateQnaDTOQuestions.js new file mode 100644 index 0000000000..588f561385 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/updateQnaDTOQuestions.js @@ -0,0 +1,76 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +const models = require('./index'); + +/** + * List of questions associated with the answer. + * + * @extends models['UpdateQuestionsDTO'] + */ +class UpdateQnaDTOQuestions extends models['UpdateQuestionsDTO'] { + /** + * Create a UpdateQnaDTOQuestions. + */ + constructor() { + super(); + } + + /** + * Defines the metadata of UpdateQnaDTOQuestions + * + * @returns {object} metadata of UpdateQnaDTOQuestions + * + */ + mapper() { + return { + required: false, + serializedName: 'UpdateQnaDTO_questions', + type: { + name: 'Composite', + className: 'UpdateQnaDTOQuestions', + modelProperties: { + add: { + required: false, + serializedName: 'add', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + }, + deleteProperty: { + required: false, + serializedName: 'delete', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + } + } + } + }; + } +} + +module.exports = UpdateQnaDTOQuestions; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/updateQuestionsDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/updateQuestionsDTO.js new file mode 100644 index 0000000000..c9ce1a7844 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/updateQuestionsDTO.js @@ -0,0 +1,75 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * PATCH Body schema for Update Kb which contains list of questions to be added + * and deleted + * + */ +class UpdateQuestionsDTO { + /** + * Create a UpdateQuestionsDTO. + * @property {array} [add] List of questions to be added + * @property {array} [deleteProperty] List of questions to be deleted. + */ + constructor() { + } + + /** + * Defines the metadata of UpdateQuestionsDTO + * + * @returns {object} metadata of UpdateQuestionsDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'UpdateQuestionsDTO', + type: { + name: 'Composite', + className: 'UpdateQuestionsDTO', + modelProperties: { + add: { + required: false, + serializedName: 'add', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + }, + deleteProperty: { + required: false, + serializedName: 'delete', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + } + } + } + }; + } +} + +module.exports = UpdateQuestionsDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/models/wordAlterationsDTO.js b/lib/services/cognitiveServices/qnamaker/lib/models/wordAlterationsDTO.js new file mode 100644 index 0000000000..4cb195498b --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/models/wordAlterationsDTO.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Collection of word alterations. + * + */ +class WordAlterationsDTO { + /** + * Create a WordAlterationsDTO. + * @property {array} wordAlterations Collection of word alterations. + */ + constructor() { + } + + /** + * Defines the metadata of WordAlterationsDTO + * + * @returns {object} metadata of WordAlterationsDTO + * + */ + mapper() { + return { + required: false, + serializedName: 'WordAlterationsDTO', + type: { + name: 'Composite', + className: 'WordAlterationsDTO', + modelProperties: { + wordAlterations: { + required: true, + serializedName: 'wordAlterations', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'AlterationsDTOElementType', + type: { + name: 'Composite', + className: 'AlterationsDTO' + } + } + } + } + } + } + }; + } +} + +module.exports = WordAlterationsDTO; diff --git a/lib/services/cognitiveServices/qnamaker/lib/operations/alterations.js b/lib/services/cognitiveServices/qnamaker/lib/operations/alterations.js new file mode 100644 index 0000000000..1362f95c79 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/operations/alterations.js @@ -0,0 +1,433 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +const msRest = require('ms-rest'); +const WebResource = msRest.WebResource; + +/** + * @summary Download alterations from runtime. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link WordAlterationsDTO} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _get(options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'alterations'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['WordAlterationsDTO']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** + * @summary Replace alterations data. + * + * @param {object} wordAlterations New alterations data. + * + * @param {array} wordAlterations.wordAlterations Collection of word + * alterations. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _replace(wordAlterations, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + if (wordAlterations === null || wordAlterations === undefined) { + throw new Error('wordAlterations cannot be null or undefined.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'alterations'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'PUT'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + // Serialize Request + let requestContent = null; + let requestModel = null; + try { + if (wordAlterations !== null && wordAlterations !== undefined) { + let requestModelMapper = new client.models['WordAlterationsDTO']().mapper(); + requestModel = client.serialize(requestModelMapper, wordAlterations, 'wordAlterations'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(wordAlterations, null, 2)}.`); + return callback(serializationError); + } + httpRequest.body = requestContent; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 204) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + + return callback(null, result, httpRequest, response); + }); +} + +/** Class representing a Alterations. */ +class Alterations { + /** + * Create a Alterations. + * @param {QnAMakerClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._get = _get; + this._replace = _replace; + } + + /** + * @summary Download alterations from runtime. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + getWithHttpOperationResponse(options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._get(options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Download alterations from runtime. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {WordAlterationsDTO} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link WordAlterationsDTO} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + get(options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._get(options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._get(options, optionalCallback); + } + } + + /** + * @summary Replace alterations data. + * + * @param {object} wordAlterations New alterations data. + * + * @param {array} wordAlterations.wordAlterations Collection of word + * alterations. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + replaceWithHttpOperationResponse(wordAlterations, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._replace(wordAlterations, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Replace alterations data. + * + * @param {object} wordAlterations New alterations data. + * + * @param {array} wordAlterations.wordAlterations Collection of word + * alterations. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {null} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + replace(wordAlterations, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._replace(wordAlterations, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._replace(wordAlterations, options, optionalCallback); + } + } + +} + +module.exports = Alterations; diff --git a/lib/services/cognitiveServices/qnamaker/lib/operations/endpoint.js b/lib/services/cognitiveServices/qnamaker/lib/operations/endpoint.js new file mode 100644 index 0000000000..390c9d9d62 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/operations/endpoint.js @@ -0,0 +1,430 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +const msRest = require('ms-rest'); +const WebResource = msRest.WebResource; + +/** + * @summary Gets endpoint keys for an endpoint + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link EndpointKeysDTO} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _getKeys(options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'endpointkeys'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['EndpointKeysDTO']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** + * @summary Re-generates an endpoint key. + * + * @param {string} keyType Type of Key + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link EndpointKeysDTO} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _refreshKeys(keyType, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + if (keyType === null || keyType === undefined || typeof keyType.valueOf() !== 'string') { + throw new Error('keyType cannot be null or undefined and it must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'endpointkeys/{keyType}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{keyType}', encodeURIComponent(keyType)); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'PATCH'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['EndpointKeysDTO']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** Class representing a Endpoint. */ +class Endpoint { + /** + * Create a Endpoint. + * @param {QnAMakerClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._getKeys = _getKeys; + this._refreshKeys = _refreshKeys; + } + + /** + * @summary Gets endpoint keys for an endpoint + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + getKeysWithHttpOperationResponse(options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._getKeys(options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Gets endpoint keys for an endpoint + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {EndpointKeysDTO} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link EndpointKeysDTO} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + getKeys(options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._getKeys(options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._getKeys(options, optionalCallback); + } + } + + /** + * @summary Re-generates an endpoint key. + * + * @param {string} keyType Type of Key + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + refreshKeysWithHttpOperationResponse(keyType, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._refreshKeys(keyType, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Re-generates an endpoint key. + * + * @param {string} keyType Type of Key + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {EndpointKeysDTO} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link EndpointKeysDTO} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + refreshKeys(keyType, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._refreshKeys(keyType, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._refreshKeys(keyType, options, optionalCallback); + } + } + +} + +module.exports = Endpoint; diff --git a/lib/services/cognitiveServices/qnamaker/lib/operations/index.d.ts b/lib/services/cognitiveServices/qnamaker/lib/operations/index.d.ts new file mode 100644 index 0000000000..6f2f991c22 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/operations/index.d.ts @@ -0,0 +1,864 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. +*/ + +import { ServiceClientOptions, RequestOptions, ServiceCallback, HttpOperationResponse } from 'ms-rest'; +import * as models from '../models'; + + +/** + * @class + * Endpoint + * __NOTE__: An instance of this class is automatically created for an + * instance of the QnAMakerClient. + */ +export interface Endpoint { + + + /** + * @summary Gets endpoint keys for an endpoint + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + getKeysWithHttpOperationResponse(options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Gets endpoint keys for an endpoint + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {EndpointKeysDTO} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {EndpointKeysDTO} [result] - The deserialized result object if an error did not occur. + * See {@link EndpointKeysDTO} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + getKeys(options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + getKeys(callback: ServiceCallback): void; + getKeys(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * @summary Re-generates an endpoint key. + * + * @param {string} keyType Type of Key + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + refreshKeysWithHttpOperationResponse(keyType: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Re-generates an endpoint key. + * + * @param {string} keyType Type of Key + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {EndpointKeysDTO} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {EndpointKeysDTO} [result] - The deserialized result object if an error did not occur. + * See {@link EndpointKeysDTO} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + refreshKeys(keyType: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + refreshKeys(keyType: string, callback: ServiceCallback): void; + refreshKeys(keyType: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; +} + +/** + * @class + * Alterations + * __NOTE__: An instance of this class is automatically created for an + * instance of the QnAMakerClient. + */ +export interface Alterations { + + + /** + * @summary Download alterations from runtime. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + getWithHttpOperationResponse(options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Download alterations from runtime. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {WordAlterationsDTO} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {WordAlterationsDTO} [result] - The deserialized result object if an error did not occur. + * See {@link WordAlterationsDTO} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + get(options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + get(callback: ServiceCallback): void; + get(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * @summary Replace alterations data. + * + * @param {object} wordAlterations New alterations data. + * + * @param {array} wordAlterations.wordAlterations Collection of word + * alterations. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + replaceWithHttpOperationResponse(wordAlterations: models.WordAlterationsDTO, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Replace alterations data. + * + * @param {object} wordAlterations New alterations data. + * + * @param {array} wordAlterations.wordAlterations Collection of word + * alterations. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {null} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + replace(wordAlterations: models.WordAlterationsDTO, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + replace(wordAlterations: models.WordAlterationsDTO, callback: ServiceCallback): void; + replace(wordAlterations: models.WordAlterationsDTO, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; +} + +/** + * @class + * Knowledgebase + * __NOTE__: An instance of this class is automatically created for an + * instance of the QnAMakerClient. + */ +export interface Knowledgebase { + + + /** + * @summary Gets all knowledgebases for a user. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + listAllWithHttpOperationResponse(options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Gets all knowledgebases for a user. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {KnowledgebasesDTO} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {KnowledgebasesDTO} [result] - The deserialized result object if an error did not occur. + * See {@link KnowledgebasesDTO} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + listAll(options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + listAll(callback: ServiceCallback): void; + listAll(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * @summary Gets details of a specific knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + getDetailsWithHttpOperationResponse(kbId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Gets details of a specific knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {KnowledgebaseDTO} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {KnowledgebaseDTO} [result] - The deserialized result object if an error did not occur. + * See {@link KnowledgebaseDTO} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + getDetails(kbId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + getDetails(kbId: string, callback: ServiceCallback): void; + getDetails(kbId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * @summary Deletes the knowledgebase and all its data. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + deleteMethodWithHttpOperationResponse(kbId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Deletes the knowledgebase and all its data. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {null} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + deleteMethod(kbId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + deleteMethod(kbId: string, callback: ServiceCallback): void; + deleteMethod(kbId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * @summary Publishes all changes in test index of a knowledgebase to its prod + * index. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + publishWithHttpOperationResponse(kbId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Publishes all changes in test index of a knowledgebase to its prod + * index. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {null} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + publish(kbId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + publish(kbId: string, callback: ServiceCallback): void; + publish(kbId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * @summary Replace knowledgebase contents. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} replaceKb An instance of ReplaceKbDTO which contains list of + * qnas to be uploaded + * + * @param {array} replaceKb.qnAList List of Q-A (QnADTO) to be added to the + * knowledgebase. Q-A Ids are assigned by the service and should be omitted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + replaceWithHttpOperationResponse(kbId: string, replaceKb: models.ReplaceKbDTO, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Replace knowledgebase contents. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} replaceKb An instance of ReplaceKbDTO which contains list of + * qnas to be uploaded + * + * @param {array} replaceKb.qnAList List of Q-A (QnADTO) to be added to the + * knowledgebase. Q-A Ids are assigned by the service and should be omitted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {null} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + replace(kbId: string, replaceKb: models.ReplaceKbDTO, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + replace(kbId: string, replaceKb: models.ReplaceKbDTO, callback: ServiceCallback): void; + replace(kbId: string, replaceKb: models.ReplaceKbDTO, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * @summary Asynchronous operation to modify a knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} updateKb Post body of the request. + * + * @param {object} [updateKb.add] An instance of CreateKbInputDTO for add + * operation + * + * @param {array} [updateKb.add.qnaList] List of QNA to be added to the index. + * Ids are generated by the service and should be omitted. + * + * @param {array} [updateKb.add.urls] List of URLs to be added to + * knowledgebase. + * + * @param {array} [updateKb.add.files] List of files to be added to + * knowledgebase. + * + * @param {object} [updateKb.deleteProperty] An instance of DeleteKbContentsDTO + * for delete Operation + * + * @param {array} [updateKb.deleteProperty.ids] List of Qna Ids to be deleted + * + * @param {array} [updateKb.deleteProperty.sources] List of sources to be + * deleted from knowledgebase. + * + * @param {object} [updateKb.update] An instance of UpdateKbContentsDTO for + * Update Operation + * + * @param {string} [updateKb.update.name] Friendly name for the knowledgebase. + * + * @param {array} [updateKb.update.qnaList] List of Q-A (UpdateQnaDTO) to be + * added to the knowledgebase. + * + * @param {array} [updateKb.update.urls] List of existing URLs to be refreshed. + * The content will be extracted again and re-indexed. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + updateWithHttpOperationResponse(kbId: string, updateKb: models.UpdateKbOperationDTO, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Asynchronous operation to modify a knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} updateKb Post body of the request. + * + * @param {object} [updateKb.add] An instance of CreateKbInputDTO for add + * operation + * + * @param {array} [updateKb.add.qnaList] List of QNA to be added to the index. + * Ids are generated by the service and should be omitted. + * + * @param {array} [updateKb.add.urls] List of URLs to be added to + * knowledgebase. + * + * @param {array} [updateKb.add.files] List of files to be added to + * knowledgebase. + * + * @param {object} [updateKb.deleteProperty] An instance of DeleteKbContentsDTO + * for delete Operation + * + * @param {array} [updateKb.deleteProperty.ids] List of Qna Ids to be deleted + * + * @param {array} [updateKb.deleteProperty.sources] List of sources to be + * deleted from knowledgebase. + * + * @param {object} [updateKb.update] An instance of UpdateKbContentsDTO for + * Update Operation + * + * @param {string} [updateKb.update.name] Friendly name for the knowledgebase. + * + * @param {array} [updateKb.update.qnaList] List of Q-A (UpdateQnaDTO) to be + * added to the knowledgebase. + * + * @param {array} [updateKb.update.urls] List of existing URLs to be refreshed. + * The content will be extracted again and re-indexed. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {Operation} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {Operation} [result] - The deserialized result object if an error did not occur. + * See {@link Operation} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + update(kbId: string, updateKb: models.UpdateKbOperationDTO, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + update(kbId: string, updateKb: models.UpdateKbOperationDTO, callback: ServiceCallback): void; + update(kbId: string, updateKb: models.UpdateKbOperationDTO, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * @summary Asynchronous operation to create a new knowledgebase. + * + * @param {object} createKbPayload Post body of the request. + * + * @param {string} createKbPayload.name Friendly name for the knowledgebase. + * + * @param {array} [createKbPayload.qnaList] List of Q-A (QnADTO) to be added to + * the knowledgebase. Q-A Ids are assigned by the service and should be + * omitted. + * + * @param {array} [createKbPayload.urls] List of URLs to be used for extracting + * Q-A. + * + * @param {array} [createKbPayload.files] List of files from which to Extract + * Q-A. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + createWithHttpOperationResponse(createKbPayload: models.CreateKbDTO, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Asynchronous operation to create a new knowledgebase. + * + * @param {object} createKbPayload Post body of the request. + * + * @param {string} createKbPayload.name Friendly name for the knowledgebase. + * + * @param {array} [createKbPayload.qnaList] List of Q-A (QnADTO) to be added to + * the knowledgebase. Q-A Ids are assigned by the service and should be + * omitted. + * + * @param {array} [createKbPayload.urls] List of URLs to be used for extracting + * Q-A. + * + * @param {array} [createKbPayload.files] List of files from which to Extract + * Q-A. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {Operation} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {Operation} [result] - The deserialized result object if an error did not occur. + * See {@link Operation} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + create(createKbPayload: models.CreateKbDTO, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + create(createKbPayload: models.CreateKbDTO, callback: ServiceCallback): void; + create(createKbPayload: models.CreateKbDTO, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * @summary Download the knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {string} environment Specifies whether environment is Test or Prod. + * Possible values include: 'Prod', 'Test' + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + downloadWithHttpOperationResponse(kbId: string, environment: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Download the knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {string} environment Specifies whether environment is Test or Prod. + * Possible values include: 'Prod', 'Test' + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {QnADocumentsDTO} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {QnADocumentsDTO} [result] - The deserialized result object if an error did not occur. + * See {@link QnADocumentsDTO} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + download(kbId: string, environment: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + download(kbId: string, environment: string, callback: ServiceCallback): void; + download(kbId: string, environment: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; +} + +/** + * @class + * Operations + * __NOTE__: An instance of this class is automatically created for an + * instance of the QnAMakerClient. + */ +export interface Operations { + + + /** + * @summary Gets details of a specific long running operation. + * + * @param {string} operationId Operation id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + getDetailsWithHttpOperationResponse(operationId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary Gets details of a specific long running operation. + * + * @param {string} operationId Operation id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {Operation} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {Operation} [result] - The deserialized result object if an error did not occur. + * See {@link Operation} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + getDetails(operationId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + getDetails(operationId: string, callback: ServiceCallback): void; + getDetails(operationId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; +} diff --git a/lib/services/cognitiveServices/qnamaker/lib/operations/index.js b/lib/services/cognitiveServices/qnamaker/lib/operations/index.js new file mode 100644 index 0000000000..212ffb33fb --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/operations/index.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +/* jshint latedef:false */ +/* jshint forin:false */ +/* jshint noempty:false */ + +'use strict'; + +exports.Endpoint = require('./endpoint'); +exports.Alterations = require('./alterations'); +exports.Knowledgebase = require('./knowledgebase'); +exports.Operations = require('./operations'); diff --git a/lib/services/cognitiveServices/qnamaker/lib/operations/knowledgebase.js b/lib/services/cognitiveServices/qnamaker/lib/operations/knowledgebase.js new file mode 100644 index 0000000000..4aec04a4c6 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/operations/knowledgebase.js @@ -0,0 +1,1825 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +const msRest = require('ms-rest'); +const WebResource = msRest.WebResource; + +/** + * @summary Gets all knowledgebases for a user. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link KnowledgebasesDTO} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _listAll(options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'knowledgebases'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['KnowledgebasesDTO']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** + * @summary Gets details of a specific knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link KnowledgebaseDTO} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _getDetails(kbId, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + if (kbId === null || kbId === undefined || typeof kbId.valueOf() !== 'string') { + throw new Error('kbId cannot be null or undefined and it must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'knowledgebases/{kbId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{kbId}', encodeURIComponent(kbId)); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['KnowledgebaseDTO']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** + * @summary Deletes the knowledgebase and all its data. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _deleteMethod(kbId, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + if (kbId === null || kbId === undefined || typeof kbId.valueOf() !== 'string') { + throw new Error('kbId cannot be null or undefined and it must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'knowledgebases/{kbId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{kbId}', encodeURIComponent(kbId)); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'DELETE'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 204) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + + return callback(null, result, httpRequest, response); + }); +} + +/** + * @summary Publishes all changes in test index of a knowledgebase to its prod + * index. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _publish(kbId, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + if (kbId === null || kbId === undefined || typeof kbId.valueOf() !== 'string') { + throw new Error('kbId cannot be null or undefined and it must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'knowledgebases/{kbId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{kbId}', encodeURIComponent(kbId)); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'POST'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 204) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + + return callback(null, result, httpRequest, response); + }); +} + +/** + * @summary Replace knowledgebase contents. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} replaceKb An instance of ReplaceKbDTO which contains list of + * qnas to be uploaded + * + * @param {array} replaceKb.qnAList List of Q-A (QnADTO) to be added to the + * knowledgebase. Q-A Ids are assigned by the service and should be omitted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _replace(kbId, replaceKb, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + if (kbId === null || kbId === undefined || typeof kbId.valueOf() !== 'string') { + throw new Error('kbId cannot be null or undefined and it must be of type string.'); + } + if (replaceKb === null || replaceKb === undefined) { + throw new Error('replaceKb cannot be null or undefined.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'knowledgebases/{kbId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{kbId}', encodeURIComponent(kbId)); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'PUT'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + // Serialize Request + let requestContent = null; + let requestModel = null; + try { + if (replaceKb !== null && replaceKb !== undefined) { + let requestModelMapper = new client.models['ReplaceKbDTO']().mapper(); + requestModel = client.serialize(requestModelMapper, replaceKb, 'replaceKb'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(replaceKb, null, 2)}.`); + return callback(serializationError); + } + httpRequest.body = requestContent; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 204) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + + return callback(null, result, httpRequest, response); + }); +} + +/** + * @summary Asynchronous operation to modify a knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} updateKb Post body of the request. + * + * @param {object} [updateKb.add] An instance of CreateKbInputDTO for add + * operation + * + * @param {array} [updateKb.add.qnaList] List of QNA to be added to the index. + * Ids are generated by the service and should be omitted. + * + * @param {array} [updateKb.add.urls] List of URLs to be added to + * knowledgebase. + * + * @param {array} [updateKb.add.files] List of files to be added to + * knowledgebase. + * + * @param {object} [updateKb.deleteProperty] An instance of DeleteKbContentsDTO + * for delete Operation + * + * @param {array} [updateKb.deleteProperty.ids] List of Qna Ids to be deleted + * + * @param {array} [updateKb.deleteProperty.sources] List of sources to be + * deleted from knowledgebase. + * + * @param {object} [updateKb.update] An instance of UpdateKbContentsDTO for + * Update Operation + * + * @param {string} [updateKb.update.name] Friendly name for the knowledgebase. + * + * @param {array} [updateKb.update.qnaList] List of Q-A (UpdateQnaDTO) to be + * added to the knowledgebase. + * + * @param {array} [updateKb.update.urls] List of existing URLs to be refreshed. + * The content will be extracted again and re-indexed. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link Operation} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _update(kbId, updateKb, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + if (kbId === null || kbId === undefined || typeof kbId.valueOf() !== 'string') { + throw new Error('kbId cannot be null or undefined and it must be of type string.'); + } + if (updateKb === null || updateKb === undefined) { + throw new Error('updateKb cannot be null or undefined.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'knowledgebases/{kbId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{kbId}', encodeURIComponent(kbId)); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'PATCH'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + // Serialize Request + let requestContent = null; + let requestModel = null; + try { + if (updateKb !== null && updateKb !== undefined) { + let requestModelMapper = new client.models['UpdateKbOperationDTO']().mapper(); + requestModel = client.serialize(requestModelMapper, updateKb, 'updateKb'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(updateKb, null, 2)}.`); + return callback(serializationError); + } + httpRequest.body = requestContent; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 202) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 202) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['Operation']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** + * @summary Asynchronous operation to create a new knowledgebase. + * + * @param {object} createKbPayload Post body of the request. + * + * @param {string} createKbPayload.name Friendly name for the knowledgebase. + * + * @param {array} [createKbPayload.qnaList] List of Q-A (QnADTO) to be added to + * the knowledgebase. Q-A Ids are assigned by the service and should be + * omitted. + * + * @param {array} [createKbPayload.urls] List of URLs to be used for extracting + * Q-A. + * + * @param {array} [createKbPayload.files] List of files from which to Extract + * Q-A. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link Operation} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _create(createKbPayload, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + if (createKbPayload === null || createKbPayload === undefined) { + throw new Error('createKbPayload cannot be null or undefined.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'knowledgebases/create'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'POST'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + // Serialize Request + let requestContent = null; + let requestModel = null; + try { + if (createKbPayload !== null && createKbPayload !== undefined) { + let requestModelMapper = new client.models['CreateKbDTO']().mapper(); + requestModel = client.serialize(requestModelMapper, createKbPayload, 'createKbPayload'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(createKbPayload, null, 2)}.`); + return callback(serializationError); + } + httpRequest.body = requestContent; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 202) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 202) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['Operation']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** + * @summary Download the knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {string} environment Specifies whether environment is Test or Prod. + * Possible values include: 'Prod', 'Test' + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link QnADocumentsDTO} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _download(kbId, environment, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + if (kbId === null || kbId === undefined || typeof kbId.valueOf() !== 'string') { + throw new Error('kbId cannot be null or undefined and it must be of type string.'); + } + if (environment === null || environment === undefined || typeof environment.valueOf() !== 'string') { + throw new Error('environment cannot be null or undefined and it must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'knowledgebases/{kbId}/{environment}/qna'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{kbId}', encodeURIComponent(kbId)); + requestUrl = requestUrl.replace('{environment}', encodeURIComponent(environment)); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['QnADocumentsDTO']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** Class representing a Knowledgebase. */ +class Knowledgebase { + /** + * Create a Knowledgebase. + * @param {QnAMakerClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._listAll = _listAll; + this._getDetails = _getDetails; + this._deleteMethod = _deleteMethod; + this._publish = _publish; + this._replace = _replace; + this._update = _update; + this._create = _create; + this._download = _download; + } + + /** + * @summary Gets all knowledgebases for a user. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + listAllWithHttpOperationResponse(options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._listAll(options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Gets all knowledgebases for a user. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {KnowledgebasesDTO} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link KnowledgebasesDTO} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + listAll(options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._listAll(options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._listAll(options, optionalCallback); + } + } + + /** + * @summary Gets details of a specific knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + getDetailsWithHttpOperationResponse(kbId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._getDetails(kbId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Gets details of a specific knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {KnowledgebaseDTO} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link KnowledgebaseDTO} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + getDetails(kbId, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._getDetails(kbId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._getDetails(kbId, options, optionalCallback); + } + } + + /** + * @summary Deletes the knowledgebase and all its data. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + deleteMethodWithHttpOperationResponse(kbId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._deleteMethod(kbId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Deletes the knowledgebase and all its data. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {null} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + deleteMethod(kbId, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._deleteMethod(kbId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._deleteMethod(kbId, options, optionalCallback); + } + } + + /** + * @summary Publishes all changes in test index of a knowledgebase to its prod + * index. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + publishWithHttpOperationResponse(kbId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._publish(kbId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Publishes all changes in test index of a knowledgebase to its prod + * index. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {null} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + publish(kbId, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._publish(kbId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._publish(kbId, options, optionalCallback); + } + } + + /** + * @summary Replace knowledgebase contents. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} replaceKb An instance of ReplaceKbDTO which contains list of + * qnas to be uploaded + * + * @param {array} replaceKb.qnAList List of Q-A (QnADTO) to be added to the + * knowledgebase. Q-A Ids are assigned by the service and should be omitted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + replaceWithHttpOperationResponse(kbId, replaceKb, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._replace(kbId, replaceKb, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Replace knowledgebase contents. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} replaceKb An instance of ReplaceKbDTO which contains list of + * qnas to be uploaded + * + * @param {array} replaceKb.qnAList List of Q-A (QnADTO) to be added to the + * knowledgebase. Q-A Ids are assigned by the service and should be omitted. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {null} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + replace(kbId, replaceKb, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._replace(kbId, replaceKb, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._replace(kbId, replaceKb, options, optionalCallback); + } + } + + /** + * @summary Asynchronous operation to modify a knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} updateKb Post body of the request. + * + * @param {object} [updateKb.add] An instance of CreateKbInputDTO for add + * operation + * + * @param {array} [updateKb.add.qnaList] List of QNA to be added to the index. + * Ids are generated by the service and should be omitted. + * + * @param {array} [updateKb.add.urls] List of URLs to be added to + * knowledgebase. + * + * @param {array} [updateKb.add.files] List of files to be added to + * knowledgebase. + * + * @param {object} [updateKb.deleteProperty] An instance of DeleteKbContentsDTO + * for delete Operation + * + * @param {array} [updateKb.deleteProperty.ids] List of Qna Ids to be deleted + * + * @param {array} [updateKb.deleteProperty.sources] List of sources to be + * deleted from knowledgebase. + * + * @param {object} [updateKb.update] An instance of UpdateKbContentsDTO for + * Update Operation + * + * @param {string} [updateKb.update.name] Friendly name for the knowledgebase. + * + * @param {array} [updateKb.update.qnaList] List of Q-A (UpdateQnaDTO) to be + * added to the knowledgebase. + * + * @param {array} [updateKb.update.urls] List of existing URLs to be refreshed. + * The content will be extracted again and re-indexed. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + updateWithHttpOperationResponse(kbId, updateKb, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._update(kbId, updateKb, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Asynchronous operation to modify a knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {object} updateKb Post body of the request. + * + * @param {object} [updateKb.add] An instance of CreateKbInputDTO for add + * operation + * + * @param {array} [updateKb.add.qnaList] List of QNA to be added to the index. + * Ids are generated by the service and should be omitted. + * + * @param {array} [updateKb.add.urls] List of URLs to be added to + * knowledgebase. + * + * @param {array} [updateKb.add.files] List of files to be added to + * knowledgebase. + * + * @param {object} [updateKb.deleteProperty] An instance of DeleteKbContentsDTO + * for delete Operation + * + * @param {array} [updateKb.deleteProperty.ids] List of Qna Ids to be deleted + * + * @param {array} [updateKb.deleteProperty.sources] List of sources to be + * deleted from knowledgebase. + * + * @param {object} [updateKb.update] An instance of UpdateKbContentsDTO for + * Update Operation + * + * @param {string} [updateKb.update.name] Friendly name for the knowledgebase. + * + * @param {array} [updateKb.update.qnaList] List of Q-A (UpdateQnaDTO) to be + * added to the knowledgebase. + * + * @param {array} [updateKb.update.urls] List of existing URLs to be refreshed. + * The content will be extracted again and re-indexed. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {Operation} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link Operation} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + update(kbId, updateKb, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._update(kbId, updateKb, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._update(kbId, updateKb, options, optionalCallback); + } + } + + /** + * @summary Asynchronous operation to create a new knowledgebase. + * + * @param {object} createKbPayload Post body of the request. + * + * @param {string} createKbPayload.name Friendly name for the knowledgebase. + * + * @param {array} [createKbPayload.qnaList] List of Q-A (QnADTO) to be added to + * the knowledgebase. Q-A Ids are assigned by the service and should be + * omitted. + * + * @param {array} [createKbPayload.urls] List of URLs to be used for extracting + * Q-A. + * + * @param {array} [createKbPayload.files] List of files from which to Extract + * Q-A. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + createWithHttpOperationResponse(createKbPayload, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._create(createKbPayload, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Asynchronous operation to create a new knowledgebase. + * + * @param {object} createKbPayload Post body of the request. + * + * @param {string} createKbPayload.name Friendly name for the knowledgebase. + * + * @param {array} [createKbPayload.qnaList] List of Q-A (QnADTO) to be added to + * the knowledgebase. Q-A Ids are assigned by the service and should be + * omitted. + * + * @param {array} [createKbPayload.urls] List of URLs to be used for extracting + * Q-A. + * + * @param {array} [createKbPayload.files] List of files from which to Extract + * Q-A. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {Operation} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link Operation} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + create(createKbPayload, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._create(createKbPayload, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._create(createKbPayload, options, optionalCallback); + } + } + + /** + * @summary Download the knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {string} environment Specifies whether environment is Test or Prod. + * Possible values include: 'Prod', 'Test' + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + downloadWithHttpOperationResponse(kbId, environment, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._download(kbId, environment, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Download the knowledgebase. + * + * @param {string} kbId Knowledgebase id. + * + * @param {string} environment Specifies whether environment is Test or Prod. + * Possible values include: 'Prod', 'Test' + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {QnADocumentsDTO} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link QnADocumentsDTO} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + download(kbId, environment, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._download(kbId, environment, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._download(kbId, environment, options, optionalCallback); + } + } + +} + +module.exports = Knowledgebase; diff --git a/lib/services/cognitiveServices/qnamaker/lib/operations/operations.js b/lib/services/cognitiveServices/qnamaker/lib/operations/operations.js new file mode 100644 index 0000000000..8e94e97361 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/operations/operations.js @@ -0,0 +1,234 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +const msRest = require('ms-rest'); +const WebResource = msRest.WebResource; + +/** + * @summary Gets details of a specific long running operation. + * + * @param {string} operationId Operation id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link Operation} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _getDetails(operationId, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') { + throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.'); + } + if (operationId === null || operationId === undefined || typeof operationId.valueOf() !== 'string') { + throw new Error('operationId cannot be null or undefined and it must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'operations/{operationId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{operationId}', encodeURIComponent(operationId)); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['Operation']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** Class representing a Operations. */ +class Operations { + /** + * Create a Operations. + * @param {QnAMakerClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._getDetails = _getDetails; + } + + /** + * @summary Gets details of a specific long running operation. + * + * @param {string} operationId Operation id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + getDetailsWithHttpOperationResponse(operationId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._getDetails(operationId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary Gets details of a specific long running operation. + * + * @param {string} operationId Operation id. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {Operation} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link Operation} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + getDetails(operationId, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._getDetails(operationId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._getDetails(operationId, options, optionalCallback); + } + } + +} + +module.exports = Operations; diff --git a/lib/services/cognitiveServices/qnamaker/lib/qnAMakerClient.d.ts b/lib/services/cognitiveServices/qnamaker/lib/qnAMakerClient.d.ts new file mode 100644 index 0000000000..4b5a5a7c56 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/qnAMakerClient.d.ts @@ -0,0 +1,48 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +import { ServiceClient, ServiceClientOptions, ServiceClientCredentials } from 'ms-rest'; +import * as models from "./models"; +import * as operations from "./operations"; + +export default class QnAMakerClient extends ServiceClient { + /** + * @class + * Initializes a new instance of the QnAMakerClient class. + * @constructor + * + * @param {credentials} credentials - Subscription credentials which uniquely identify client subscription. + * + * @param {string} endpoint - Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus.api.cognitive.microsoft.com). + * + * @param {object} [options] - The parameter options + * + * @param {Array} [options.filters] - Filters to be added to the request pipeline + * + * @param {object} [options.requestOptions] - Options for the underlying request object + * {@link https://github.com/request/request#requestoptions-callback Options doc} + * + * @param {boolean} [options.noRetryPolicy] - If set to true, turn off default retry policy + * + */ + constructor(credentials: ServiceClientCredentials, endpoint: string, options?: ServiceClientOptions); + + credentials: ServiceClientCredentials; + + endpoint: string; + + // Operation groups + endpoint: operations.Endpoint; + alterations: operations.Alterations; + knowledgebase: operations.Knowledgebase; + operations: operations.Operations; +} + +export { QnAMakerClient, models as QnAMakerModels }; diff --git a/lib/services/cognitiveServices/qnamaker/lib/qnAMakerClient.js b/lib/services/cognitiveServices/qnamaker/lib/qnAMakerClient.js new file mode 100644 index 0000000000..dcfb04e904 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/lib/qnAMakerClient.js @@ -0,0 +1,67 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +/* jshint latedef:false */ +/* jshint forin:false */ +/* jshint noempty:false */ + +'use strict'; + +const msRest = require('ms-rest'); +const ServiceClient = msRest.ServiceClient; + +const models = require('./models'); +const operations = require('./operations'); + + +/** Class representing a QnAMakerClient. */ +class QnAMakerClient extends ServiceClient { + /** + * Create a QnAMakerClient. + * @param {credentials} credentials - Subscription credentials which uniquely identify client subscription. + * @param {string} endpoint - Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus.api.cognitive.microsoft.com). + * @param {object} [options] - The parameter options + * @param {Array} [options.filters] - Filters to be added to the request pipeline + * @param {object} [options.requestOptions] - Options for the underlying request object + * {@link https://github.com/request/request#requestoptions-callback Options doc} + * @param {boolean} [options.noRetryPolicy] - If set to true, turn off default retry policy + */ + constructor(credentials, endpoint, options) { + if (credentials === null || credentials === undefined) { + throw new Error('\'credentials\' cannot be null.'); + } + if (endpoint === null || endpoint === undefined) { + throw new Error('\'endpoint\' cannot be null.'); + } + + if (!options) options = {}; + + super(credentials, options); + + this.baseUri = '{Endpoint}/qnamaker/v4.0'; + this.credentials = credentials; + this.endpoint = endpoint; + + let packageInfo = this.getPackageJsonInfo(__dirname); + this.addUserAgentInfo(`${packageInfo.name}/${packageInfo.version}`); + this.endpoint = new operations.Endpoint(this); + this.alterations = new operations.Alterations(this); + this.knowledgebase = new operations.Knowledgebase(this); + this.operations = new operations.Operations(this); + this.models = models; + msRest.addSerializationMixin(this); + } + +} + +module.exports = QnAMakerClient; +module.exports['default'] = QnAMakerClient; +module.exports.QnAMakerClient = QnAMakerClient; +module.exports.QnAMakerModels = models; diff --git a/lib/services/cognitiveServices/qnamaker/package.json b/lib/services/cognitiveServices/qnamaker/package.json new file mode 100644 index 0000000000..26386c7462 --- /dev/null +++ b/lib/services/cognitiveServices/qnamaker/package.json @@ -0,0 +1,24 @@ +{ + "name": "azure-cognitiveservices-qnamaker", + "author": "Microsoft Corporation", + "description": "QnAMakerClient Library with typescript type definitions for node", + "version": "1.0.0", + "dependencies": { + "ms-rest": "^2.3.3" + }, + "keywords": [ + "node", + "azure" + ], + "license": "MIT", + "main": "./lib/qnAMakerClient.js", + "types": "./lib/qnAMakerClient.d.ts", + "homepage": "https://github.com/azure/azure-sdk-for-node/tree/master/lib/services/cognitiveServices/qnamaker", + "repository": { + "type": "git", + "url": "https://github.com/azure/azure-sdk-for-node.git" + }, + "bugs": { + "url": "https://github.com/azure/azure-sdk-for-node/issues" + } +}