diff --git a/lib/services/face/LICENSE.txt b/lib/services/face/LICENSE.txt index 0313a903d7..5431ba98b9 100644 --- a/lib/services/face/LICENSE.txt +++ b/lib/services/face/LICENSE.txt @@ -1,21 +1,21 @@ -The MIT License (MIT) - -Copyright (c) 2017 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. \ No newline at end of file +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/face/lib/faceClient.d.ts b/lib/services/face/lib/faceClient.d.ts new file mode 100644 index 0000000000..164e434ef7 --- /dev/null +++ b/lib/services/face/lib/faceClient.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 FaceClient extends ServiceClient { + /** + * @class + * Initializes a new instance of the FaceClient 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 + face: operations.Face; + personGroupPerson: operations.PersonGroupPerson; + personGroupOperations: operations.PersonGroupOperations; + faceListOperations: operations.FaceListOperations; +} + +export { FaceClient, models as FaceModels }; diff --git a/lib/services/face/lib/faceClient.js b/lib/services/face/lib/faceClient.js new file mode 100644 index 0000000000..776554f63f --- /dev/null +++ b/lib/services/face/lib/faceClient.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 FaceClient. */ +class FaceClient extends ServiceClient { + /** + * Create a FaceClient. + * @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}/face/v1.0'; + this.credentials = credentials; + this.endpoint = endpoint; + + let packageInfo = this.getPackageJsonInfo(__dirname); + this.addUserAgentInfo(`${packageInfo.name}/${packageInfo.version}`); + this.face = new operations.Face(this); + this.personGroupPerson = new operations.PersonGroupPerson(this); + this.personGroupOperations = new operations.PersonGroupOperations(this); + this.faceListOperations = new operations.FaceListOperations(this); + this.models = models; + msRest.addSerializationMixin(this); + } + +} + +module.exports = FaceClient; +module.exports['default'] = FaceClient; +module.exports.FaceClient = FaceClient; +module.exports.FaceModels = models; diff --git a/lib/services/face/lib/models/accessory.js b/lib/services/face/lib/models/accessory.js new file mode 100644 index 0000000000..987d4b86c7 --- /dev/null +++ b/lib/services/face/lib/models/accessory.js @@ -0,0 +1,62 @@ +/* + * 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'; + +/** + * Accessory item and corresponding confidence level. + * + */ +class Accessory { + /** + * Create a Accessory. + * @member {string} [type] Type of an accessory. Possible values include: + * 'headWear', 'glasses', 'mask' + * @member {number} [confidence] Confidence level of an accessory + */ + constructor() { + } + + /** + * Defines the metadata of Accessory + * + * @returns {object} metadata of Accessory + * + */ + mapper() { + return { + required: false, + serializedName: 'Accessory', + type: { + name: 'Composite', + className: 'Accessory', + modelProperties: { + type: { + required: false, + serializedName: 'type', + type: { + name: 'Enum', + allowedValues: [ 'headWear', 'glasses', 'mask' ] + } + }, + confidence: { + required: false, + serializedName: 'confidence', + type: { + name: 'Number' + } + } + } + } + }; + } +} + +module.exports = Accessory; diff --git a/lib/services/face/lib/models/blur.js b/lib/services/face/lib/models/blur.js new file mode 100644 index 0000000000..76b653cbf8 --- /dev/null +++ b/lib/services/face/lib/models/blur.js @@ -0,0 +1,63 @@ +/* + * 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'; + +/** + * Properties describing any presence of blur within the image. + * + */ +class Blur { + /** + * Create a Blur. + * @member {string} [blurLevel] An enum value indicating level of blurriness. + * Possible values include: 'Low', 'Medium', 'High' + * @member {number} [value] A number indicating level of blurriness ranging + * from 0 to 1. + */ + constructor() { + } + + /** + * Defines the metadata of Blur + * + * @returns {object} metadata of Blur + * + */ + mapper() { + return { + required: false, + serializedName: 'Blur', + type: { + name: 'Composite', + className: 'Blur', + modelProperties: { + blurLevel: { + required: false, + serializedName: 'blurLevel', + type: { + name: 'Enum', + allowedValues: [ 'Low', 'Medium', 'High' ] + } + }, + value: { + required: false, + serializedName: 'value', + type: { + name: 'Number' + } + } + } + } + }; + } +} + +module.exports = Blur; diff --git a/lib/services/face/lib/models/coordinate.js b/lib/services/face/lib/models/coordinate.js new file mode 100644 index 0000000000..16ef6c0705 --- /dev/null +++ b/lib/services/face/lib/models/coordinate.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'; + +/** + * Coordinates within an image + * + */ +class Coordinate { + /** + * Create a Coordinate. + * @member {number} x The horizontal component, in pixels. + * @member {number} y The vertical component, in pixels. + */ + constructor() { + } + + /** + * Defines the metadata of Coordinate + * + * @returns {object} metadata of Coordinate + * + */ + mapper() { + return { + required: false, + serializedName: 'Coordinate', + type: { + name: 'Composite', + className: 'Coordinate', + modelProperties: { + x: { + required: true, + serializedName: 'x', + type: { + name: 'Number' + } + }, + y: { + required: true, + serializedName: 'y', + type: { + name: 'Number' + } + } + } + } + }; + } +} + +module.exports = Coordinate; diff --git a/lib/services/face/lib/models/detectedFace.js b/lib/services/face/lib/models/detectedFace.js index 2d16486347..c56faa01a6 100644 --- a/lib/services/face/lib/models/detectedFace.js +++ b/lib/services/face/lib/models/detectedFace.js @@ -19,7 +19,7 @@ const models = require('./index'); class DetectedFace { /** * Create a DetectedFace. - * @member {string} [faceId] + * @member {uuid} [faceId] * @member {object} faceRectangle * @member {number} [faceRectangle.width] The width of the rectangle, in * pixels. @@ -168,21 +168,24 @@ class DetectedFace { * @member {object} [faceAttributes] * @member {number} [faceAttributes.age] Age in years * @member {string} [faceAttributes.gender] Possible gender of the face. - * Possible values include: 'male', 'female' + * Possible values include: 'male', 'female', 'genderless' * @member {number} [faceAttributes.smile] Smile intensity, a number between * [0,1] - * @member {object} [faceAttributes.facialHair] + * @member {object} [faceAttributes.facialHair] Properties describing facial + * hair attributes. * @member {number} [faceAttributes.facialHair.moustache] * @member {number} [faceAttributes.facialHair.beard] * @member {number} [faceAttributes.facialHair.sideburns] * @member {string} [faceAttributes.glasses] Glasses type if any of the face. * Possible values include: 'noGlasses', 'readingGlasses', 'sunglasses', * 'swimmingGoggles' - * @member {object} [faceAttributes.headPose] + * @member {object} [faceAttributes.headPose] Properties indicating head pose + * of the face. * @member {number} [faceAttributes.headPose.roll] * @member {number} [faceAttributes.headPose.yaw] * @member {number} [faceAttributes.headPose.pitch] - * @member {object} [faceAttributes.emotion] + * @member {object} [faceAttributes.emotion] Properties describing facial + * emotion in form of confidence ranging from 0 to 1. * @member {number} [faceAttributes.emotion.anger] * @member {number} [faceAttributes.emotion.contempt] * @member {number} [faceAttributes.emotion.disgust] @@ -191,38 +194,46 @@ class DetectedFace { * @member {number} [faceAttributes.emotion.neutral] * @member {number} [faceAttributes.emotion.sadness] * @member {number} [faceAttributes.emotion.surprise] - * @member {object} [faceAttributes.hair] + * @member {object} [faceAttributes.hair] Properties describing hair + * attributes. * @member {number} [faceAttributes.hair.bald] A number describing confidence * level of whether the person is bald. * @member {boolean} [faceAttributes.hair.invisible] A boolean value * describing whether the hair is visible in the image. - * @member {array} [faceAttributes.hair.hairColor] - * @member {object} [faceAttributes.makeup] + * @member {array} [faceAttributes.hair.hairColor] An array of candidate + * colors and confidence level in the presence of each. + * @member {object} [faceAttributes.makeup] Properties describing present + * makeups on a given face. * @member {boolean} [faceAttributes.makeup.eyeMakeup] A boolean value * describing whether eye makeup is present on a face. * @member {boolean} [faceAttributes.makeup.lipMakeup] A boolean value * describing whether lip makeup is present on a face. - * @member {object} [faceAttributes.occlusion] + * @member {object} [faceAttributes.occlusion] Properties describing + * occlusions on a given face. * @member {boolean} [faceAttributes.occlusion.foreheadOccluded] A boolean * value indicating whether forehead is occluded. * @member {boolean} [faceAttributes.occlusion.eyeOccluded] A boolean value * indicating whether eyes are occluded. * @member {boolean} [faceAttributes.occlusion.mouthOccluded] A boolean value * indicating whether the mouth is occluded. - * @member {array} [faceAttributes.accessories] - * @member {object} [faceAttributes.blur] + * @member {array} [faceAttributes.accessories] Properties describing any + * accessories on a given face. + * @member {object} [faceAttributes.blur] Properties describing any presence + * of blur within the image. * @member {string} [faceAttributes.blur.blurLevel] An enum value indicating * level of blurriness. Possible values include: 'Low', 'Medium', 'High' * @member {number} [faceAttributes.blur.value] A number indicating level of * blurriness ranging from 0 to 1. - * @member {object} [faceAttributes.exposure] + * @member {object} [faceAttributes.exposure] Properties describing exposure + * level of the image. * @member {string} [faceAttributes.exposure.exposureLevel] An enum value * indicating level of exposure. Possible values include: 'UnderExposure', * 'GoodExposure', 'OverExposure' * @member {number} [faceAttributes.exposure.value] A number indicating level * of exposure level ranging from 0 to 1. [0, 0.25) is under exposure. [0.25, * 0.75) is good exposure. [0.75, 1] is over exposure. - * @member {object} [faceAttributes.noise] + * @member {object} [faceAttributes.noise] Properties describing noise level + * of the image. * @member {string} [faceAttributes.noise.noiseLevel] An enum value * indicating level of noise. Possible values include: 'Low', 'Medium', * 'High' @@ -251,9 +262,6 @@ class DetectedFace { faceId: { required: false, serializedName: 'faceId', - constraints: { - MaxLength: 64 - }, type: { name: 'String' } diff --git a/lib/services/face/lib/models/emotion.js b/lib/services/face/lib/models/emotion.js new file mode 100644 index 0000000000..e5c6d7fdf0 --- /dev/null +++ b/lib/services/face/lib/models/emotion.js @@ -0,0 +1,109 @@ +/* + * 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'; + +/** + * Properties describing facial emotion in form of confidence ranging from 0 to + * 1. + * + */ +class Emotion { + /** + * Create a Emotion. + * @member {number} [anger] + * @member {number} [contempt] + * @member {number} [disgust] + * @member {number} [fear] + * @member {number} [happiness] + * @member {number} [neutral] + * @member {number} [sadness] + * @member {number} [surprise] + */ + constructor() { + } + + /** + * Defines the metadata of Emotion + * + * @returns {object} metadata of Emotion + * + */ + mapper() { + return { + required: false, + serializedName: 'Emotion', + type: { + name: 'Composite', + className: 'Emotion', + modelProperties: { + anger: { + required: false, + serializedName: 'anger', + type: { + name: 'Number' + } + }, + contempt: { + required: false, + serializedName: 'contempt', + type: { + name: 'Number' + } + }, + disgust: { + required: false, + serializedName: 'disgust', + type: { + name: 'Number' + } + }, + fear: { + required: false, + serializedName: 'fear', + type: { + name: 'Number' + } + }, + happiness: { + required: false, + serializedName: 'happiness', + type: { + name: 'Number' + } + }, + neutral: { + required: false, + serializedName: 'neutral', + type: { + name: 'Number' + } + }, + sadness: { + required: false, + serializedName: 'sadness', + type: { + name: 'Number' + } + }, + surprise: { + required: false, + serializedName: 'surprise', + type: { + name: 'Number' + } + } + } + } + }; + } +} + +module.exports = Emotion; diff --git a/lib/services/face/lib/models/exposure.js b/lib/services/face/lib/models/exposure.js new file mode 100644 index 0000000000..8a29189488 --- /dev/null +++ b/lib/services/face/lib/models/exposure.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'; + +/** + * Properties describing exposure level of the image. + * + */ +class Exposure { + /** + * Create a Exposure. + * @member {string} [exposureLevel] An enum value indicating level of + * exposure. Possible values include: 'UnderExposure', 'GoodExposure', + * 'OverExposure' + * @member {number} [value] A number indicating level of exposure level + * ranging from 0 to 1. [0, 0.25) is under exposure. [0.25, 0.75) is good + * exposure. [0.75, 1] is over exposure. + */ + constructor() { + } + + /** + * Defines the metadata of Exposure + * + * @returns {object} metadata of Exposure + * + */ + mapper() { + return { + required: false, + serializedName: 'Exposure', + type: { + name: 'Composite', + className: 'Exposure', + modelProperties: { + exposureLevel: { + required: false, + serializedName: 'exposureLevel', + type: { + name: 'Enum', + allowedValues: [ 'UnderExposure', 'GoodExposure', 'OverExposure' ] + } + }, + value: { + required: false, + serializedName: 'value', + type: { + name: 'Number' + } + } + } + } + }; + } +} + +module.exports = Exposure; diff --git a/lib/services/face/lib/models/faceAttributes.js b/lib/services/face/lib/models/faceAttributes.js index a4f8247443..067614b1ad 100644 --- a/lib/services/face/lib/models/faceAttributes.js +++ b/lib/services/face/lib/models/faceAttributes.js @@ -21,20 +21,22 @@ class FaceAttributes { * Create a FaceAttributes. * @member {number} [age] Age in years * @member {string} [gender] Possible gender of the face. Possible values - * include: 'male', 'female' + * include: 'male', 'female', 'genderless' * @member {number} [smile] Smile intensity, a number between [0,1] - * @member {object} [facialHair] + * @member {object} [facialHair] Properties describing facial hair + * attributes. * @member {number} [facialHair.moustache] * @member {number} [facialHair.beard] * @member {number} [facialHair.sideburns] * @member {string} [glasses] Glasses type if any of the face. Possible * values include: 'noGlasses', 'readingGlasses', 'sunglasses', * 'swimmingGoggles' - * @member {object} [headPose] + * @member {object} [headPose] Properties indicating head pose of the face. * @member {number} [headPose.roll] * @member {number} [headPose.yaw] * @member {number} [headPose.pitch] - * @member {object} [emotion] + * @member {object} [emotion] Properties describing facial emotion in form of + * confidence ranging from 0 to 1. * @member {number} [emotion.anger] * @member {number} [emotion.contempt] * @member {number} [emotion.disgust] @@ -43,38 +45,44 @@ class FaceAttributes { * @member {number} [emotion.neutral] * @member {number} [emotion.sadness] * @member {number} [emotion.surprise] - * @member {object} [hair] + * @member {object} [hair] Properties describing hair attributes. * @member {number} [hair.bald] A number describing confidence level of * whether the person is bald. * @member {boolean} [hair.invisible] A boolean value describing whether the * hair is visible in the image. - * @member {array} [hair.hairColor] - * @member {object} [makeup] + * @member {array} [hair.hairColor] An array of candidate colors and + * confidence level in the presence of each. + * @member {object} [makeup] Properties describing present makeups on a given + * face. * @member {boolean} [makeup.eyeMakeup] A boolean value describing whether * eye makeup is present on a face. * @member {boolean} [makeup.lipMakeup] A boolean value describing whether * lip makeup is present on a face. - * @member {object} [occlusion] + * @member {object} [occlusion] Properties describing occlusions on a given + * face. * @member {boolean} [occlusion.foreheadOccluded] A boolean value indicating * whether forehead is occluded. * @member {boolean} [occlusion.eyeOccluded] A boolean value indicating * whether eyes are occluded. * @member {boolean} [occlusion.mouthOccluded] A boolean value indicating * whether the mouth is occluded. - * @member {array} [accessories] - * @member {object} [blur] + * @member {array} [accessories] Properties describing any accessories on a + * given face. + * @member {object} [blur] Properties describing any presence of blur within + * the image. * @member {string} [blur.blurLevel] An enum value indicating level of * blurriness. Possible values include: 'Low', 'Medium', 'High' * @member {number} [blur.value] A number indicating level of blurriness * ranging from 0 to 1. - * @member {object} [exposure] + * @member {object} [exposure] Properties describing exposure level of the + * image. * @member {string} [exposure.exposureLevel] An enum value indicating level * of exposure. Possible values include: 'UnderExposure', 'GoodExposure', * 'OverExposure' * @member {number} [exposure.value] A number indicating level of exposure * level ranging from 0 to 1. [0, 0.25) is under exposure. [0.25, 0.75) is * good exposure. [0.75, 1] is over exposure. - * @member {object} [noise] + * @member {object} [noise] Properties describing noise level of the image. * @member {string} [noise.noiseLevel] An enum value indicating level of * noise. Possible values include: 'Low', 'Medium', 'High' * @member {number} [noise.value] A number indicating level of noise level @@ -111,16 +119,12 @@ class FaceAttributes { serializedName: 'gender', type: { name: 'Enum', - allowedValues: [ 'male', 'female' ] + allowedValues: [ 'male', 'female', 'genderless' ] } }, smile: { required: false, serializedName: 'smile', - constraints: { - InclusiveMaximum: 1, - InclusiveMinimum: 0 - }, type: { name: 'Number' } @@ -130,7 +134,7 @@ class FaceAttributes { serializedName: 'facialHair', type: { name: 'Composite', - className: 'FacialHairProperties' + className: 'FacialHair' } }, glasses: { @@ -146,7 +150,7 @@ class FaceAttributes { serializedName: 'headPose', type: { name: 'Composite', - className: 'HeadPoseProperties' + className: 'HeadPose' } }, emotion: { @@ -154,7 +158,7 @@ class FaceAttributes { serializedName: 'emotion', type: { name: 'Composite', - className: 'EmotionProperties' + className: 'Emotion' } }, hair: { @@ -162,7 +166,7 @@ class FaceAttributes { serializedName: 'hair', type: { name: 'Composite', - className: 'HairProperties' + className: 'Hair' } }, makeup: { @@ -170,7 +174,7 @@ class FaceAttributes { serializedName: 'makeup', type: { name: 'Composite', - className: 'MakeupProperties' + className: 'Makeup' } }, occlusion: { @@ -178,7 +182,7 @@ class FaceAttributes { serializedName: 'occlusion', type: { name: 'Composite', - className: 'OcclusionProperties' + className: 'Occlusion' } }, accessories: { @@ -188,10 +192,10 @@ class FaceAttributes { name: 'Sequence', element: { required: false, - serializedName: 'AccessoryItemElementType', + serializedName: 'AccessoryElementType', type: { name: 'Composite', - className: 'AccessoryItem' + className: 'Accessory' } } } @@ -201,7 +205,7 @@ class FaceAttributes { serializedName: 'blur', type: { name: 'Composite', - className: 'BlurProperties' + className: 'Blur' } }, exposure: { @@ -209,7 +213,7 @@ class FaceAttributes { serializedName: 'exposure', type: { name: 'Composite', - className: 'ExposureProperties' + className: 'Exposure' } }, noise: { @@ -217,7 +221,7 @@ class FaceAttributes { serializedName: 'noise', type: { name: 'Composite', - className: 'NoiseProperties' + className: 'Noise' } } } diff --git a/lib/services/face/lib/models/faceLandmarks.js b/lib/services/face/lib/models/faceLandmarks.js index 15e1b48b78..6aae30cb72 100644 --- a/lib/services/face/lib/models/faceLandmarks.js +++ b/lib/services/face/lib/models/faceLandmarks.js @@ -129,7 +129,7 @@ class FaceLandmarks { serializedName: 'pupilLeft', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, pupilRight: { @@ -137,7 +137,7 @@ class FaceLandmarks { serializedName: 'pupilRight', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, noseTip: { @@ -145,7 +145,7 @@ class FaceLandmarks { serializedName: 'noseTip', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, mouthLeft: { @@ -153,7 +153,7 @@ class FaceLandmarks { serializedName: 'mouthLeft', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, mouthRight: { @@ -161,7 +161,7 @@ class FaceLandmarks { serializedName: 'mouthRight', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, eyebrowLeftOuter: { @@ -169,7 +169,7 @@ class FaceLandmarks { serializedName: 'eyebrowLeftOuter', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, eyebrowLeftInner: { @@ -177,7 +177,7 @@ class FaceLandmarks { serializedName: 'eyebrowLeftInner', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, eyeLeftOuter: { @@ -185,7 +185,7 @@ class FaceLandmarks { serializedName: 'eyeLeftOuter', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, eyeLeftTop: { @@ -193,7 +193,7 @@ class FaceLandmarks { serializedName: 'eyeLeftTop', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, eyeLeftBottom: { @@ -201,7 +201,7 @@ class FaceLandmarks { serializedName: 'eyeLeftBottom', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, eyeLeftInner: { @@ -209,7 +209,7 @@ class FaceLandmarks { serializedName: 'eyeLeftInner', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, eyebrowRightInner: { @@ -217,7 +217,7 @@ class FaceLandmarks { serializedName: 'eyebrowRightInner', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, eyebrowRightOuter: { @@ -225,7 +225,7 @@ class FaceLandmarks { serializedName: 'eyebrowRightOuter', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, eyeRightInner: { @@ -233,7 +233,7 @@ class FaceLandmarks { serializedName: 'eyeRightInner', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, eyeRightTop: { @@ -241,7 +241,7 @@ class FaceLandmarks { serializedName: 'eyeRightTop', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, eyeRightBottom: { @@ -249,7 +249,7 @@ class FaceLandmarks { serializedName: 'eyeRightBottom', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, eyeRightOuter: { @@ -257,7 +257,7 @@ class FaceLandmarks { serializedName: 'eyeRightOuter', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, noseRootLeft: { @@ -265,7 +265,7 @@ class FaceLandmarks { serializedName: 'noseRootLeft', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, noseRootRight: { @@ -273,7 +273,7 @@ class FaceLandmarks { serializedName: 'noseRootRight', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, noseLeftAlarTop: { @@ -281,7 +281,7 @@ class FaceLandmarks { serializedName: 'noseLeftAlarTop', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, noseRightAlarTop: { @@ -289,7 +289,7 @@ class FaceLandmarks { serializedName: 'noseRightAlarTop', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, noseLeftAlarOutTip: { @@ -297,7 +297,7 @@ class FaceLandmarks { serializedName: 'noseLeftAlarOutTip', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, noseRightAlarOutTip: { @@ -305,7 +305,7 @@ class FaceLandmarks { serializedName: 'noseRightAlarOutTip', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, upperLipTop: { @@ -313,7 +313,7 @@ class FaceLandmarks { serializedName: 'upperLipTop', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, upperLipBottom: { @@ -321,7 +321,7 @@ class FaceLandmarks { serializedName: 'upperLipBottom', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, underLipTop: { @@ -329,7 +329,7 @@ class FaceLandmarks { serializedName: 'underLipTop', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } }, underLipBottom: { @@ -337,7 +337,7 @@ class FaceLandmarks { serializedName: 'underLipBottom', type: { name: 'Composite', - className: 'Position' + className: 'Coordinate' } } } diff --git a/lib/services/face/lib/models/faceList.js b/lib/services/face/lib/models/faceList.js new file mode 100644 index 0000000000..0812f53914 --- /dev/null +++ b/lib/services/face/lib/models/faceList.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'; + +const models = require('./index'); + +/** + * Face list object. + * + * @extends models['NameAndUserDataContract'] + */ +class FaceList extends models['NameAndUserDataContract'] { + /** + * Create a FaceList. + * @member {string} faceListId FaceListId of the target face list. + * @member {array} [persistedFaces] Persisted faces within the face list. + */ + constructor() { + super(); + } + + /** + * Defines the metadata of FaceList + * + * @returns {object} metadata of FaceList + * + */ + mapper() { + return { + required: false, + serializedName: 'FaceList', + type: { + name: 'Composite', + className: 'FaceList', + modelProperties: { + name: { + required: false, + serializedName: 'name', + constraints: { + MaxLength: 128 + }, + type: { + name: 'String' + } + }, + userData: { + required: false, + serializedName: 'userData', + constraints: { + MaxLength: 16384 + }, + type: { + name: 'String' + } + }, + faceListId: { + required: true, + serializedName: 'faceListId', + constraints: { + MaxLength: 64, + Pattern: '^[a-z0-9-_]+$' + }, + type: { + name: 'String' + } + }, + persistedFaces: { + required: false, + serializedName: 'persistedFaces', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'PersistedFaceElementType', + type: { + name: 'Composite', + className: 'PersistedFace' + } + } + } + } + } + } + }; + } +} + +module.exports = FaceList; diff --git a/lib/services/face/lib/models/facialHair.js b/lib/services/face/lib/models/facialHair.js new file mode 100644 index 0000000000..c5916bc543 --- /dev/null +++ b/lib/services/face/lib/models/facialHair.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'; + +/** + * Properties describing facial hair attributes. + * + */ +class FacialHair { + /** + * Create a FacialHair. + * @member {number} [moustache] + * @member {number} [beard] + * @member {number} [sideburns] + */ + constructor() { + } + + /** + * Defines the metadata of FacialHair + * + * @returns {object} metadata of FacialHair + * + */ + mapper() { + return { + required: false, + serializedName: 'FacialHair', + type: { + name: 'Composite', + className: 'FacialHair', + modelProperties: { + moustache: { + required: false, + serializedName: 'moustache', + type: { + name: 'Number' + } + }, + beard: { + required: false, + serializedName: 'beard', + type: { + name: 'Number' + } + }, + sideburns: { + required: false, + serializedName: 'sideburns', + type: { + name: 'Number' + } + } + } + } + }; + } +} + +module.exports = FacialHair; diff --git a/lib/services/face/lib/models/findSimilarRequest.js b/lib/services/face/lib/models/findSimilarRequest.js index 7033b1bff1..91d6bf1b17 100644 --- a/lib/services/face/lib/models/findSimilarRequest.js +++ b/lib/services/face/lib/models/findSimilarRequest.js @@ -17,9 +17,9 @@ class FindSimilarRequest { /** * Create a FindSimilarRequest. - * @member {string} faceId FaceId of the query face. User needs to call Face - * - Detect first to get a valid faceId. Note that this faceId is not - * persisted and will expire 24 hours after the detection call + * @member {uuid} faceId FaceId of the query face. User needs to call Face - + * Detect first to get a valid faceId. Note that this faceId is not persisted + * and will expire 24 hours after the detection call * @member {string} [faceListId] An existing user-specified unique candidate * face list, created in Face List - Create a Face List. Face list contains a * set of persistedFaceIds which are persisted and will never expire. @@ -53,9 +53,6 @@ class FindSimilarRequest { faceId: { required: true, serializedName: 'faceId', - constraints: { - MaxLength: 64 - }, type: { name: 'String' } @@ -81,7 +78,7 @@ class FindSimilarRequest { name: 'Sequence', element: { required: false, - serializedName: 'StringElementType', + serializedName: 'UuidElementType', type: { name: 'String' } diff --git a/lib/services/face/lib/models/groupRequest.js b/lib/services/face/lib/models/groupRequest.js index f9b69088ad..ab73763ae1 100644 --- a/lib/services/face/lib/models/groupRequest.js +++ b/lib/services/face/lib/models/groupRequest.js @@ -47,7 +47,7 @@ class GroupRequest { name: 'Sequence', element: { required: false, - serializedName: 'StringElementType', + serializedName: 'UuidElementType', type: { name: 'String' } diff --git a/lib/services/face/lib/models/groupResult.js b/lib/services/face/lib/models/groupResult.js new file mode 100644 index 0000000000..36ace98c7e --- /dev/null +++ b/lib/services/face/lib/models/groupResult.js @@ -0,0 +1,83 @@ +/* + * 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 array of face groups based on face similarity. + * + */ +class GroupResult { + /** + * Create a GroupResult. + * @member {array} groups A partition of the original faces based on face + * similarity. Groups are ranked by number of faces + * @member {array} [messyGroup] Face ids array of faces that cannot find any + * similar faces from original faces. + */ + constructor() { + } + + /** + * Defines the metadata of GroupResult + * + * @returns {object} metadata of GroupResult + * + */ + mapper() { + return { + required: false, + serializedName: 'GroupResult', + type: { + name: 'Composite', + className: 'GroupResult', + modelProperties: { + groups: { + required: true, + serializedName: 'groups', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'ArrayElementType', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'UuidElementType', + type: { + name: 'String' + } + } + } + } + } + }, + messyGroup: { + required: false, + serializedName: 'messyGroup', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'UuidElementType', + type: { + name: 'String' + } + } + } + } + } + } + }; + } +} + +module.exports = GroupResult; diff --git a/lib/services/face/lib/models/hair.js b/lib/services/face/lib/models/hair.js new file mode 100644 index 0000000000..bb7acb1327 --- /dev/null +++ b/lib/services/face/lib/models/hair.js @@ -0,0 +1,81 @@ +/* + * 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'); + +/** + * Properties describing hair attributes. + * + */ +class Hair { + /** + * Create a Hair. + * @member {number} [bald] A number describing confidence level of whether + * the person is bald. + * @member {boolean} [invisible] A boolean value describing whether the hair + * is visible in the image. + * @member {array} [hairColor] An array of candidate colors and confidence + * level in the presence of each. + */ + constructor() { + } + + /** + * Defines the metadata of Hair + * + * @returns {object} metadata of Hair + * + */ + mapper() { + return { + required: false, + serializedName: 'Hair', + type: { + name: 'Composite', + className: 'Hair', + modelProperties: { + bald: { + required: false, + serializedName: 'bald', + type: { + name: 'Number' + } + }, + invisible: { + required: false, + serializedName: 'invisible', + type: { + name: 'Boolean' + } + }, + hairColor: { + required: false, + serializedName: 'hairColor', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'HairColorElementType', + type: { + name: 'Composite', + className: 'HairColor' + } + } + } + } + } + } + }; + } +} + +module.exports = Hair; diff --git a/lib/services/face/lib/models/hairColor.js b/lib/services/face/lib/models/hairColor.js new file mode 100644 index 0000000000..948265c835 --- /dev/null +++ b/lib/services/face/lib/models/hairColor.js @@ -0,0 +1,62 @@ +/* + * 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'; + +/** + * Hair color and associated confidence + * + */ +class HairColor { + /** + * Create a HairColor. + * @member {string} [color] Name of the hair color. Possible values include: + * 'unknown', 'white', 'gray', 'blond', 'brown', 'red', 'black', 'other' + * @member {number} [confidence] Confidence level of the color + */ + constructor() { + } + + /** + * Defines the metadata of HairColor + * + * @returns {object} metadata of HairColor + * + */ + mapper() { + return { + required: false, + serializedName: 'HairColor', + type: { + name: 'Composite', + className: 'HairColor', + modelProperties: { + color: { + required: false, + serializedName: 'color', + type: { + name: 'Enum', + allowedValues: [ 'unknown', 'white', 'gray', 'blond', 'brown', 'red', 'black', 'other' ] + } + }, + confidence: { + required: false, + serializedName: 'confidence', + type: { + name: 'Number' + } + } + } + } + }; + } +} + +module.exports = HairColor; diff --git a/lib/services/face/lib/models/headPose.js b/lib/services/face/lib/models/headPose.js new file mode 100644 index 0000000000..4a8c915e9b --- /dev/null +++ b/lib/services/face/lib/models/headPose.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'; + +/** + * Properties indicating head pose of the face. + * + */ +class HeadPose { + /** + * Create a HeadPose. + * @member {number} [roll] + * @member {number} [yaw] + * @member {number} [pitch] + */ + constructor() { + } + + /** + * Defines the metadata of HeadPose + * + * @returns {object} metadata of HeadPose + * + */ + mapper() { + return { + required: false, + serializedName: 'HeadPose', + type: { + name: 'Composite', + className: 'HeadPose', + modelProperties: { + roll: { + required: false, + serializedName: 'roll', + type: { + name: 'Number' + } + }, + yaw: { + required: false, + serializedName: 'yaw', + type: { + name: 'Number' + } + }, + pitch: { + required: false, + serializedName: 'pitch', + type: { + name: 'Number' + } + } + } + } + }; + } +} + +module.exports = HeadPose; diff --git a/lib/services/face/lib/models/identifyCandidate.js b/lib/services/face/lib/models/identifyCandidate.js new file mode 100644 index 0000000000..f3b92d541c --- /dev/null +++ b/lib/services/face/lib/models/identifyCandidate.js @@ -0,0 +1,62 @@ +/* + * 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'; + +/** + * All possible faces that may qualify. + * + */ +class IdentifyCandidate { + /** + * Create a IdentifyCandidate. + * @member {uuid} personId Id of candidate + * @member {number} confidence Confidence threshold of identification, used + * to judge whether one face belong to one person. The range of + * confidenceThreshold is [0, 1] (default specified by algorithm). + */ + constructor() { + } + + /** + * Defines the metadata of IdentifyCandidate + * + * @returns {object} metadata of IdentifyCandidate + * + */ + mapper() { + return { + required: false, + serializedName: 'IdentifyCandidate', + type: { + name: 'Composite', + className: 'IdentifyCandidate', + modelProperties: { + personId: { + required: true, + serializedName: 'personId', + type: { + name: 'String' + } + }, + confidence: { + required: true, + serializedName: 'confidence', + type: { + name: 'Number' + } + } + } + } + }; + } +} + +module.exports = IdentifyCandidate; diff --git a/lib/services/face/lib/models/identifyRequest.js b/lib/services/face/lib/models/identifyRequest.js index df6ca4d90e..7c10b7d14d 100644 --- a/lib/services/face/lib/models/identifyRequest.js +++ b/lib/services/face/lib/models/identifyRequest.js @@ -17,13 +17,17 @@ class IdentifyRequest { /** * Create a IdentifyRequest. - * @member {string} personGroupId personGroupId of the target person group, + * @member {string} personGroupId PersonGroupId of the target person group, * created by PersonGroups.Create - * @member {array} faceIds Array of candidate faceId created by Face - - * Detect. - * @member {number} [maxNumOfCandidatesReturned] The number of top similar - * faces returned. Default value: 1 . - * @member {number} [confidenceThreshold] + * @member {array} faceIds Array of query faces faceIds, created by the Face + * - Detect. Each of the faces are identified independently. The valid number + * of faceIds is between [1, 10]. + * @member {number} [maxNumOfCandidatesReturned] The range of + * maxNumOfCandidatesReturned is between 1 and 5 (default is 1). Default + * value: 1 . + * @member {number} [confidenceThreshold] Confidence threshold of + * identification, used to judge whether one face belong to one person. The + * range of confidenceThreshold is [0, 1] (default specified by algorithm). */ constructor() { } @@ -45,6 +49,10 @@ class IdentifyRequest { personGroupId: { required: true, serializedName: 'personGroupId', + constraints: { + MaxLength: 64, + Pattern: '^[a-z0-9-_]+$' + }, type: { name: 'String' } @@ -53,13 +61,13 @@ class IdentifyRequest { required: true, serializedName: 'faceIds', constraints: { - MaxItems: 1000 + MaxItems: 10 }, type: { name: 'Sequence', element: { required: false, - serializedName: 'StringElementType', + serializedName: 'UuidElementType', type: { name: 'String' } @@ -71,7 +79,7 @@ class IdentifyRequest { serializedName: 'maxNumOfCandidatesReturned', defaultValue: 1, constraints: { - InclusiveMaximum: 1000, + InclusiveMaximum: 5, InclusiveMinimum: 1 }, type: { diff --git a/lib/services/face/lib/models/identifyResult.js b/lib/services/face/lib/models/identifyResult.js new file mode 100644 index 0000000000..1b77fd4875 --- /dev/null +++ b/lib/services/face/lib/models/identifyResult.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'; + +const models = require('./index'); + +/** + * Response body for identify face operation. + * + */ +class IdentifyResult { + /** + * Create a IdentifyResult. + * @member {uuid} faceId FaceId of the query face + * @member {array} candidates Identified person candidates for that face + * (ranked by confidence). Array size should be no larger than input + * maxNumOfCandidatesReturned. If no person is identified, will return an + * empty array. + */ + constructor() { + } + + /** + * Defines the metadata of IdentifyResult + * + * @returns {object} metadata of IdentifyResult + * + */ + mapper() { + return { + required: false, + serializedName: 'IdentifyResult', + type: { + name: 'Composite', + className: 'IdentifyResult', + modelProperties: { + faceId: { + required: true, + serializedName: 'faceId', + type: { + name: 'String' + } + }, + candidates: { + required: true, + serializedName: 'candidates', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'IdentifyCandidateElementType', + type: { + name: 'Composite', + className: 'IdentifyCandidate' + } + } + } + } + } + } + }; + } +} + +module.exports = IdentifyResult; diff --git a/lib/services/face/lib/models/imageUrl.js b/lib/services/face/lib/models/imageUrl.js index 3feb6972d1..1727196bb1 100644 --- a/lib/services/face/lib/models/imageUrl.js +++ b/lib/services/face/lib/models/imageUrl.js @@ -16,7 +16,7 @@ class ImageUrl { /** * Create a ImageUrl. - * @member {string} url + * @member {string} url Publicly reachable URL of an image */ constructor() { } diff --git a/lib/services/face/lib/models/index.d.ts b/lib/services/face/lib/models/index.d.ts index 90e9031e62..ac054fa25f 100644 --- a/lib/services/face/lib/models/index.d.ts +++ b/lib/services/face/lib/models/index.d.ts @@ -61,14 +61,14 @@ export interface FaceRectangle { /** * @class - * Initializes a new instance of the Position class. + * Initializes a new instance of the Coordinate class. * @constructor * Coordinates within an image * * @member {number} x The horizontal component, in pixels. * @member {number} y The vertical component, in pixels. */ -export interface Position { +export interface Coordinate { x: number; y: number; } @@ -164,38 +164,38 @@ export interface Position { * @member {number} [underLipBottom.y] The vertical component, in pixels. */ export interface FaceLandmarks { - pupilLeft?: Position; - pupilRight?: Position; - noseTip?: Position; - mouthLeft?: Position; - mouthRight?: Position; - eyebrowLeftOuter?: Position; - eyebrowLeftInner?: Position; - eyeLeftOuter?: Position; - eyeLeftTop?: Position; - eyeLeftBottom?: Position; - eyeLeftInner?: Position; - eyebrowRightInner?: Position; - eyebrowRightOuter?: Position; - eyeRightInner?: Position; - eyeRightTop?: Position; - eyeRightBottom?: Position; - eyeRightOuter?: Position; - noseRootLeft?: Position; - noseRootRight?: Position; - noseLeftAlarTop?: Position; - noseRightAlarTop?: Position; - noseLeftAlarOutTip?: Position; - noseRightAlarOutTip?: Position; - upperLipTop?: Position; - upperLipBottom?: Position; - underLipTop?: Position; - underLipBottom?: Position; + pupilLeft?: Coordinate; + pupilRight?: Coordinate; + noseTip?: Coordinate; + mouthLeft?: Coordinate; + mouthRight?: Coordinate; + eyebrowLeftOuter?: Coordinate; + eyebrowLeftInner?: Coordinate; + eyeLeftOuter?: Coordinate; + eyeLeftTop?: Coordinate; + eyeLeftBottom?: Coordinate; + eyeLeftInner?: Coordinate; + eyebrowRightInner?: Coordinate; + eyebrowRightOuter?: Coordinate; + eyeRightInner?: Coordinate; + eyeRightTop?: Coordinate; + eyeRightBottom?: Coordinate; + eyeRightOuter?: Coordinate; + noseRootLeft?: Coordinate; + noseRootRight?: Coordinate; + noseLeftAlarTop?: Coordinate; + noseRightAlarTop?: Coordinate; + noseLeftAlarOutTip?: Coordinate; + noseRightAlarOutTip?: Coordinate; + upperLipTop?: Coordinate; + upperLipBottom?: Coordinate; + underLipTop?: Coordinate; + underLipBottom?: Coordinate; } /** * @class - * Initializes a new instance of the FacialHairProperties class. + * Initializes a new instance of the FacialHair class. * @constructor * Properties describing facial hair attributes. * @@ -203,7 +203,7 @@ export interface FaceLandmarks { * @member {number} [beard] * @member {number} [sideburns] */ -export interface FacialHairProperties { +export interface FacialHair { moustache?: number; beard?: number; sideburns?: number; @@ -211,7 +211,7 @@ export interface FacialHairProperties { /** * @class - * Initializes a new instance of the HeadPoseProperties class. + * Initializes a new instance of the HeadPose class. * @constructor * Properties indicating head pose of the face. * @@ -219,7 +219,7 @@ export interface FacialHairProperties { * @member {number} [yaw] * @member {number} [pitch] */ -export interface HeadPoseProperties { +export interface HeadPose { roll?: number; yaw?: number; pitch?: number; @@ -227,7 +227,7 @@ export interface HeadPoseProperties { /** * @class - * Initializes a new instance of the EmotionProperties class. + * Initializes a new instance of the Emotion class. * @constructor * Properties describing facial emotion in form of confidence ranging from 0 to * 1. @@ -241,7 +241,7 @@ export interface HeadPoseProperties { * @member {number} [sadness] * @member {number} [surprise] */ -export interface EmotionProperties { +export interface Emotion { anger?: number; contempt?: number; disgust?: number; @@ -254,21 +254,22 @@ export interface EmotionProperties { /** * @class - * Initializes a new instance of the ColorProperty class. + * Initializes a new instance of the HairColor class. * @constructor * Hair color and associated confidence * - * @member {string} [color] Name of the color. - * @member {number} [confidence] + * @member {string} [color] Name of the hair color. Possible values include: + * 'unknown', 'white', 'gray', 'blond', 'brown', 'red', 'black', 'other' + * @member {number} [confidence] Confidence level of the color */ -export interface ColorProperty { +export interface HairColor { color?: string; confidence?: number; } /** * @class - * Initializes a new instance of the HairProperties class. + * Initializes a new instance of the Hair class. * @constructor * Properties describing hair attributes. * @@ -276,17 +277,18 @@ export interface ColorProperty { * person is bald. * @member {boolean} [invisible] A boolean value describing whether the hair is * visible in the image. - * @member {array} [hairColor] + * @member {array} [hairColor] An array of candidate colors and confidence + * level in the presence of each. */ -export interface HairProperties { +export interface Hair { bald?: number; invisible?: boolean; - hairColor?: ColorProperty[]; + hairColor?: HairColor[]; } /** * @class - * Initializes a new instance of the MakeupProperties class. + * Initializes a new instance of the Makeup class. * @constructor * Properties describing present makeups on a given face. * @@ -295,16 +297,16 @@ export interface HairProperties { * @member {boolean} [lipMakeup] A boolean value describing whether lip makeup * is present on a face. */ -export interface MakeupProperties { +export interface Makeup { eyeMakeup?: boolean; lipMakeup?: boolean; } /** * @class - * Initializes a new instance of the OcclusionProperties class. + * Initializes a new instance of the Occlusion class. * @constructor - * Properties describing occulusions on a given face. + * Properties describing occlusions on a given face. * * @member {boolean} [foreheadOccluded] A boolean value indicating whether * forehead is occluded. @@ -313,7 +315,7 @@ export interface MakeupProperties { * @member {boolean} [mouthOccluded] A boolean value indicating whether the * mouth is occluded. */ -export interface OcclusionProperties { +export interface Occlusion { foreheadOccluded?: boolean; eyeOccluded?: boolean; mouthOccluded?: boolean; @@ -321,21 +323,22 @@ export interface OcclusionProperties { /** * @class - * Initializes a new instance of the AccessoryItem class. + * Initializes a new instance of the Accessory class. * @constructor * Accessory item and corresponding confidence level. * - * @member {string} [type] Description of an accessory - * @member {number} [confidence] + * @member {string} [type] Type of an accessory. Possible values include: + * 'headWear', 'glasses', 'mask' + * @member {number} [confidence] Confidence level of an accessory */ -export interface AccessoryItem { +export interface Accessory { type?: string; confidence?: number; } /** * @class - * Initializes a new instance of the BlurProperties class. + * Initializes a new instance of the Blur class. * @constructor * Properties describing any presence of blur within the image. * @@ -344,14 +347,14 @@ export interface AccessoryItem { * @member {number} [value] A number indicating level of blurriness ranging * from 0 to 1. */ -export interface BlurProperties { +export interface Blur { blurLevel?: string; value?: number; } /** * @class - * Initializes a new instance of the ExposureProperties class. + * Initializes a new instance of the Exposure class. * @constructor * Properties describing exposure level of the image. * @@ -361,14 +364,14 @@ export interface BlurProperties { * from 0 to 1. [0, 0.25) is under exposure. [0.25, 0.75) is good exposure. * [0.75, 1] is over exposure. */ -export interface ExposureProperties { +export interface Exposure { exposureLevel?: string; value?: number; } /** * @class - * Initializes a new instance of the NoiseProperties class. + * Initializes a new instance of the Noise class. * @constructor * Properties describing noise level of the image. * @@ -379,7 +382,7 @@ export interface ExposureProperties { * [0.75, 1] is over exposure. [0, 0.3) is low noise level. [0.3, 0.7) is * medium noise level. [0.7, 1] is high noise level. */ -export interface NoiseProperties { +export interface Noise { noiseLevel?: string; value?: number; } @@ -392,19 +395,20 @@ export interface NoiseProperties { * * @member {number} [age] Age in years * @member {string} [gender] Possible gender of the face. Possible values - * include: 'male', 'female' + * include: 'male', 'female', 'genderless' * @member {number} [smile] Smile intensity, a number between [0,1] - * @member {object} [facialHair] + * @member {object} [facialHair] Properties describing facial hair attributes. * @member {number} [facialHair.moustache] * @member {number} [facialHair.beard] * @member {number} [facialHair.sideburns] * @member {string} [glasses] Glasses type if any of the face. Possible values * include: 'noGlasses', 'readingGlasses', 'sunglasses', 'swimmingGoggles' - * @member {object} [headPose] + * @member {object} [headPose] Properties indicating head pose of the face. * @member {number} [headPose.roll] * @member {number} [headPose.yaw] * @member {number} [headPose.pitch] - * @member {object} [emotion] + * @member {object} [emotion] Properties describing facial emotion in form of + * confidence ranging from 0 to 1. * @member {number} [emotion.anger] * @member {number} [emotion.contempt] * @member {number} [emotion.disgust] @@ -413,38 +417,44 @@ export interface NoiseProperties { * @member {number} [emotion.neutral] * @member {number} [emotion.sadness] * @member {number} [emotion.surprise] - * @member {object} [hair] + * @member {object} [hair] Properties describing hair attributes. * @member {number} [hair.bald] A number describing confidence level of whether * the person is bald. * @member {boolean} [hair.invisible] A boolean value describing whether the * hair is visible in the image. - * @member {array} [hair.hairColor] - * @member {object} [makeup] + * @member {array} [hair.hairColor] An array of candidate colors and confidence + * level in the presence of each. + * @member {object} [makeup] Properties describing present makeups on a given + * face. * @member {boolean} [makeup.eyeMakeup] A boolean value describing whether eye * makeup is present on a face. * @member {boolean} [makeup.lipMakeup] A boolean value describing whether lip * makeup is present on a face. - * @member {object} [occlusion] + * @member {object} [occlusion] Properties describing occlusions on a given + * face. * @member {boolean} [occlusion.foreheadOccluded] A boolean value indicating * whether forehead is occluded. * @member {boolean} [occlusion.eyeOccluded] A boolean value indicating whether * eyes are occluded. * @member {boolean} [occlusion.mouthOccluded] A boolean value indicating * whether the mouth is occluded. - * @member {array} [accessories] - * @member {object} [blur] + * @member {array} [accessories] Properties describing any accessories on a + * given face. + * @member {object} [blur] Properties describing any presence of blur within + * the image. * @member {string} [blur.blurLevel] An enum value indicating level of * blurriness. Possible values include: 'Low', 'Medium', 'High' * @member {number} [blur.value] A number indicating level of blurriness * ranging from 0 to 1. - * @member {object} [exposure] + * @member {object} [exposure] Properties describing exposure level of the + * image. * @member {string} [exposure.exposureLevel] An enum value indicating level of * exposure. Possible values include: 'UnderExposure', 'GoodExposure', * 'OverExposure' * @member {number} [exposure.value] A number indicating level of exposure * level ranging from 0 to 1. [0, 0.25) is under exposure. [0.25, 0.75) is good * exposure. [0.75, 1] is over exposure. - * @member {object} [noise] + * @member {object} [noise] Properties describing noise level of the image. * @member {string} [noise.noiseLevel] An enum value indicating level of noise. * Possible values include: 'Low', 'Medium', 'High' * @member {number} [noise.value] A number indicating level of noise level @@ -456,17 +466,17 @@ export interface FaceAttributes { age?: number; gender?: string; smile?: number; - facialHair?: FacialHairProperties; + facialHair?: FacialHair; glasses?: string; - headPose?: HeadPoseProperties; - emotion?: EmotionProperties; - hair?: HairProperties; - makeup?: MakeupProperties; - occlusion?: OcclusionProperties; - accessories?: AccessoryItem[]; - blur?: BlurProperties; - exposure?: ExposureProperties; - noise?: NoiseProperties; + headPose?: HeadPose; + emotion?: Emotion; + hair?: Hair; + makeup?: Makeup; + occlusion?: Occlusion; + accessories?: Accessory[]; + blur?: Blur; + exposure?: Exposure; + noise?: Noise; } /** @@ -475,7 +485,7 @@ export interface FaceAttributes { * @constructor * Detected Face object. * - * @member {string} [faceId] + * @member {uuid} [faceId] * @member {object} faceRectangle * @member {number} [faceRectangle.width] The width of the rectangle, in * pixels. @@ -624,21 +634,24 @@ export interface FaceAttributes { * @member {object} [faceAttributes] * @member {number} [faceAttributes.age] Age in years * @member {string} [faceAttributes.gender] Possible gender of the face. - * Possible values include: 'male', 'female' + * Possible values include: 'male', 'female', 'genderless' * @member {number} [faceAttributes.smile] Smile intensity, a number between * [0,1] - * @member {object} [faceAttributes.facialHair] + * @member {object} [faceAttributes.facialHair] Properties describing facial + * hair attributes. * @member {number} [faceAttributes.facialHair.moustache] * @member {number} [faceAttributes.facialHair.beard] * @member {number} [faceAttributes.facialHair.sideburns] * @member {string} [faceAttributes.glasses] Glasses type if any of the face. * Possible values include: 'noGlasses', 'readingGlasses', 'sunglasses', * 'swimmingGoggles' - * @member {object} [faceAttributes.headPose] + * @member {object} [faceAttributes.headPose] Properties indicating head pose + * of the face. * @member {number} [faceAttributes.headPose.roll] * @member {number} [faceAttributes.headPose.yaw] * @member {number} [faceAttributes.headPose.pitch] - * @member {object} [faceAttributes.emotion] + * @member {object} [faceAttributes.emotion] Properties describing facial + * emotion in form of confidence ranging from 0 to 1. * @member {number} [faceAttributes.emotion.anger] * @member {number} [faceAttributes.emotion.contempt] * @member {number} [faceAttributes.emotion.disgust] @@ -647,38 +660,46 @@ export interface FaceAttributes { * @member {number} [faceAttributes.emotion.neutral] * @member {number} [faceAttributes.emotion.sadness] * @member {number} [faceAttributes.emotion.surprise] - * @member {object} [faceAttributes.hair] + * @member {object} [faceAttributes.hair] Properties describing hair + * attributes. * @member {number} [faceAttributes.hair.bald] A number describing confidence * level of whether the person is bald. * @member {boolean} [faceAttributes.hair.invisible] A boolean value describing * whether the hair is visible in the image. - * @member {array} [faceAttributes.hair.hairColor] - * @member {object} [faceAttributes.makeup] + * @member {array} [faceAttributes.hair.hairColor] An array of candidate colors + * and confidence level in the presence of each. + * @member {object} [faceAttributes.makeup] Properties describing present + * makeups on a given face. * @member {boolean} [faceAttributes.makeup.eyeMakeup] A boolean value * describing whether eye makeup is present on a face. * @member {boolean} [faceAttributes.makeup.lipMakeup] A boolean value * describing whether lip makeup is present on a face. - * @member {object} [faceAttributes.occlusion] + * @member {object} [faceAttributes.occlusion] Properties describing occlusions + * on a given face. * @member {boolean} [faceAttributes.occlusion.foreheadOccluded] A boolean * value indicating whether forehead is occluded. * @member {boolean} [faceAttributes.occlusion.eyeOccluded] A boolean value * indicating whether eyes are occluded. * @member {boolean} [faceAttributes.occlusion.mouthOccluded] A boolean value * indicating whether the mouth is occluded. - * @member {array} [faceAttributes.accessories] - * @member {object} [faceAttributes.blur] + * @member {array} [faceAttributes.accessories] Properties describing any + * accessories on a given face. + * @member {object} [faceAttributes.blur] Properties describing any presence of + * blur within the image. * @member {string} [faceAttributes.blur.blurLevel] An enum value indicating * level of blurriness. Possible values include: 'Low', 'Medium', 'High' * @member {number} [faceAttributes.blur.value] A number indicating level of * blurriness ranging from 0 to 1. - * @member {object} [faceAttributes.exposure] + * @member {object} [faceAttributes.exposure] Properties describing exposure + * level of the image. * @member {string} [faceAttributes.exposure.exposureLevel] An enum value * indicating level of exposure. Possible values include: 'UnderExposure', * 'GoodExposure', 'OverExposure' * @member {number} [faceAttributes.exposure.value] A number indicating level * of exposure level ranging from 0 to 1. [0, 0.25) is under exposure. [0.25, * 0.75) is good exposure. [0.75, 1] is over exposure. - * @member {object} [faceAttributes.noise] + * @member {object} [faceAttributes.noise] Properties describing noise level of + * the image. * @member {string} [faceAttributes.noise.noiseLevel] An enum value indicating * level of noise. Possible values include: 'Low', 'Medium', 'High' * @member {number} [faceAttributes.noise.value] A number indicating level of @@ -693,27 +714,13 @@ export interface DetectedFace { faceAttributes?: FaceAttributes; } -/** - * @class - * Initializes a new instance of the PersistedFaceResult class. - * @constructor - * Persisted face result. - * - * @member {string} persistedFaceId persistedFaceId of candidate face when find - * by faceListId. persistedFaceId in face list is persisted and will not - * expire. As showed in below response - */ -export interface PersistedFaceResult { - persistedFaceId: string; -} - /** * @class * Initializes a new instance of the FindSimilarRequest class. * @constructor * Request body for find similar operation. * - * @member {string} faceId FaceId of the query face. User needs to call Face - + * @member {uuid} faceId FaceId of the query face. User needs to call Face - * Detect first to get a valid faceId. Note that this faceId is not persisted * and will expire 24 hours after the detection call * @member {string} [faceListId] An existing user-specified unique candidate @@ -739,22 +746,23 @@ export interface FindSimilarRequest { /** * @class - * Initializes a new instance of the SimilarFaceResult class. + * Initializes a new instance of the SimilarFace class. * @constructor * Response body for find similar face operation. * - * @member {string} [faceId] faceId of candidate face when find by faceIds. + * @member {uuid} [faceId] FaceId of candidate face when find by faceIds. * faceId is created by Face - Detect and will expire 24 hours after the * detection call - * @member {string} [persistedFaceId] persistedFaceId of candidate face when - * find by faceListId. persistedFaceId in face list is persisted and will not + * @member {uuid} [persistedFaceId] PersistedFaceId of candidate face when find + * by faceListId. persistedFaceId in face list is persisted and will not * expire. As showed in below response - * @member {number} [confidence] + * @member {number} confidence Similarity confidence of the candidate face. The + * higher confidence, the more similar. Range between [0,1]. */ -export interface SimilarFaceResult { +export interface SimilarFace { faceId?: string; persistedFaceId?: string; - confidence?: number; + confidence: number; } /** @@ -772,7 +780,7 @@ export interface GroupRequest { /** * @class - * Initializes a new instance of the GroupResponse class. + * Initializes a new instance of the GroupResult class. * @constructor * An array of face groups based on face similarity. * @@ -781,7 +789,7 @@ export interface GroupRequest { * @member {array} [messyGroup] Face ids array of faces that cannot find any * similar faces from original faces. */ -export interface GroupResponse { +export interface GroupResult { groups: string[][]; messyGroup?: string[]; } @@ -792,12 +800,17 @@ export interface GroupResponse { * @constructor * Request body for identify face operation. * - * @member {string} personGroupId personGroupId of the target person group, + * @member {string} personGroupId PersonGroupId of the target person group, * created by PersonGroups.Create - * @member {array} faceIds Array of candidate faceId created by Face - Detect. - * @member {number} [maxNumOfCandidatesReturned] The number of top similar - * faces returned. Default value: 1 . - * @member {number} [confidenceThreshold] + * @member {array} faceIds Array of query faces faceIds, created by the Face - + * Detect. Each of the faces are identified independently. The valid number of + * faceIds is between [1, 10]. + * @member {number} [maxNumOfCandidatesReturned] The range of + * maxNumOfCandidatesReturned is between 1 and 5 (default is 1). Default value: + * 1 . + * @member {number} [confidenceThreshold] Confidence threshold of + * identification, used to judge whether one face belong to one person. The + * range of confidenceThreshold is [0, 1] (default specified by algorithm). */ export interface IdentifyRequest { personGroupId: string; @@ -808,61 +821,66 @@ export interface IdentifyRequest { /** * @class - * Initializes a new instance of the IdentifyResultCandidate class. + * Initializes a new instance of the IdentifyCandidate class. * @constructor * All possible faces that may qualify. * - * @member {string} personId Id of candidate - * @member {number} confidence + * @member {uuid} personId Id of candidate + * @member {number} confidence Confidence threshold of identification, used to + * judge whether one face belong to one person. The range of + * confidenceThreshold is [0, 1] (default specified by algorithm). */ -export interface IdentifyResultCandidate { +export interface IdentifyCandidate { personId: string; confidence: number; } /** * @class - * Initializes a new instance of the IdentifyResultItem class. + * Initializes a new instance of the IdentifyResult class. * @constructor * Response body for identify face operation. * - * @member {string} faceId faceId of the query face - * @member {array} candidates + * @member {uuid} faceId FaceId of the query face + * @member {array} candidates Identified person candidates for that face + * (ranked by confidence). Array size should be no larger than input + * maxNumOfCandidatesReturned. If no person is identified, will return an empty + * array. */ -export interface IdentifyResultItem { +export interface IdentifyResult { faceId: string; - candidates: IdentifyResultCandidate[]; + candidates: IdentifyCandidate[]; } /** * @class - * Initializes a new instance of the VerifyPersonGroupRequest class. + * Initializes a new instance of the VerifyFaceToPersonRequest class. * @constructor * Request body for verify operation. * - * @member {string} faceId faceId the face, comes from Face - Detect - * @member {string} personId Specify a certain person in a person group. - * personId is created in Persons.Create. + * @member {uuid} faceId FaceId the face, comes from Face - Detect * @member {string} personGroupId Using existing personGroupId and personId for * fast loading a specified person. personGroupId is created in Person * Groups.Create. + * @member {uuid} personId Specify a certain person in a person group. personId + * is created in Persons.Create. */ -export interface VerifyPersonGroupRequest { +export interface VerifyFaceToPersonRequest { faceId: string; - personId: string; personGroupId: string; + personId: string; } /** * @class - * Initializes a new instance of the VerifyRequest class. + * Initializes a new instance of the VerifyFaceToFaceRequest class. * @constructor * Request body for verify operation. * - * @member {string} faceId1 faceId of the first face, comes from Face - Detect - * @member {string} faceId2 faceId of the second face, comes from Face - Detect + * @member {uuid} faceId1 FaceId of the first face, comes from Face - Detect + * @member {uuid} faceId2 FaceId of the second face, comes from Face - Detect */ -export interface VerifyRequest { +export interface VerifyFaceToFaceRequest { faceId1: string; faceId2: string; } @@ -875,157 +893,108 @@ export interface VerifyRequest { * * @member {boolean} isIdentical True if the two faces belong to the same * person or the face belongs to the person, otherwise false. - * @member {number} [confidence] + * @member {number} confidence A number indicates the similarity confidence of + * whether two faces belong to the same person, or whether the face belongs to + * the person. By default, isIdentical is set to True if similarity confidence + * is greater than or equal to 0.5. This is useful for advanced users to + * override "isIdentical" and fine-tune the result on their own data. */ export interface VerifyResult { isIdentical: boolean; - confidence?: number; -} - -/** - * @class - * Initializes a new instance of the CreateFaceListRequest class. - * @constructor - * Request to create a face list. - * - * @member {string} [name] Name of the face list, maximum length is 128. - * @member {string} [userData] Optional user defined data for the face list. - * Length should not exceed 16KB. - */ -export interface CreateFaceListRequest { - name?: string; - userData?: string; + confidence: number; } /** * @class - * Initializes a new instance of the PersonFaceResult class. + * Initializes a new instance of the PersistedFace class. * @constructor * PersonFace object. * - * @member {string} persistedFaceId The persistedFaceId of the target face, - * which is persisted and will not expire. Different from faceId created by - * Face - Detect and will expire in 24 hours after the detection call. - * @member {string} [userData] User-provided data attached to the face. + * @member {uuid} persistedFaceId The persistedFaceId of the target face, which + * is persisted and will not expire. Different from faceId created by Face - + * Detect and will expire in 24 hours after the detection call. + * @member {string} [userData] User-provided data attached to the face. The + * size limit is 1KB. */ -export interface PersonFaceResult { +export interface PersistedFace { persistedFaceId: string; userData?: string; } /** * @class - * Initializes a new instance of the GetFaceListResult class. + * Initializes a new instance of the NameAndUserDataContract class. * @constructor - * Result of the GetFaceList operation. + * A combination of user defined name and user specified data for the person, + * personGroup, and faceList * - * @member {string} faceListId faceListId of the target face list. - * @member {string} [name] Face list's display name. - * @member {string} [userData] User-provided data attached to this face list. - * @member {array} [persistedFaces] Persisted faces within the face list. + * @member {string} [name] User defined name, maximum length is 128. + * @member {string} [userData] User specified data. Length should not exceed + * 16KB. */ -export interface GetFaceListResult { - faceListId: string; +export interface NameAndUserDataContract { name?: string; userData?: string; - persistedFaces?: PersonFaceResult[]; } /** * @class - * Initializes a new instance of the CreatePersonGroupRequest class. + * Initializes a new instance of the FaceList class. * @constructor - * Request to create a person group. + * Face list object. * - * @member {string} [name] Name of the face list, maximum length is 128. - * @member {string} [userData] Optional user defined data for the face list. - * Length should not exceed 16KB. + * @member {string} faceListId FaceListId of the target face list. + * @member {array} [persistedFaces] Persisted faces within the face list. */ -export interface CreatePersonGroupRequest { - name?: string; - userData?: string; +export interface FaceList extends NameAndUserDataContract { + faceListId: string; + persistedFaces?: PersistedFace[]; } /** * @class - * Initializes a new instance of the PersonGroupResult class. + * Initializes a new instance of the PersonGroup class. * @constructor * Person group object. * - * @member {string} personGroupId faceListId of the target face list. - * @member {string} [name] Face list's display name. - * @member {string} [userData] User-provided data attached to this face list. + * @member {string} personGroupId PersonGroupId of the existing person groups. */ -export interface PersonGroupResult { +export interface PersonGroup extends NameAndUserDataContract { personGroupId: string; - name?: string; - userData?: string; -} - -/** - * @class - * Initializes a new instance of the CreatePersonRequest class. - * @constructor - * Request to create a person object. - * - * @member {string} [name] Display name of the target person. The maximum - * length is 128. - * @member {string} [userData] Optional fields for user-provided data attached - * to a person. Size limit is 16KB. - */ -export interface CreatePersonRequest { - name?: string; - userData?: string; -} - -/** - * @class - * Initializes a new instance of the CreatePersonResult class. - * @constructor - * Result of creating person. - * - * @member {string} personId personID of the new created person. - */ -export interface CreatePersonResult { - personId: string; } /** * @class - * Initializes a new instance of the PersonResult class. + * Initializes a new instance of the Person class. * @constructor * Person object. * - * @member {string} personId personId of the target face list. - * @member {array} [persistedFaceIds] persistedFaceIds of registered faces in + * @member {uuid} personId PersonId of the target face list. + * @member {array} [persistedFaceIds] PersistedFaceIds of registered faces in * the person. These persistedFaceIds are returned from Person - Add a Person * Face, and will not expire. - * @member {string} [name] Person's display name. - * @member {string} [userData] User-provided data attached to this person. */ -export interface PersonResult { +export interface Person extends NameAndUserDataContract { personId: string; persistedFaceIds?: string[]; - name?: string; - userData?: string; } /** * @class - * Initializes a new instance of the UpdatePersonFaceDataRequest class. + * Initializes a new instance of the UpdatePersonFaceRequest class. * @constructor * Request to update person face data. * * @member {string} [userData] User-provided data attached to the face. The - * size limit is 1KB + * size limit is 1KB. */ -export interface UpdatePersonFaceDataRequest { +export interface UpdatePersonFaceRequest { userData?: string; } /** * @class - * Initializes a new instance of the TrainingStatus1 class. + * Initializes a new instance of the TrainingStatus class. * @constructor * Training status object. * @@ -1035,16 +1004,16 @@ export interface UpdatePersonFaceDataRequest { * succeed means this person group is ready for Face - Identify. Status failed * is often caused by no person or no persisted face exist in the person group. * Possible values include: 'nonstarted', 'running', 'succeeded', 'failed' - * @member {date} [created] A combined UTC date and time string that describes + * @member {date} created A combined UTC date and time string that describes * person group created time. * @member {date} [lastAction] Person group last modify time in the UTC, could * be null value when the person group is not successfully trained. * @member {string} [message] Show failure message when training failed * (omitted when training succeed). */ -export interface TrainingStatus1 { +export interface TrainingStatus { status: string; - created?: Date; + created: Date; lastAction?: Date; message?: string; } @@ -1053,7 +1022,7 @@ export interface TrainingStatus1 { * @class * Initializes a new instance of the ImageUrl class. * @constructor - * @member {string} url + * @member {string} url Publicly reachable URL of an image */ export interface ImageUrl { url: string; diff --git a/lib/services/face/lib/models/index.js b/lib/services/face/lib/models/index.js index 52bea8ca75..ab6fd3d5b8 100644 --- a/lib/services/face/lib/models/index.js +++ b/lib/services/face/lib/models/index.js @@ -17,40 +17,36 @@ exports.ErrorModel = require('./errorModel'); exports.APIError = require('./aPIError'); exports.FaceRectangle = require('./faceRectangle'); -exports.Position = require('./position'); +exports.Coordinate = require('./coordinate'); exports.FaceLandmarks = require('./faceLandmarks'); -exports.FacialHairProperties = require('./facialHairProperties'); -exports.HeadPoseProperties = require('./headPoseProperties'); -exports.EmotionProperties = require('./emotionProperties'); -exports.ColorProperty = require('./colorProperty'); -exports.HairProperties = require('./hairProperties'); -exports.MakeupProperties = require('./makeupProperties'); -exports.OcclusionProperties = require('./occlusionProperties'); -exports.AccessoryItem = require('./accessoryItem'); -exports.BlurProperties = require('./blurProperties'); -exports.ExposureProperties = require('./exposureProperties'); -exports.NoiseProperties = require('./noiseProperties'); +exports.FacialHair = require('./facialHair'); +exports.HeadPose = require('./headPose'); +exports.Emotion = require('./emotion'); +exports.HairColor = require('./hairColor'); +exports.Hair = require('./hair'); +exports.Makeup = require('./makeup'); +exports.Occlusion = require('./occlusion'); +exports.Accessory = require('./accessory'); +exports.Blur = require('./blur'); +exports.Exposure = require('./exposure'); +exports.Noise = require('./noise'); exports.FaceAttributes = require('./faceAttributes'); exports.DetectedFace = require('./detectedFace'); -exports.PersistedFaceResult = require('./persistedFaceResult'); exports.FindSimilarRequest = require('./findSimilarRequest'); -exports.SimilarFaceResult = require('./similarFaceResult'); +exports.SimilarFace = require('./similarFace'); exports.GroupRequest = require('./groupRequest'); -exports.GroupResponse = require('./groupResponse'); +exports.GroupResult = require('./groupResult'); exports.IdentifyRequest = require('./identifyRequest'); -exports.IdentifyResultCandidate = require('./identifyResultCandidate'); -exports.IdentifyResultItem = require('./identifyResultItem'); -exports.VerifyPersonGroupRequest = require('./verifyPersonGroupRequest'); -exports.VerifyRequest = require('./verifyRequest'); +exports.IdentifyCandidate = require('./identifyCandidate'); +exports.IdentifyResult = require('./identifyResult'); +exports.VerifyFaceToPersonRequest = require('./verifyFaceToPersonRequest'); +exports.VerifyFaceToFaceRequest = require('./verifyFaceToFaceRequest'); exports.VerifyResult = require('./verifyResult'); -exports.CreateFaceListRequest = require('./createFaceListRequest'); -exports.PersonFaceResult = require('./personFaceResult'); -exports.GetFaceListResult = require('./getFaceListResult'); -exports.CreatePersonGroupRequest = require('./createPersonGroupRequest'); -exports.PersonGroupResult = require('./personGroupResult'); -exports.CreatePersonRequest = require('./createPersonRequest'); -exports.CreatePersonResult = require('./createPersonResult'); -exports.PersonResult = require('./personResult'); -exports.UpdatePersonFaceDataRequest = require('./updatePersonFaceDataRequest'); -exports.TrainingStatus1 = require('./trainingStatus1'); +exports.PersistedFace = require('./persistedFace'); +exports.NameAndUserDataContract = require('./nameAndUserDataContract'); +exports.FaceList = require('./faceList'); +exports.PersonGroup = require('./personGroup'); +exports.Person = require('./person'); +exports.UpdatePersonFaceRequest = require('./updatePersonFaceRequest'); +exports.TrainingStatus = require('./trainingStatus'); exports.ImageUrl = require('./imageUrl'); diff --git a/lib/services/face/lib/models/makeup.js b/lib/services/face/lib/models/makeup.js new file mode 100644 index 0000000000..c142e488ad --- /dev/null +++ b/lib/services/face/lib/models/makeup.js @@ -0,0 +1,62 @@ +/* + * 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'; + +/** + * Properties describing present makeups on a given face. + * + */ +class Makeup { + /** + * Create a Makeup. + * @member {boolean} [eyeMakeup] A boolean value describing whether eye + * makeup is present on a face. + * @member {boolean} [lipMakeup] A boolean value describing whether lip + * makeup is present on a face. + */ + constructor() { + } + + /** + * Defines the metadata of Makeup + * + * @returns {object} metadata of Makeup + * + */ + mapper() { + return { + required: false, + serializedName: 'Makeup', + type: { + name: 'Composite', + className: 'Makeup', + modelProperties: { + eyeMakeup: { + required: false, + serializedName: 'eyeMakeup', + type: { + name: 'Boolean' + } + }, + lipMakeup: { + required: false, + serializedName: 'lipMakeup', + type: { + name: 'Boolean' + } + } + } + } + }; + } +} + +module.exports = Makeup; diff --git a/lib/services/face/lib/models/nameAndUserDataContract.js b/lib/services/face/lib/models/nameAndUserDataContract.js new file mode 100644 index 0000000000..a4f0946a26 --- /dev/null +++ b/lib/services/face/lib/models/nameAndUserDataContract.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'; + +/** + * A combination of user defined name and user specified data for the person, + * personGroup, and faceList + * + */ +class NameAndUserDataContract { + /** + * Create a NameAndUserDataContract. + * @member {string} [name] User defined name, maximum length is 128. + * @member {string} [userData] User specified data. Length should not exceed + * 16KB. + */ + constructor() { + } + + /** + * Defines the metadata of NameAndUserDataContract + * + * @returns {object} metadata of NameAndUserDataContract + * + */ + mapper() { + return { + required: false, + serializedName: 'NameAndUserDataContract', + type: { + name: 'Composite', + className: 'NameAndUserDataContract', + modelProperties: { + name: { + required: false, + serializedName: 'name', + constraints: { + MaxLength: 128 + }, + type: { + name: 'String' + } + }, + userData: { + required: false, + serializedName: 'userData', + constraints: { + MaxLength: 16384 + }, + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = NameAndUserDataContract; diff --git a/lib/services/face/lib/models/noise.js b/lib/services/face/lib/models/noise.js new file mode 100644 index 0000000000..952a76345c --- /dev/null +++ b/lib/services/face/lib/models/noise.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'; + +/** + * Properties describing noise level of the image. + * + */ +class Noise { + /** + * Create a Noise. + * @member {string} [noiseLevel] An enum value indicating level of noise. + * Possible values include: 'Low', 'Medium', 'High' + * @member {number} [value] A number indicating level of noise level ranging + * from 0 to 1. [0, 0.25) is under exposure. [0.25, 0.75) is good exposure. + * [0.75, 1] is over exposure. [0, 0.3) is low noise level. [0.3, 0.7) is + * medium noise level. [0.7, 1] is high noise level. + */ + constructor() { + } + + /** + * Defines the metadata of Noise + * + * @returns {object} metadata of Noise + * + */ + mapper() { + return { + required: false, + serializedName: 'Noise', + type: { + name: 'Composite', + className: 'Noise', + modelProperties: { + noiseLevel: { + required: false, + serializedName: 'noiseLevel', + type: { + name: 'Enum', + allowedValues: [ 'Low', 'Medium', 'High' ] + } + }, + value: { + required: false, + serializedName: 'value', + type: { + name: 'Number' + } + } + } + } + }; + } +} + +module.exports = Noise; diff --git a/lib/services/face/lib/models/occlusion.js b/lib/services/face/lib/models/occlusion.js new file mode 100644 index 0000000000..9a2493e202 --- /dev/null +++ b/lib/services/face/lib/models/occlusion.js @@ -0,0 +1,71 @@ +/* + * 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'; + +/** + * Properties describing occlusions on a given face. + * + */ +class Occlusion { + /** + * Create a Occlusion. + * @member {boolean} [foreheadOccluded] A boolean value indicating whether + * forehead is occluded. + * @member {boolean} [eyeOccluded] A boolean value indicating whether eyes + * are occluded. + * @member {boolean} [mouthOccluded] A boolean value indicating whether the + * mouth is occluded. + */ + constructor() { + } + + /** + * Defines the metadata of Occlusion + * + * @returns {object} metadata of Occlusion + * + */ + mapper() { + return { + required: false, + serializedName: 'Occlusion', + type: { + name: 'Composite', + className: 'Occlusion', + modelProperties: { + foreheadOccluded: { + required: false, + serializedName: 'foreheadOccluded', + type: { + name: 'Boolean' + } + }, + eyeOccluded: { + required: false, + serializedName: 'eyeOccluded', + type: { + name: 'Boolean' + } + }, + mouthOccluded: { + required: false, + serializedName: 'mouthOccluded', + type: { + name: 'Boolean' + } + } + } + } + }; + } +} + +module.exports = Occlusion; diff --git a/lib/services/face/lib/models/persistedFace.js b/lib/services/face/lib/models/persistedFace.js new file mode 100644 index 0000000000..3af70d34ab --- /dev/null +++ b/lib/services/face/lib/models/persistedFace.js @@ -0,0 +1,66 @@ +/* + * 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'; + +/** + * PersonFace object. + * + */ +class PersistedFace { + /** + * Create a PersistedFace. + * @member {uuid} persistedFaceId The persistedFaceId of the target face, + * which is persisted and will not expire. Different from faceId created by + * Face - Detect and will expire in 24 hours after the detection call. + * @member {string} [userData] User-provided data attached to the face. The + * size limit is 1KB. + */ + constructor() { + } + + /** + * Defines the metadata of PersistedFace + * + * @returns {object} metadata of PersistedFace + * + */ + mapper() { + return { + required: false, + serializedName: 'PersistedFace', + type: { + name: 'Composite', + className: 'PersistedFace', + modelProperties: { + persistedFaceId: { + required: true, + serializedName: 'persistedFaceId', + type: { + name: 'String' + } + }, + userData: { + required: false, + serializedName: 'userData', + constraints: { + MaxLength: 1024 + }, + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = PersistedFace; diff --git a/lib/services/face/lib/models/person.js b/lib/services/face/lib/models/person.js new file mode 100644 index 0000000000..b7f228ae69 --- /dev/null +++ b/lib/services/face/lib/models/person.js @@ -0,0 +1,93 @@ +/* + * 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'); + +/** + * Person object. + * + * @extends models['NameAndUserDataContract'] + */ +class Person extends models['NameAndUserDataContract'] { + /** + * Create a Person. + * @member {uuid} personId PersonId of the target face list. + * @member {array} [persistedFaceIds] PersistedFaceIds of registered faces in + * the person. These persistedFaceIds are returned from Person - Add a Person + * Face, and will not expire. + */ + constructor() { + super(); + } + + /** + * Defines the metadata of Person + * + * @returns {object} metadata of Person + * + */ + mapper() { + return { + required: false, + serializedName: 'Person', + type: { + name: 'Composite', + className: 'Person', + modelProperties: { + name: { + required: false, + serializedName: 'name', + constraints: { + MaxLength: 128 + }, + type: { + name: 'String' + } + }, + userData: { + required: false, + serializedName: 'userData', + constraints: { + MaxLength: 16384 + }, + type: { + name: 'String' + } + }, + personId: { + required: true, + serializedName: 'personId', + type: { + name: 'String' + } + }, + persistedFaceIds: { + required: false, + serializedName: 'persistedFaceIds', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'UuidElementType', + type: { + name: 'String' + } + } + } + } + } + } + }; + } +} + +module.exports = Person; diff --git a/lib/services/face/lib/models/personGroup.js b/lib/services/face/lib/models/personGroup.js new file mode 100644 index 0000000000..6bcc60b369 --- /dev/null +++ b/lib/services/face/lib/models/personGroup.js @@ -0,0 +1,81 @@ +/* + * 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'); + +/** + * Person group object. + * + * @extends models['NameAndUserDataContract'] + */ +class PersonGroup extends models['NameAndUserDataContract'] { + /** + * Create a PersonGroup. + * @member {string} personGroupId PersonGroupId of the existing person + * groups. + */ + constructor() { + super(); + } + + /** + * Defines the metadata of PersonGroup + * + * @returns {object} metadata of PersonGroup + * + */ + mapper() { + return { + required: false, + serializedName: 'PersonGroup', + type: { + name: 'Composite', + className: 'PersonGroup', + modelProperties: { + name: { + required: false, + serializedName: 'name', + constraints: { + MaxLength: 128 + }, + type: { + name: 'String' + } + }, + userData: { + required: false, + serializedName: 'userData', + constraints: { + MaxLength: 16384 + }, + type: { + name: 'String' + } + }, + personGroupId: { + required: true, + serializedName: 'personGroupId', + constraints: { + MaxLength: 64, + Pattern: '^[a-z0-9-_]+$' + }, + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = PersonGroup; diff --git a/lib/services/face/lib/models/similarFace.js b/lib/services/face/lib/models/similarFace.js new file mode 100644 index 0000000000..67438f1183 --- /dev/null +++ b/lib/services/face/lib/models/similarFace.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'; + +/** + * Response body for find similar face operation. + * + */ +class SimilarFace { + /** + * Create a SimilarFace. + * @member {uuid} [faceId] FaceId of candidate face when find by faceIds. + * faceId is created by Face - Detect and will expire 24 hours after the + * detection call + * @member {uuid} [persistedFaceId] PersistedFaceId of candidate face when + * find by faceListId. persistedFaceId in face list is persisted and will not + * expire. As showed in below response + * @member {number} confidence Similarity confidence of the candidate face. + * The higher confidence, the more similar. Range between [0,1]. + */ + constructor() { + } + + /** + * Defines the metadata of SimilarFace + * + * @returns {object} metadata of SimilarFace + * + */ + mapper() { + return { + required: false, + serializedName: 'SimilarFace', + type: { + name: 'Composite', + className: 'SimilarFace', + modelProperties: { + faceId: { + required: false, + serializedName: 'faceId', + type: { + name: 'String' + } + }, + persistedFaceId: { + required: false, + serializedName: 'persistedFaceId', + type: { + name: 'String' + } + }, + confidence: { + required: true, + serializedName: 'confidence', + type: { + name: 'Number' + } + } + } + } + }; + } +} + +module.exports = SimilarFace; diff --git a/lib/services/face/lib/models/trainingStatus.js b/lib/services/face/lib/models/trainingStatus.js index 66c6b31b02..9b71f28137 100644 --- a/lib/services/face/lib/models/trainingStatus.js +++ b/lib/services/face/lib/models/trainingStatus.js @@ -24,8 +24,8 @@ class TrainingStatus { * failed is often caused by no person or no persisted face exist in the * person group. Possible values include: 'nonstarted', 'running', * 'succeeded', 'failed' - * @member {date} [created] A combined UTC date and time string that - * describes person group created time. + * @member {date} created A combined UTC date and time string that describes + * person group created time. * @member {date} [lastAction] Person group last modify time in the UTC, * could be null value when the person group is not successfully trained. * @member {string} [message] Show failure message when training failed @@ -52,11 +52,12 @@ class TrainingStatus { required: true, serializedName: 'status', type: { - name: 'String' + name: 'Enum', + allowedValues: [ 'nonstarted', 'running', 'succeeded', 'failed' ] } }, created: { - required: false, + required: true, serializedName: 'createdDateTime', type: { name: 'DateTime' diff --git a/lib/services/face/lib/models/updatePersonFaceRequest.js b/lib/services/face/lib/models/updatePersonFaceRequest.js new file mode 100644 index 0000000000..7101b19fe4 --- /dev/null +++ b/lib/services/face/lib/models/updatePersonFaceRequest.js @@ -0,0 +1,56 @@ +/* + * 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'; + +/** + * Request to update person face data. + * + */ +class UpdatePersonFaceRequest { + /** + * Create a UpdatePersonFaceRequest. + * @member {string} [userData] User-provided data attached to the face. The + * size limit is 1KB. + */ + constructor() { + } + + /** + * Defines the metadata of UpdatePersonFaceRequest + * + * @returns {object} metadata of UpdatePersonFaceRequest + * + */ + mapper() { + return { + required: false, + serializedName: 'UpdatePersonFaceRequest', + type: { + name: 'Composite', + className: 'UpdatePersonFaceRequest', + modelProperties: { + userData: { + required: false, + serializedName: 'userData', + constraints: { + MaxLength: 1024 + }, + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = UpdatePersonFaceRequest; diff --git a/lib/services/face/lib/models/verifyFaceToFaceRequest.js b/lib/services/face/lib/models/verifyFaceToFaceRequest.js new file mode 100644 index 0000000000..cbc3534599 --- /dev/null +++ b/lib/services/face/lib/models/verifyFaceToFaceRequest.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'; + +/** + * Request body for verify operation. + * + */ +class VerifyFaceToFaceRequest { + /** + * Create a VerifyFaceToFaceRequest. + * @member {uuid} faceId1 FaceId of the first face, comes from Face - Detect + * @member {uuid} faceId2 FaceId of the second face, comes from Face - Detect + */ + constructor() { + } + + /** + * Defines the metadata of VerifyFaceToFaceRequest + * + * @returns {object} metadata of VerifyFaceToFaceRequest + * + */ + mapper() { + return { + required: false, + serializedName: 'VerifyFaceToFaceRequest', + type: { + name: 'Composite', + className: 'VerifyFaceToFaceRequest', + modelProperties: { + faceId1: { + required: true, + serializedName: 'faceId1', + type: { + name: 'String' + } + }, + faceId2: { + required: true, + serializedName: 'faceId2', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = VerifyFaceToFaceRequest; diff --git a/lib/services/face/lib/models/verifyFaceToPersonRequest.js b/lib/services/face/lib/models/verifyFaceToPersonRequest.js new file mode 100644 index 0000000000..04b4e51e1e --- /dev/null +++ b/lib/services/face/lib/models/verifyFaceToPersonRequest.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'; + +/** + * Request body for verify operation. + * + */ +class VerifyFaceToPersonRequest { + /** + * Create a VerifyFaceToPersonRequest. + * @member {uuid} faceId FaceId the face, comes from Face - Detect + * @member {string} personGroupId Using existing personGroupId and personId + * for fast loading a specified person. personGroupId is created in Person + * Groups.Create. + * @member {uuid} personId Specify a certain person in a person group. + * personId is created in Persons.Create. + */ + constructor() { + } + + /** + * Defines the metadata of VerifyFaceToPersonRequest + * + * @returns {object} metadata of VerifyFaceToPersonRequest + * + */ + mapper() { + return { + required: false, + serializedName: 'VerifyFaceToPersonRequest', + type: { + name: 'Composite', + className: 'VerifyFaceToPersonRequest', + modelProperties: { + faceId: { + required: true, + serializedName: 'faceId', + type: { + name: 'String' + } + }, + personGroupId: { + required: true, + serializedName: 'personGroupId', + constraints: { + MaxLength: 64, + Pattern: '^[a-z0-9-_]+$' + }, + type: { + name: 'String' + } + }, + personId: { + required: true, + serializedName: 'personId', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = VerifyFaceToPersonRequest; diff --git a/lib/services/face/lib/models/verifyResult.js b/lib/services/face/lib/models/verifyResult.js index 725cbb4928..9a8269bcbf 100644 --- a/lib/services/face/lib/models/verifyResult.js +++ b/lib/services/face/lib/models/verifyResult.js @@ -19,7 +19,12 @@ class VerifyResult { * Create a VerifyResult. * @member {boolean} isIdentical True if the two faces belong to the same * person or the face belongs to the person, otherwise false. - * @member {number} [confidence] + * @member {number} confidence A number indicates the similarity confidence + * of whether two faces belong to the same person, or whether the face + * belongs to the person. By default, isIdentical is set to True if + * similarity confidence is greater than or equal to 0.5. This is useful for + * advanced users to override "isIdentical" and fine-tune the result on their + * own data. */ constructor() { } @@ -46,7 +51,7 @@ class VerifyResult { } }, confidence: { - required: false, + required: true, serializedName: 'confidence', type: { name: 'Number' diff --git a/lib/services/face/lib/operations/face.js b/lib/services/face/lib/operations/face.js index e49d3d0d85..f1f9a07708 100644 --- a/lib/services/face/lib/operations/face.js +++ b/lib/services/face/lib/operations/face.js @@ -17,7 +17,7 @@ const WebResource = msRest.WebResource; * Given query face's faceId, find the similar-looking faces from a faceId * array or a faceListId. * - * @param {string} faceId FaceId of the query face. User needs to call Face - + * @param {uuid} faceId FaceId of the query face. User needs to call Face - * Detect first to get a valid faceId. Note that this faceId is not persisted * and will expire 24 hours after the detection call * @@ -71,23 +71,11 @@ function _findSimilar(faceId, options, callback) { let mode = (options && options.mode !== undefined) ? options.mode : 'matchPerson'; // Validate try { - if (this.client.azureRegion) { - let allowedValues = [ 'westus', 'westeurope', 'southeastasia', 'eastus2', 'westcentralus', 'westus2', 'eastus', 'southcentralus', 'northeurope', 'eastasia', 'australiaeast', 'brazilsouth' ]; - let enumValue = this.client.azureRegion; - if (!allowedValues.some( function(item) { return item === enumValue; })) { - throw new Error(enumValue + ' is not a valid value. The valid values are: ' + allowedValues); - } - } else { - throw new Error('this.client.azureRegion cannot be null or undefined.'); + 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 (faceId === null || faceId === undefined || typeof faceId.valueOf() !== 'string') { - throw new Error('faceId cannot be null or undefined and it must be of type string.'); - } - if (faceId !== null && faceId !== undefined) { - if (faceId.length > 64) - { - throw new Error('"faceId" should satisfy the constraint - "MaxLength": 64'); - } + if (faceId === null || faceId === undefined || typeof faceId.valueOf() !== 'string' || !msRest.isValidUuid(faceId)) { + throw new Error('faceId cannot be null or undefined and it must be of type string and must be a valid uuid.'); } if (faceListId !== null && faceListId !== undefined && typeof faceListId.valueOf() !== 'string') { throw new Error('faceListId must be of type string.'); @@ -104,8 +92,8 @@ function _findSimilar(faceId, options, callback) { } if (Array.isArray(faceIds)) { for (let i = 0; i < faceIds.length; i++) { - if (faceIds[i] !== null && faceIds[i] !== undefined && typeof faceIds[i].valueOf() !== 'string') { - throw new Error('faceIds[i] must be of type string.'); + if (faceIds[i] !== null && faceIds[i] !== undefined && !(typeof faceIds[i].valueOf() === 'string' && msRest.isValidUuid(faceIds[i]))) { + throw new Error('faceIds[i] must be of type string and must be a valid uuid.'); } } } @@ -129,9 +117,9 @@ function _findSimilar(faceId, options, callback) { } } if (mode) { - let allowedValues1 = [ 'matchPerson', 'matchFace' ]; - if (!allowedValues1.some( function(item) { return item === mode; })) { - throw new Error(mode + ' is not a valid value. The valid values are: ' + allowedValues1); + let allowedValues = [ 'matchPerson', 'matchFace' ]; + if (!allowedValues.some( function(item) { return item === mode; })) { + throw new Error(mode + ' is not a valid value. The valid values are: ' + allowedValues); } } } catch (error) { @@ -150,7 +138,7 @@ function _findSimilar(faceId, options, callback) { // Construct URL let baseUrl = this.client.baseUri; let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'findsimilars'; - requestUrl = requestUrl.replace('{AzureRegion}', this.client.azureRegion); + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); // Create HTTP transport objects let httpRequest = new WebResource(); @@ -230,10 +218,10 @@ function _findSimilar(faceId, options, callback) { name: 'Sequence', element: { required: false, - serializedName: 'SimilarFaceResultElementType', + serializedName: 'SimilarFaceElementType', type: { name: 'Composite', - className: 'SimilarFaceResult' + className: 'SimilarFace' } } } @@ -270,7 +258,7 @@ function _findSimilar(faceId, options, callback) { * {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 GroupResponse} for more information. + * See {@link GroupResult} for more information. * * {object} [request] - The HTTP Request object if an error did not occur. * @@ -288,21 +276,15 @@ function _group(faceIds, options, callback) { } // Validate try { - if (this.client.azureRegion) { - let allowedValues = [ 'westus', 'westeurope', 'southeastasia', 'eastus2', 'westcentralus', 'westus2', 'eastus', 'southcentralus', 'northeurope', 'eastasia', 'australiaeast', 'brazilsouth' ]; - let enumValue = this.client.azureRegion; - if (!allowedValues.some( function(item) { return item === enumValue; })) { - throw new Error(enumValue + ' is not a valid value. The valid values are: ' + allowedValues); - } - } else { - throw new Error('this.client.azureRegion cannot be null or undefined.'); + 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 (!Array.isArray(faceIds)) { throw new Error('faceIds cannot be null or undefined and it must be of type array.'); } for (let i = 0; i < faceIds.length; i++) { - if (faceIds[i] !== null && faceIds[i] !== undefined && typeof faceIds[i].valueOf() !== 'string') { - throw new Error('faceIds[i] must be of type string.'); + if (faceIds[i] !== null && faceIds[i] !== undefined && !(typeof faceIds[i].valueOf() === 'string' && msRest.isValidUuid(faceIds[i]))) { + throw new Error('faceIds[i] must be of type string and must be a valid uuid.'); } } if (faceIds !== null && faceIds !== undefined) { @@ -323,7 +305,7 @@ function _group(faceIds, options, callback) { // Construct URL let baseUrl = this.client.baseUri; let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'group'; - requestUrl = requestUrl.replace('{AzureRegion}', this.client.azureRegion); + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); // Create HTTP transport objects let httpRequest = new WebResource(); @@ -396,7 +378,7 @@ function _group(faceIds, options, callback) { parsedResponse = JSON.parse(responseBody); result = JSON.parse(responseBody); if (parsedResponse !== null && parsedResponse !== undefined) { - let resultMapper = new client.models['GroupResponse']().mapper(); + let resultMapper = new client.models['GroupResult']().mapper(); result = client.deserialize(resultMapper, parsedResponse, 'result'); } } catch (error) { @@ -414,17 +396,21 @@ function _group(faceIds, options, callback) { /** * Identify unknown faces from a person group. * - * @param {string} personGroupId personGroupId of the target person group, + * @param {string} personGroupId PersonGroupId of the target person group, * created by PersonGroups.Create * - * @param {array} faceIds Array of candidate faceId created by Face - Detect. + * @param {array} faceIds Array of query faces faceIds, created by the Face - + * Detect. Each of the faces are identified independently. The valid number of + * faceIds is between [1, 10]. * * @param {object} [options] Optional Parameters. * - * @param {number} [options.maxNumOfCandidatesReturned] The number of top - * similar faces returned. + * @param {number} [options.maxNumOfCandidatesReturned] The range of + * maxNumOfCandidatesReturned is between 1 and 5 (default is 1). * - * @param {number} [options.confidenceThreshold] + * @param {number} [options.confidenceThreshold] Confidence threshold of + * identification, used to judge whether one face belong to one person. The + * range of confidenceThreshold is [0, 1] (default specified by algorithm). * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -455,39 +441,43 @@ function _identify(personGroupId, faceIds, options, callback) { let confidenceThreshold = (options && options.confidenceThreshold !== undefined) ? options.confidenceThreshold : undefined; // Validate try { - if (this.client.azureRegion) { - let allowedValues = [ 'westus', 'westeurope', 'southeastasia', 'eastus2', 'westcentralus', 'westus2', 'eastus', 'southcentralus', 'northeurope', 'eastasia', 'australiaeast', 'brazilsouth' ]; - let enumValue = this.client.azureRegion; - if (!allowedValues.some( function(item) { return item === enumValue; })) { - throw new Error(enumValue + ' is not a valid value. The valid values are: ' + allowedValues); - } - } else { - throw new Error('this.client.azureRegion cannot be null or undefined.'); + 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } if (!Array.isArray(faceIds)) { throw new Error('faceIds cannot be null or undefined and it must be of type array.'); } for (let i = 0; i < faceIds.length; i++) { - if (faceIds[i] !== null && faceIds[i] !== undefined && typeof faceIds[i].valueOf() !== 'string') { - throw new Error('faceIds[i] must be of type string.'); + if (faceIds[i] !== null && faceIds[i] !== undefined && !(typeof faceIds[i].valueOf() === 'string' && msRest.isValidUuid(faceIds[i]))) { + throw new Error('faceIds[i] must be of type string and must be a valid uuid.'); } } if (faceIds !== null && faceIds !== undefined) { - if (faceIds.length > 1000) + if (faceIds.length > 10) { - throw new Error('"faceIds" should satisfy the constraint - "MaxItems": 1000'); + throw new Error('"faceIds" should satisfy the constraint - "MaxItems": 10'); } } if (maxNumOfCandidatesReturned !== null && maxNumOfCandidatesReturned !== undefined && typeof maxNumOfCandidatesReturned !== 'number') { throw new Error('maxNumOfCandidatesReturned must be of type number.'); } if (maxNumOfCandidatesReturned !== null && maxNumOfCandidatesReturned !== undefined) { - if (maxNumOfCandidatesReturned > 1000) + if (maxNumOfCandidatesReturned > 5) { - throw new Error('"maxNumOfCandidatesReturned" should satisfy the constraint - "InclusiveMaximum": 1000'); + throw new Error('"maxNumOfCandidatesReturned" should satisfy the constraint - "InclusiveMaximum": 5'); } if (maxNumOfCandidatesReturned < 1) { @@ -512,7 +502,7 @@ function _identify(personGroupId, faceIds, options, callback) { // Construct URL let baseUrl = this.client.baseUri; let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'identify'; - requestUrl = requestUrl.replace('{AzureRegion}', this.client.azureRegion); + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); // Create HTTP transport objects let httpRequest = new WebResource(); @@ -592,10 +582,10 @@ function _identify(personGroupId, faceIds, options, callback) { name: 'Sequence', element: { required: false, - serializedName: 'IdentifyResultItemElementType', + serializedName: 'IdentifyResultElementType', type: { name: 'Composite', - className: 'IdentifyResultItem' + className: 'IdentifyResult' } } } @@ -618,9 +608,9 @@ function _identify(personGroupId, faceIds, options, callback) { * Verify whether two faces belong to a same person or whether one face belongs * to a person. * - * @param {string} faceId1 faceId of the first face, comes from Face - Detect + * @param {uuid} faceId1 FaceId of the first face, comes from Face - Detect * - * @param {string} faceId2 faceId of the second face, comes from Face - Detect + * @param {uuid} faceId2 FaceId of the second face, comes from Face - Detect * * @param {object} [options] Optional Parameters. * @@ -640,7 +630,7 @@ function _identify(personGroupId, faceIds, options, callback) { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _verify(faceId1, faceId2, options, callback) { +function _verifyFaceToFace(faceId1, faceId2, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -652,39 +642,21 @@ function _verify(faceId1, faceId2, options, callback) { } // Validate try { - if (this.client.azureRegion) { - let allowedValues = [ 'westus', 'westeurope', 'southeastasia', 'eastus2', 'westcentralus', 'westus2', 'eastus', 'southcentralus', 'northeurope', 'eastasia', 'australiaeast', 'brazilsouth' ]; - let enumValue = this.client.azureRegion; - if (!allowedValues.some( function(item) { return item === enumValue; })) { - throw new Error(enumValue + ' is not a valid value. The valid values are: ' + allowedValues); - } - } else { - throw new Error('this.client.azureRegion cannot be null or undefined.'); - } - if (faceId1 === null || faceId1 === undefined || typeof faceId1.valueOf() !== 'string') { - throw new Error('faceId1 cannot be null or undefined and it must be of type string.'); - } - if (faceId1 !== null && faceId1 !== undefined) { - if (faceId1.length > 64) - { - throw new Error('"faceId1" should satisfy the constraint - "MaxLength": 64'); - } + 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 (faceId2 === null || faceId2 === undefined || typeof faceId2.valueOf() !== 'string') { - throw new Error('faceId2 cannot be null or undefined and it must be of type string.'); + if (faceId1 === null || faceId1 === undefined || typeof faceId1.valueOf() !== 'string' || !msRest.isValidUuid(faceId1)) { + throw new Error('faceId1 cannot be null or undefined and it must be of type string and must be a valid uuid.'); } - if (faceId2 !== null && faceId2 !== undefined) { - if (faceId2.length > 64) - { - throw new Error('"faceId2" should satisfy the constraint - "MaxLength": 64'); - } + if (faceId2 === null || faceId2 === undefined || typeof faceId2.valueOf() !== 'string' || !msRest.isValidUuid(faceId2)) { + throw new Error('faceId2 cannot be null or undefined and it must be of type string and must be a valid uuid.'); } } catch (error) { return callback(error); } let body; if ((faceId1 !== null && faceId1 !== undefined) || (faceId2 !== null && faceId2 !== undefined)) { - body = new client.models['VerifyRequest'](); + body = new client.models['VerifyFaceToFaceRequest'](); body.faceId1 = faceId1; body.faceId2 = faceId2; } @@ -692,7 +664,7 @@ function _verify(faceId1, faceId2, options, callback) { // Construct URL let baseUrl = this.client.baseUri; let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'verify'; - requestUrl = requestUrl.replace('{AzureRegion}', this.client.azureRegion); + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); // Create HTTP transport objects let httpRequest = new WebResource(); @@ -713,7 +685,7 @@ function _verify(faceId1, faceId2, options, callback) { let requestModel = null; try { if (body !== null && body !== undefined) { - let requestModelMapper = new client.models['VerifyRequest']().mapper(); + let requestModelMapper = new client.models['VerifyFaceToFaceRequest']().mapper(); requestModel = client.serialize(requestModelMapper, body, 'body'); requestContent = JSON.stringify(requestModel); } @@ -784,7 +756,7 @@ function _verify(faceId1, faceId2, options, callback) { * Detect human faces in an image and returns face locations, and optionally * with faceIds, landmarks, and attributes. * - * @param {string} url + * @param {string} url Publicly reachable URL of an image * * @param {object} [options] Optional Parameters. * @@ -815,7 +787,7 @@ function _verify(faceId1, faceId2, options, callback) { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _detect(url, options, callback) { +function _detectWithUrl(url, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -830,14 +802,8 @@ function _detect(url, options, callback) { let returnFaceAttributes = (options && options.returnFaceAttributes !== undefined) ? options.returnFaceAttributes : undefined; // Validate try { - if (this.client.azureRegion) { - let allowedValues = [ 'westus', 'westeurope', 'southeastasia', 'eastus2', 'westcentralus', 'westus2', 'eastus', 'southcentralus', 'northeurope', 'eastasia', 'australiaeast', 'brazilsouth' ]; - let enumValue = this.client.azureRegion; - if (!allowedValues.some( function(item) { return item === enumValue; })) { - throw new Error(enumValue + ' is not a valid value. The valid values are: ' + allowedValues); - } - } else { - throw new Error('this.client.azureRegion cannot be null or undefined.'); + 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 (returnFaceId !== null && returnFaceId !== undefined && typeof returnFaceId !== 'boolean') { throw new Error('returnFaceId must be of type boolean.'); @@ -848,9 +814,9 @@ function _detect(url, options, callback) { if (Array.isArray(returnFaceAttributes)) { for (let i = 0; i < returnFaceAttributes.length; i++) { if (returnFaceAttributes[i]) { - let allowedValues1 = [ 'age', 'gender', 'headPose', 'smile', 'facialHair', 'glasses', 'emotion', 'hair', 'makeup', 'occlusion', 'accessories', 'blur', 'exposure', 'noise' ]; - if (!allowedValues1.some( function(item) { return item === returnFaceAttributes[i]; })) { - throw new Error(returnFaceAttributes[i] + ' is not a valid value. The valid values are: ' + allowedValues1); + let allowedValues = [ 'age', 'gender', 'headPose', 'smile', 'facialHair', 'glasses', 'emotion', 'hair', 'makeup', 'occlusion', 'accessories', 'blur', 'exposure', 'noise' ]; + if (!allowedValues.some( function(item) { return item === returnFaceAttributes[i]; })) { + throw new Error(returnFaceAttributes[i] + ' is not a valid value. The valid values are: ' + allowedValues); } } } @@ -870,7 +836,7 @@ function _detect(url, options, callback) { // Construct URL let baseUrl = this.client.baseUri; let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'detect'; - requestUrl = requestUrl.replace('{AzureRegion}', this.client.azureRegion); + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); let queryParameters = []; if (returnFaceId !== null && returnFaceId !== undefined) { queryParameters.push('returnFaceId=' + encodeURIComponent(returnFaceId.toString())); @@ -989,15 +955,15 @@ function _detect(url, options, callback) { * Verify whether two faces belong to a same person. Compares a face Id with a * Person Id * - * @param {string} faceId faceId the face, comes from Face - Detect - * - * @param {string} personId Specify a certain person in a person group. - * personId is created in Persons.Create. + * @param {uuid} faceId FaceId the face, comes from Face - Detect * * @param {string} personGroupId Using existing personGroupId and personId for * fast loading a specified person. personGroupId is created in Person * Groups.Create. * + * @param {uuid} personId Specify a certain person in a person group. personId + * is created in Persons.Create. + * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -1016,7 +982,7 @@ function _detect(url, options, callback) { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _verifyWithPersonGroup(faceId, personId, personGroupId, options, callback) { +function _verifyFaceToPerson(faceId, personGroupId, personId, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -1028,45 +994,43 @@ function _verifyWithPersonGroup(faceId, personId, personGroupId, options, callba } // Validate try { - if (this.client.azureRegion) { - let allowedValues = [ 'westus', 'westeurope', 'southeastasia', 'eastus2', 'westcentralus', 'westus2', 'eastus', 'southcentralus', 'northeurope', 'eastasia', 'australiaeast', 'brazilsouth' ]; - let enumValue = this.client.azureRegion; - if (!allowedValues.some( function(item) { return item === enumValue; })) { - throw new Error(enumValue + ' is not a valid value. The valid values are: ' + allowedValues); - } - } else { - throw new Error('this.client.azureRegion cannot be null or undefined.'); + 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 (faceId === null || faceId === undefined || typeof faceId.valueOf() !== 'string') { - throw new Error('faceId cannot be null or undefined and it must be of type string.'); + if (faceId === null || faceId === undefined || typeof faceId.valueOf() !== 'string' || !msRest.isValidUuid(faceId)) { + throw new Error('faceId cannot be null or undefined and it must be of type string and must be a valid uuid.'); } - if (faceId !== null && faceId !== undefined) { - if (faceId.length > 64) + if (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) { - throw new Error('"faceId" should satisfy the constraint - "MaxLength": 64'); + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); } } - if (personId === null || personId === undefined || typeof personId.valueOf() !== 'string') { - throw new Error('personId cannot be null or undefined and it must be of type string.'); - } - if (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { - throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + if (personId === null || personId === undefined || typeof personId.valueOf() !== 'string' || !msRest.isValidUuid(personId)) { + throw new Error('personId cannot be null or undefined and it must be of type string and must be a valid uuid.'); } } catch (error) { return callback(error); } let body; - if ((faceId !== null && faceId !== undefined) || (personId !== null && personId !== undefined) || (personGroupId !== null && personGroupId !== undefined)) { - body = new client.models['VerifyPersonGroupRequest'](); + if ((faceId !== null && faceId !== undefined) || (personGroupId !== null && personGroupId !== undefined) || (personId !== null && personId !== undefined)) { + body = new client.models['VerifyFaceToPersonRequest'](); body.faceId = faceId; - body.personId = personId; body.personGroupId = personGroupId; + body.personId = personId; } // Construct URL let baseUrl = this.client.baseUri; let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'verify'; - requestUrl = requestUrl.replace('{AzureRegion}', this.client.azureRegion); + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); // Create HTTP transport objects let httpRequest = new WebResource(); @@ -1087,7 +1051,7 @@ function _verifyWithPersonGroup(faceId, personId, personGroupId, options, callba let requestModel = null; try { if (body !== null && body !== undefined) { - let requestModelMapper = new client.models['VerifyPersonGroupRequest']().mapper(); + let requestModelMapper = new client.models['VerifyFaceToPersonRequest']().mapper(); requestModel = client.serialize(requestModelMapper, body, 'body'); requestContent = JSON.stringify(requestModel); } @@ -1189,7 +1153,7 @@ function _verifyWithPersonGroup(faceId, personId, personGroupId, options, callba * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _detectInStream(image, options, callback) { +function _detectWithStream(image, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -1204,14 +1168,8 @@ function _detectInStream(image, options, callback) { let returnFaceAttributes = (options && options.returnFaceAttributes !== undefined) ? options.returnFaceAttributes : undefined; // Validate try { - if (this.client.azureRegion) { - let allowedValues = [ 'westus', 'westeurope', 'southeastasia', 'eastus2', 'westcentralus', 'westus2', 'eastus', 'southcentralus', 'northeurope', 'eastasia', 'australiaeast', 'brazilsouth' ]; - let enumValue = this.client.azureRegion; - if (!allowedValues.some( function(item) { return item === enumValue; })) { - throw new Error(enumValue + ' is not a valid value. The valid values are: ' + allowedValues); - } - } else { - throw new Error('this.client.azureRegion cannot be null or undefined.'); + 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 (returnFaceId !== null && returnFaceId !== undefined && typeof returnFaceId !== 'boolean') { throw new Error('returnFaceId must be of type boolean.'); @@ -1222,9 +1180,9 @@ function _detectInStream(image, options, callback) { if (Array.isArray(returnFaceAttributes)) { for (let i = 0; i < returnFaceAttributes.length; i++) { if (returnFaceAttributes[i]) { - let allowedValues1 = [ 'age', 'gender', 'headPose', 'smile', 'facialHair', 'glasses', 'emotion', 'hair', 'makeup', 'occlusion', 'accessories', 'blur', 'exposure', 'noise' ]; - if (!allowedValues1.some( function(item) { return item === returnFaceAttributes[i]; })) { - throw new Error(returnFaceAttributes[i] + ' is not a valid value. The valid values are: ' + allowedValues1); + let allowedValues = [ 'age', 'gender', 'headPose', 'smile', 'facialHair', 'glasses', 'emotion', 'hair', 'makeup', 'occlusion', 'accessories', 'blur', 'exposure', 'noise' ]; + if (!allowedValues.some( function(item) { return item === returnFaceAttributes[i]; })) { + throw new Error(returnFaceAttributes[i] + ' is not a valid value. The valid values are: ' + allowedValues); } } } @@ -1239,7 +1197,7 @@ function _detectInStream(image, options, callback) { // Construct URL let baseUrl = this.client.baseUri; let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'detect'; - requestUrl = requestUrl.replace('{AzureRegion}', this.client.azureRegion); + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); let queryParameters = []; if (returnFaceId !== null && returnFaceId !== undefined) { queryParameters.push('returnFaceId=' + encodeURIComponent(returnFaceId.toString())); @@ -1346,24 +1304,24 @@ function _detectInStream(image, options, callback) { class Face { /** * Create a Face. - * @param {FaceAPIClient} client Reference to the service client. + * @param {FaceClient} client Reference to the service client. */ constructor(client) { this.client = client; this._findSimilar = _findSimilar; this._group = _group; this._identify = _identify; - this._verify = _verify; - this._detect = _detect; - this._verifyWithPersonGroup = _verifyWithPersonGroup; - this._detectInStream = _detectInStream; + this._verifyFaceToFace = _verifyFaceToFace; + this._detectWithUrl = _detectWithUrl; + this._verifyFaceToPerson = _verifyFaceToPerson; + this._detectWithStream = _detectWithStream; } /** * Given query face's faceId, find the similar-looking faces from a faceId * array or a faceListId. * - * @param {string} faceId FaceId of the query face. User needs to call Face - + * @param {uuid} faceId FaceId of the query face. User needs to call Face - * Detect first to get a valid faceId. Note that this faceId is not persisted * and will expire 24 hours after the detection call * @@ -1413,7 +1371,7 @@ class Face { * Given query face's faceId, find the similar-looking faces from a faceId * array or a faceListId. * - * @param {string} faceId FaceId of the query face. User needs to call Face - + * @param {uuid} faceId FaceId of the query face. User needs to call Face - * Detect first to get a valid faceId. Note that this faceId is not persisted * and will expire 24 hours after the detection call * @@ -1493,7 +1451,7 @@ class Face { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error} - The error object. */ @@ -1529,7 +1487,7 @@ class Face { * * {Promise} A promise is returned * - * @resolve {GroupResponse} - The deserialized result object. + * @resolve {GroupResult} - The deserialized result object. * * @reject {Error} - The error object. * @@ -1538,7 +1496,7 @@ class Face { * {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 GroupResponse} for more information. + * See {@link GroupResult} for more information. * * {object} [request] - The HTTP Request object if an error did not occur. * @@ -1567,17 +1525,21 @@ class Face { /** * Identify unknown faces from a person group. * - * @param {string} personGroupId personGroupId of the target person group, + * @param {string} personGroupId PersonGroupId of the target person group, * created by PersonGroups.Create * - * @param {array} faceIds Array of candidate faceId created by Face - Detect. + * @param {array} faceIds Array of query faces faceIds, created by the Face - + * Detect. Each of the faces are identified independently. The valid number of + * faceIds is between [1, 10]. * * @param {object} [options] Optional Parameters. * - * @param {number} [options.maxNumOfCandidatesReturned] The number of top - * similar faces returned. + * @param {number} [options.maxNumOfCandidatesReturned] The range of + * maxNumOfCandidatesReturned is between 1 and 5 (default is 1). * - * @param {number} [options.confidenceThreshold] + * @param {number} [options.confidenceThreshold] Confidence threshold of + * identification, used to judge whether one face belong to one person. The + * range of confidenceThreshold is [0, 1] (default specified by algorithm). * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -1605,17 +1567,21 @@ class Face { /** * Identify unknown faces from a person group. * - * @param {string} personGroupId personGroupId of the target person group, + * @param {string} personGroupId PersonGroupId of the target person group, * created by PersonGroups.Create * - * @param {array} faceIds Array of candidate faceId created by Face - Detect. + * @param {array} faceIds Array of query faces faceIds, created by the Face - + * Detect. Each of the faces are identified independently. The valid number of + * faceIds is between [1, 10]. * * @param {object} [options] Optional Parameters. * - * @param {number} [options.maxNumOfCandidatesReturned] The number of top - * similar faces returned. + * @param {number} [options.maxNumOfCandidatesReturned] The range of + * maxNumOfCandidatesReturned is between 1 and 5 (default is 1). * - * @param {number} [options.confidenceThreshold] + * @param {number} [options.confidenceThreshold] Confidence threshold of + * identification, used to judge whether one face belong to one person. The + * range of confidenceThreshold is [0, 1] (default specified by algorithm). * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -1665,9 +1631,9 @@ class Face { * Verify whether two faces belong to a same person or whether one face belongs * to a person. * - * @param {string} faceId1 faceId of the first face, comes from Face - Detect + * @param {uuid} faceId1 FaceId of the first face, comes from Face - Detect * - * @param {string} faceId2 faceId of the second face, comes from Face - Detect + * @param {uuid} faceId2 FaceId of the second face, comes from Face - Detect * * @param {object} [options] Optional Parameters. * @@ -1680,11 +1646,11 @@ class Face { * * @reject {Error} - The error object. */ - verifyWithHttpOperationResponse(faceId1, faceId2, options) { + verifyFaceToFaceWithHttpOperationResponse(faceId1, faceId2, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._verify(faceId1, faceId2, options, (err, result, request, response) => { + self._verifyFaceToFace(faceId1, faceId2, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -1698,9 +1664,9 @@ class Face { * Verify whether two faces belong to a same person or whether one face belongs * to a person. * - * @param {string} faceId1 faceId of the first face, comes from Face - Detect + * @param {uuid} faceId1 FaceId of the first face, comes from Face - Detect * - * @param {string} faceId2 faceId of the second face, comes from Face - Detect + * @param {uuid} faceId2 FaceId of the second face, comes from Face - Detect * * @param {object} [options] Optional Parameters. * @@ -1729,7 +1695,7 @@ class Face { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ - verify(faceId1, faceId2, options, optionalCallback) { + verifyFaceToFace(faceId1, faceId2, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -1738,14 +1704,14 @@ class Face { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._verify(faceId1, faceId2, options, (err, result, request, response) => { + self._verifyFaceToFace(faceId1, faceId2, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._verify(faceId1, faceId2, options, optionalCallback); + return self._verifyFaceToFace(faceId1, faceId2, options, optionalCallback); } } @@ -1753,7 +1719,7 @@ class Face { * Detect human faces in an image and returns face locations, and optionally * with faceIds, landmarks, and attributes. * - * @param {string} url + * @param {string} url Publicly reachable URL of an image * * @param {object} [options] Optional Parameters. * @@ -1778,11 +1744,11 @@ class Face { * * @reject {Error} - The error object. */ - detectWithHttpOperationResponse(url, options) { + detectWithUrlWithHttpOperationResponse(url, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._detect(url, options, (err, result, request, response) => { + self._detectWithUrl(url, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -1796,7 +1762,7 @@ class Face { * Detect human faces in an image and returns face locations, and optionally * with faceIds, landmarks, and attributes. * - * @param {string} url + * @param {string} url Publicly reachable URL of an image * * @param {object} [options] Optional Parameters. * @@ -1836,7 +1802,7 @@ class Face { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ - detect(url, options, optionalCallback) { + detectWithUrl(url, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -1845,14 +1811,14 @@ class Face { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._detect(url, options, (err, result, request, response) => { + self._detectWithUrl(url, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._detect(url, options, optionalCallback); + return self._detectWithUrl(url, options, optionalCallback); } } @@ -1860,15 +1826,15 @@ class Face { * Verify whether two faces belong to a same person. Compares a face Id with a * Person Id * - * @param {string} faceId faceId the face, comes from Face - Detect - * - * @param {string} personId Specify a certain person in a person group. - * personId is created in Persons.Create. + * @param {uuid} faceId FaceId the face, comes from Face - Detect * * @param {string} personGroupId Using existing personGroupId and personId for * fast loading a specified person. personGroupId is created in Person * Groups.Create. * + * @param {uuid} personId Specify a certain person in a person group. personId + * is created in Persons.Create. + * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -1880,11 +1846,11 @@ class Face { * * @reject {Error} - The error object. */ - verifyWithPersonGroupWithHttpOperationResponse(faceId, personId, personGroupId, options) { + verifyFaceToPersonWithHttpOperationResponse(faceId, personGroupId, personId, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._verifyWithPersonGroup(faceId, personId, personGroupId, options, (err, result, request, response) => { + self._verifyFaceToPerson(faceId, personGroupId, personId, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -1898,15 +1864,15 @@ class Face { * Verify whether two faces belong to a same person. Compares a face Id with a * Person Id * - * @param {string} faceId faceId the face, comes from Face - Detect - * - * @param {string} personId Specify a certain person in a person group. - * personId is created in Persons.Create. + * @param {uuid} faceId FaceId the face, comes from Face - Detect * * @param {string} personGroupId Using existing personGroupId and personId for * fast loading a specified person. personGroupId is created in Person * Groups.Create. * + * @param {uuid} personId Specify a certain person in a person group. personId + * is created in Persons.Create. + * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -1934,7 +1900,7 @@ class Face { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ - verifyWithPersonGroup(faceId, personId, personGroupId, options, optionalCallback) { + verifyFaceToPerson(faceId, personGroupId, personId, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -1943,14 +1909,14 @@ class Face { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._verifyWithPersonGroup(faceId, personId, personGroupId, options, (err, result, request, response) => { + self._verifyFaceToPerson(faceId, personGroupId, personId, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._verifyWithPersonGroup(faceId, personId, personGroupId, options, optionalCallback); + return self._verifyFaceToPerson(faceId, personGroupId, personId, options, optionalCallback); } } @@ -1983,11 +1949,11 @@ class Face { * * @reject {Error} - The error object. */ - detectInStreamWithHttpOperationResponse(image, options) { + detectWithStreamWithHttpOperationResponse(image, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._detectInStream(image, options, (err, result, request, response) => { + self._detectWithStream(image, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -2041,7 +2007,7 @@ class Face { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ - detectInStream(image, options, optionalCallback) { + detectWithStream(image, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -2050,14 +2016,14 @@ class Face { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._detectInStream(image, options, (err, result, request, response) => { + self._detectWithStream(image, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._detectInStream(image, options, optionalCallback); + return self._detectWithStream(image, options, optionalCallback); } } diff --git a/lib/services/face/lib/operations/faceListOperations.js b/lib/services/face/lib/operations/faceListOperations.js new file mode 100644 index 0000000000..e7a71f8a6a --- /dev/null +++ b/lib/services/face/lib/operations/faceListOperations.js @@ -0,0 +1,1974 @@ +/* + * 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; + +/** + * Create an empty face list. Up to 64 face lists are allowed to exist in one + * subscription. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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 _create(faceListId, 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.'); + } + let name = (options && options.name !== undefined) ? options.name : undefined; + let userData = (options && options.userData !== undefined) ? options.userData : undefined; + // 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 (faceListId === null || faceListId === undefined || typeof faceListId.valueOf() !== 'string') { + throw new Error('faceListId cannot be null or undefined and it must be of type string.'); + } + if (faceListId !== null && faceListId !== undefined) { + if (faceListId.length > 64) + { + throw new Error('"faceListId" should satisfy the constraint - "MaxLength": 64'); + } + if (faceListId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"faceListId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (name !== null && name !== undefined && typeof name.valueOf() !== 'string') { + throw new Error('name must be of type string.'); + } + if (name !== null && name !== undefined) { + if (name.length > 128) + { + throw new Error('"name" should satisfy the constraint - "MaxLength": 128'); + } + } + if (userData !== null && userData !== undefined && typeof userData.valueOf() !== 'string') { + throw new Error('userData must be of type string.'); + } + if (userData !== null && userData !== undefined) { + if (userData.length > 16384) + { + throw new Error('"userData" should satisfy the constraint - "MaxLength": 16384'); + } + } + } catch (error) { + return callback(error); + } + let body; + if ((name !== null && name !== undefined) || (userData !== null && userData !== undefined)) { + body = new client.models['NameAndUserDataContract'](); + body.name = name; + body.userData = userData; + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'facelists/{faceListId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{faceListId}', encodeURIComponent(faceListId)); + + // 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 (body !== null && body !== undefined) { + let requestModelMapper = new client.models['NameAndUserDataContract']().mapper(); + requestModel = client.serialize(requestModelMapper, body, 'body'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(body, 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 !== 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['APIError']().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); + }); +} + +/** + * Retrieve a face list's information. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @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 FaceList} 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(faceListId, 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 (faceListId === null || faceListId === undefined || typeof faceListId.valueOf() !== 'string') { + throw new Error('faceListId cannot be null or undefined and it must be of type string.'); + } + if (faceListId !== null && faceListId !== undefined) { + if (faceListId.length > 64) + { + throw new Error('"faceListId" should satisfy the constraint - "MaxLength": 64'); + } + if (faceListId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"faceListId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'facelists/{faceListId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{faceListId}', encodeURIComponent(faceListId)); + + // 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['APIError']().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['FaceList']().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); + }); +} + +/** + * Update information of a face list. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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 _update(faceListId, 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.'); + } + let name = (options && options.name !== undefined) ? options.name : undefined; + let userData = (options && options.userData !== undefined) ? options.userData : undefined; + // 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 (faceListId === null || faceListId === undefined || typeof faceListId.valueOf() !== 'string') { + throw new Error('faceListId cannot be null or undefined and it must be of type string.'); + } + if (faceListId !== null && faceListId !== undefined) { + if (faceListId.length > 64) + { + throw new Error('"faceListId" should satisfy the constraint - "MaxLength": 64'); + } + if (faceListId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"faceListId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (name !== null && name !== undefined && typeof name.valueOf() !== 'string') { + throw new Error('name must be of type string.'); + } + if (name !== null && name !== undefined) { + if (name.length > 128) + { + throw new Error('"name" should satisfy the constraint - "MaxLength": 128'); + } + } + if (userData !== null && userData !== undefined && typeof userData.valueOf() !== 'string') { + throw new Error('userData must be of type string.'); + } + if (userData !== null && userData !== undefined) { + if (userData.length > 16384) + { + throw new Error('"userData" should satisfy the constraint - "MaxLength": 16384'); + } + } + } catch (error) { + return callback(error); + } + let body; + if ((name !== null && name !== undefined) || (userData !== null && userData !== undefined)) { + body = new client.models['NameAndUserDataContract'](); + body.name = name; + body.userData = userData; + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'facelists/{faceListId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{faceListId}', encodeURIComponent(faceListId)); + + // 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 (body !== null && body !== undefined) { + let requestModelMapper = new client.models['NameAndUserDataContract']().mapper(); + requestModel = client.serialize(requestModelMapper, body, 'body'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(body, 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 !== 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['APIError']().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); + }); +} + +/** + * Delete an existing face list according to faceListId. Persisted face images + * in the face list will also be deleted. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @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(faceListId, 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 (faceListId === null || faceListId === undefined || typeof faceListId.valueOf() !== 'string') { + throw new Error('faceListId cannot be null or undefined and it must be of type string.'); + } + if (faceListId !== null && faceListId !== undefined) { + if (faceListId.length > 64) + { + throw new Error('"faceListId" should satisfy the constraint - "MaxLength": 64'); + } + if (faceListId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"faceListId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'facelists/{faceListId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{faceListId}', encodeURIComponent(faceListId)); + + // 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 !== 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['APIError']().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); + }); +} + +/** + * Retrieve information about all existing face lists. Only faceListId, name + * and userData will be returned. + * + * @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. + * + * {array} [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 _list(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('/') ? '' : '/') + 'facelists'; + 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['APIError']().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 = { + required: false, + serializedName: 'parsedResponse', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'FaceListElementType', + type: { + name: 'Composite', + className: 'FaceList' + } + } + } + }; + 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); + }); +} + +/** + * Delete an existing face from a face list (given by a persisitedFaceId and a + * faceListId). Persisted image related to the face will also be deleted. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. + * + * @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 _deleteFace(faceListId, persistedFaceId, 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 (faceListId === null || faceListId === undefined || typeof faceListId.valueOf() !== 'string') { + throw new Error('faceListId cannot be null or undefined and it must be of type string.'); + } + if (faceListId !== null && faceListId !== undefined) { + if (faceListId.length > 64) + { + throw new Error('"faceListId" should satisfy the constraint - "MaxLength": 64'); + } + if (faceListId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"faceListId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (persistedFaceId === null || persistedFaceId === undefined || typeof persistedFaceId.valueOf() !== 'string' || !msRest.isValidUuid(persistedFaceId)) { + throw new Error('persistedFaceId cannot be null or undefined and it must be of type string and must be a valid uuid.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'facelists/{faceListId}/persistedFaces/{persistedFaceId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{faceListId}', encodeURIComponent(faceListId)); + requestUrl = requestUrl.replace('{persistedFaceId}', encodeURIComponent(persistedFaceId.toString())); + + // 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 !== 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['APIError']().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); + }); +} + +/** + * Add a face to a face list. The input face is specified as an image with a + * targetFace rectangle. It returns a persistedFaceId representing the added + * face, and persistedFaceId will not expire. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {string} url Publicly reachable URL of an image + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. + * + * @param {array} [options.targetFace] A face rectangle to specify the target + * face to be added to a person in the format of + * "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If + * there is more than one face in the image, targetFace is required to specify + * which face to add. No targetFace means there is only one face detected in + * the entire image. + * + * @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 PersistedFace} 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 _addFaceFromUrl(faceListId, url, 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.'); + } + let userData = (options && options.userData !== undefined) ? options.userData : undefined; + let targetFace = (options && options.targetFace !== undefined) ? options.targetFace : undefined; + // 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 (faceListId === null || faceListId === undefined || typeof faceListId.valueOf() !== 'string') { + throw new Error('faceListId cannot be null or undefined and it must be of type string.'); + } + if (faceListId !== null && faceListId !== undefined) { + if (faceListId.length > 64) + { + throw new Error('"faceListId" should satisfy the constraint - "MaxLength": 64'); + } + if (faceListId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"faceListId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (userData !== null && userData !== undefined && typeof userData.valueOf() !== 'string') { + throw new Error('userData must be of type string.'); + } + if (userData !== null && userData !== undefined) { + if (userData.length > 1024) + { + throw new Error('"userData" should satisfy the constraint - "MaxLength": 1024'); + } + } + if (Array.isArray(targetFace)) { + for (let i = 0; i < targetFace.length; i++) { + if (targetFace[i] !== null && targetFace[i] !== undefined && typeof targetFace[i] !== 'number') { + throw new Error('targetFace[i] must be of type number.'); + } + } + } + if (url === null || url === undefined || typeof url.valueOf() !== 'string') { + throw new Error('url cannot be null or undefined and it must be of type string.'); + } + } catch (error) { + return callback(error); + } + let imageUrl; + if (url !== null && url !== undefined) { + imageUrl = new client.models['ImageUrl'](); + imageUrl.url = url; + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'facelists/{faceListId}/persistedFaces'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{faceListId}', encodeURIComponent(faceListId)); + let queryParameters = []; + if (userData !== null && userData !== undefined) { + queryParameters.push('userData=' + encodeURIComponent(userData)); + } + if (targetFace !== null && targetFace !== undefined) { + queryParameters.push('targetFace=' + encodeURIComponent(targetFace.join(','))); + } + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // 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 (imageUrl !== null && imageUrl !== undefined) { + let requestModelMapper = new client.models['ImageUrl']().mapper(); + requestModel = client.serialize(requestModelMapper, imageUrl, 'imageUrl'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(imageUrl, 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 !== 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['APIError']().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['PersistedFace']().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); + }); +} + +/** + * Add a face to a face list. The input face is specified as an image with a + * targetFace rectangle. It returns a persistedFaceId representing the added + * face, and persistedFaceId will not expire. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {object} image An image stream. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. + * + * @param {array} [options.targetFace] A face rectangle to specify the target + * face to be added to a person in the format of + * "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If + * there is more than one face in the image, targetFace is required to specify + * which face to add. No targetFace means there is only one face detected in + * the entire image. + * + * @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 PersistedFace} 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 _addFaceFromStream(faceListId, image, 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.'); + } + let userData = (options && options.userData !== undefined) ? options.userData : undefined; + let targetFace = (options && options.targetFace !== undefined) ? options.targetFace : undefined; + // 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 (faceListId === null || faceListId === undefined || typeof faceListId.valueOf() !== 'string') { + throw new Error('faceListId cannot be null or undefined and it must be of type string.'); + } + if (faceListId !== null && faceListId !== undefined) { + if (faceListId.length > 64) + { + throw new Error('"faceListId" should satisfy the constraint - "MaxLength": 64'); + } + if (faceListId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"faceListId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (userData !== null && userData !== undefined && typeof userData.valueOf() !== 'string') { + throw new Error('userData must be of type string.'); + } + if (userData !== null && userData !== undefined) { + if (userData.length > 1024) + { + throw new Error('"userData" should satisfy the constraint - "MaxLength": 1024'); + } + } + if (Array.isArray(targetFace)) { + for (let i = 0; i < targetFace.length; i++) { + if (targetFace[i] !== null && targetFace[i] !== undefined && typeof targetFace[i] !== 'number') { + throw new Error('targetFace[i] must be of type number.'); + } + } + } + if (image === null || image === undefined) { + throw new Error('image cannot be null or undefined and it must be of type object.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'facelists/{faceListId}/persistedFaces'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{faceListId}', encodeURIComponent(faceListId)); + let queryParameters = []; + if (userData !== null && userData !== undefined) { + queryParameters.push('userData=' + encodeURIComponent(userData)); + } + if (targetFace !== null && targetFace !== undefined) { + queryParameters.push('targetFace=' + encodeURIComponent(targetFace.join(','))); + } + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'POST'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/octet-stream'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + // Serialize Request + let requestContent = image; + httpRequest.body = requestContent; + // 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['APIError']().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['PersistedFace']().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 FaceListOperations. */ +class FaceListOperations { + /** + * Create a FaceListOperations. + * @param {FaceClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._create = _create; + this._get = _get; + this._update = _update; + this._deleteMethod = _deleteMethod; + this._list = _list; + this._deleteFace = _deleteFace; + this._addFaceFromUrl = _addFaceFromUrl; + this._addFaceFromStream = _addFaceFromStream; + } + + /** + * Create an empty face list. Up to 64 face lists are allowed to exist in one + * subscription. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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(faceListId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._create(faceListId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Create an empty face list. Up to 64 face lists are allowed to exist in one + * subscription. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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. + */ + create(faceListId, 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(faceListId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._create(faceListId, options, optionalCallback); + } + } + + /** + * Retrieve a face list's information. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @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(faceListId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._get(faceListId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Retrieve a face list's information. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @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 {FaceList} - 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 FaceList} 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(faceListId, 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(faceListId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._get(faceListId, options, optionalCallback); + } + } + + /** + * Update information of a face list. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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(faceListId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._update(faceListId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Update information of a face list. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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. + */ + update(faceListId, 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(faceListId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._update(faceListId, options, optionalCallback); + } + } + + /** + * Delete an existing face list according to faceListId. Persisted face images + * in the face list will also be deleted. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @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(faceListId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._deleteMethod(faceListId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Delete an existing face list according to faceListId. Persisted face images + * in the face list will also be deleted. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @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(faceListId, 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(faceListId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._deleteMethod(faceListId, options, optionalCallback); + } + } + + /** + * Retrieve information about all existing face lists. Only faceListId, name + * and userData will be returned. + * + * @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. + */ + listWithHttpOperationResponse(options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._list(options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Retrieve information about all existing face lists. Only faceListId, name + * and userData will be returned. + * + * @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 {Array} - 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. + * + * {array} [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. + */ + list(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._list(options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._list(options, optionalCallback); + } + } + + /** + * Delete an existing face from a face list (given by a persisitedFaceId and a + * faceListId). Persisted image related to the face will also be deleted. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. + * + * @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. + */ + deleteFaceWithHttpOperationResponse(faceListId, persistedFaceId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._deleteFace(faceListId, persistedFaceId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Delete an existing face from a face list (given by a persisitedFaceId and a + * faceListId). Persisted image related to the face will also be deleted. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. + * + * @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. + */ + deleteFace(faceListId, persistedFaceId, 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._deleteFace(faceListId, persistedFaceId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._deleteFace(faceListId, persistedFaceId, options, optionalCallback); + } + } + + /** + * Add a face to a face list. The input face is specified as an image with a + * targetFace rectangle. It returns a persistedFaceId representing the added + * face, and persistedFaceId will not expire. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {string} url Publicly reachable URL of an image + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. + * + * @param {array} [options.targetFace] A face rectangle to specify the target + * face to be added to a person in the format of + * "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If + * there is more than one face in the image, targetFace is required to specify + * which face to add. No targetFace means there is only one face detected in + * the entire image. + * + * @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. + */ + addFaceFromUrlWithHttpOperationResponse(faceListId, url, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._addFaceFromUrl(faceListId, url, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Add a face to a face list. The input face is specified as an image with a + * targetFace rectangle. It returns a persistedFaceId representing the added + * face, and persistedFaceId will not expire. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {string} url Publicly reachable URL of an image + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. + * + * @param {array} [options.targetFace] A face rectangle to specify the target + * face to be added to a person in the format of + * "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If + * there is more than one face in the image, targetFace is required to specify + * which face to add. No targetFace means there is only one face detected in + * the entire image. + * + * @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 {PersistedFace} - 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 PersistedFace} 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. + */ + addFaceFromUrl(faceListId, url, 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._addFaceFromUrl(faceListId, url, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._addFaceFromUrl(faceListId, url, options, optionalCallback); + } + } + + /** + * Add a face to a face list. The input face is specified as an image with a + * targetFace rectangle. It returns a persistedFaceId representing the added + * face, and persistedFaceId will not expire. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {object} image An image stream. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. + * + * @param {array} [options.targetFace] A face rectangle to specify the target + * face to be added to a person in the format of + * "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If + * there is more than one face in the image, targetFace is required to specify + * which face to add. No targetFace means there is only one face detected in + * the entire image. + * + * @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. + */ + addFaceFromStreamWithHttpOperationResponse(faceListId, image, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._addFaceFromStream(faceListId, image, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Add a face to a face list. The input face is specified as an image with a + * targetFace rectangle. It returns a persistedFaceId representing the added + * face, and persistedFaceId will not expire. + * + * @param {string} faceListId Id referencing a particular face list. + * + * @param {object} image An image stream. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. + * + * @param {array} [options.targetFace] A face rectangle to specify the target + * face to be added to a person in the format of + * "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If + * there is more than one face in the image, targetFace is required to specify + * which face to add. No targetFace means there is only one face detected in + * the entire image. + * + * @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 {PersistedFace} - 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 PersistedFace} 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. + */ + addFaceFromStream(faceListId, image, 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._addFaceFromStream(faceListId, image, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._addFaceFromStream(faceListId, image, options, optionalCallback); + } + } + +} + +module.exports = FaceListOperations; diff --git a/lib/services/face/lib/operations/index.d.ts b/lib/services/face/lib/operations/index.d.ts index 92e478dde9..ff57e7336e 100644 --- a/lib/services/face/lib/operations/index.d.ts +++ b/lib/services/face/lib/operations/index.d.ts @@ -17,7 +17,7 @@ import * as models from '../models'; * @class * Face * __NOTE__: An instance of this class is automatically created for an - * instance of the FaceAPIClient. + * instance of the FaceClient. */ export interface Face { @@ -26,7 +26,7 @@ export interface Face { * Given query face's faceId, find the similar-looking faces from a faceId * array or a faceListId. * - * @param {string} faceId FaceId of the query face. User needs to call Face - + * @param {uuid} faceId FaceId of the query face. User needs to call Face - * Detect first to get a valid faceId. Note that this faceId is not persisted * and will expire 24 hours after the detection call * @@ -58,13 +58,13 @@ export interface Face { * * @reject {Error|ServiceError} - The error object. */ - findSimilarWithHttpOperationResponse(faceId: string, options?: { faceListId? : string, faceIds? : string[], maxNumOfCandidatesReturned? : number, mode? : string, customHeaders? : { [headerName: string]: string; } }): Promise>; + findSimilarWithHttpOperationResponse(faceId: string, options?: { faceListId? : string, faceIds? : string[], maxNumOfCandidatesReturned? : number, mode? : string, customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Given query face's faceId, find the similar-looking faces from a faceId * array or a faceListId. * - * @param {string} faceId FaceId of the query face. User needs to call Face - + * @param {uuid} faceId FaceId of the query face. User needs to call Face - * Detect first to get a valid faceId. Note that this faceId is not persisted * and will expire 24 hours after the detection call * @@ -111,9 +111,9 @@ export interface Face { * * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. */ - findSimilar(faceId: string, options?: { faceListId? : string, faceIds? : string[], maxNumOfCandidatesReturned? : number, mode? : string, customHeaders? : { [headerName: string]: string; } }): Promise; - findSimilar(faceId: string, callback: ServiceCallback): void; - findSimilar(faceId: string, options: { faceListId? : string, faceIds? : string[], maxNumOfCandidatesReturned? : number, mode? : string, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + findSimilar(faceId: string, options?: { faceListId? : string, faceIds? : string[], maxNumOfCandidatesReturned? : number, mode? : string, customHeaders? : { [headerName: string]: string; } }): Promise; + findSimilar(faceId: string, callback: ServiceCallback): void; + findSimilar(faceId: string, options: { faceListId? : string, faceIds? : string[], maxNumOfCandidatesReturned? : number, mode? : string, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** @@ -129,11 +129,11 @@ export interface Face { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - groupWithHttpOperationResponse(faceIds: string[], options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + groupWithHttpOperationResponse(faceIds: string[], options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Divide candidate faces into groups based on face similarity. @@ -153,7 +153,7 @@ export interface Face { * * {Promise} A promise is returned. * - * @resolve {GroupResponse} - The deserialized result object. + * @resolve {GroupResult} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -161,32 +161,36 @@ export interface Face { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {GroupResponse} [result] - The deserialized result object if an error did not occur. - * See {@link GroupResponse} for more information. + * {GroupResult} [result] - The deserialized result object if an error did not occur. + * See {@link GroupResult} 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. */ - group(faceIds: string[], options?: { customHeaders? : { [headerName: string]: string; } }): Promise; - group(faceIds: string[], callback: ServiceCallback): void; - group(faceIds: string[], options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + group(faceIds: string[], options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + group(faceIds: string[], callback: ServiceCallback): void; + group(faceIds: string[], options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** * Identify unknown faces from a person group. * - * @param {string} personGroupId personGroupId of the target person group, + * @param {string} personGroupId PersonGroupId of the target person group, * created by PersonGroups.Create * - * @param {array} faceIds Array of candidate faceId created by Face - Detect. + * @param {array} faceIds Array of query faces faceIds, created by the Face - + * Detect. Each of the faces are identified independently. The valid number of + * faceIds is between [1, 10]. * * @param {object} [options] Optional Parameters. * - * @param {number} [options.maxNumOfCandidatesReturned] The number of top - * similar faces returned. + * @param {number} [options.maxNumOfCandidatesReturned] The range of + * maxNumOfCandidatesReturned is between 1 and 5 (default is 1). * - * @param {number} [options.confidenceThreshold] + * @param {number} [options.confidenceThreshold] Confidence threshold of + * identification, used to judge whether one face belong to one person. The + * range of confidenceThreshold is [0, 1] (default specified by algorithm). * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -197,22 +201,26 @@ export interface Face { * * @reject {Error|ServiceError} - The error object. */ - identifyWithHttpOperationResponse(personGroupId: string, faceIds: string[], options?: { maxNumOfCandidatesReturned? : number, confidenceThreshold? : number, customHeaders? : { [headerName: string]: string; } }): Promise>; + identifyWithHttpOperationResponse(personGroupId: string, faceIds: string[], options?: { maxNumOfCandidatesReturned? : number, confidenceThreshold? : number, customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Identify unknown faces from a person group. * - * @param {string} personGroupId personGroupId of the target person group, + * @param {string} personGroupId PersonGroupId of the target person group, * created by PersonGroups.Create * - * @param {array} faceIds Array of candidate faceId created by Face - Detect. + * @param {array} faceIds Array of query faces faceIds, created by the Face - + * Detect. Each of the faces are identified independently. The valid number of + * faceIds is between [1, 10]. * * @param {object} [options] Optional Parameters. * - * @param {number} [options.maxNumOfCandidatesReturned] The number of top - * similar faces returned. + * @param {number} [options.maxNumOfCandidatesReturned] The range of + * maxNumOfCandidatesReturned is between 1 and 5 (default is 1). * - * @param {number} [options.confidenceThreshold] + * @param {number} [options.confidenceThreshold] Confidence threshold of + * identification, used to judge whether one face belong to one person. The + * range of confidenceThreshold is [0, 1] (default specified by algorithm). * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -238,18 +246,18 @@ export interface Face { * * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. */ - identify(personGroupId: string, faceIds: string[], options?: { maxNumOfCandidatesReturned? : number, confidenceThreshold? : number, customHeaders? : { [headerName: string]: string; } }): Promise; - identify(personGroupId: string, faceIds: string[], callback: ServiceCallback): void; - identify(personGroupId: string, faceIds: string[], options: { maxNumOfCandidatesReturned? : number, confidenceThreshold? : number, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + identify(personGroupId: string, faceIds: string[], options?: { maxNumOfCandidatesReturned? : number, confidenceThreshold? : number, customHeaders? : { [headerName: string]: string; } }): Promise; + identify(personGroupId: string, faceIds: string[], callback: ServiceCallback): void; + identify(personGroupId: string, faceIds: string[], options: { maxNumOfCandidatesReturned? : number, confidenceThreshold? : number, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** * Verify whether two faces belong to a same person or whether one face belongs * to a person. * - * @param {string} faceId1 faceId of the first face, comes from Face - Detect + * @param {uuid} faceId1 FaceId of the first face, comes from Face - Detect * - * @param {string} faceId2 faceId of the second face, comes from Face - Detect + * @param {uuid} faceId2 FaceId of the second face, comes from Face - Detect * * @param {object} [options] Optional Parameters. * @@ -262,15 +270,15 @@ export interface Face { * * @reject {Error|ServiceError} - The error object. */ - verifyWithHttpOperationResponse(faceId1: string, faceId2: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + verifyFaceToFaceWithHttpOperationResponse(faceId1: string, faceId2: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Verify whether two faces belong to a same person or whether one face belongs * to a person. * - * @param {string} faceId1 faceId of the first face, comes from Face - Detect + * @param {uuid} faceId1 FaceId of the first face, comes from Face - Detect * - * @param {string} faceId2 faceId of the second face, comes from Face - Detect + * @param {uuid} faceId2 FaceId of the second face, comes from Face - Detect * * @param {object} [options] Optional Parameters. * @@ -299,16 +307,16 @@ export interface Face { * * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. */ - verify(faceId1: string, faceId2: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; - verify(faceId1: string, faceId2: string, callback: ServiceCallback): void; - verify(faceId1: string, faceId2: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + verifyFaceToFace(faceId1: string, faceId2: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + verifyFaceToFace(faceId1: string, faceId2: string, callback: ServiceCallback): void; + verifyFaceToFace(faceId1: string, faceId2: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** * Detect human faces in an image and returns face locations, and optionally * with faceIds, landmarks, and attributes. * - * @param {string} url + * @param {string} url Publicly reachable URL of an image * * @param {object} [options] Optional Parameters. * @@ -333,13 +341,13 @@ export interface Face { * * @reject {Error|ServiceError} - The error object. */ - detectWithHttpOperationResponse(url: string, options?: { returnFaceId? : boolean, returnFaceLandmarks? : boolean, returnFaceAttributes? : string[], customHeaders? : { [headerName: string]: string; } }): Promise>; + detectWithUrlWithHttpOperationResponse(url: string, options?: { returnFaceId? : boolean, returnFaceLandmarks? : boolean, returnFaceAttributes? : string[], customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Detect human faces in an image and returns face locations, and optionally * with faceIds, landmarks, and attributes. * - * @param {string} url + * @param {string} url Publicly reachable URL of an image * * @param {object} [options] Optional Parameters. * @@ -379,24 +387,24 @@ export interface Face { * * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. */ - detect(url: string, options?: { returnFaceId? : boolean, returnFaceLandmarks? : boolean, returnFaceAttributes? : string[], customHeaders? : { [headerName: string]: string; } }): Promise; - detect(url: string, callback: ServiceCallback): void; - detect(url: string, options: { returnFaceId? : boolean, returnFaceLandmarks? : boolean, returnFaceAttributes? : string[], customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + detectWithUrl(url: string, options?: { returnFaceId? : boolean, returnFaceLandmarks? : boolean, returnFaceAttributes? : string[], customHeaders? : { [headerName: string]: string; } }): Promise; + detectWithUrl(url: string, callback: ServiceCallback): void; + detectWithUrl(url: string, options: { returnFaceId? : boolean, returnFaceLandmarks? : boolean, returnFaceAttributes? : string[], customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** * Verify whether two faces belong to a same person. Compares a face Id with a * Person Id * - * @param {string} faceId faceId the face, comes from Face - Detect - * - * @param {string} personId Specify a certain person in a person group. - * personId is created in Persons.Create. + * @param {uuid} faceId FaceId the face, comes from Face - Detect * * @param {string} personGroupId Using existing personGroupId and personId for * fast loading a specified person. personGroupId is created in Person * Groups.Create. * + * @param {uuid} personId Specify a certain person in a person group. personId + * is created in Persons.Create. + * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -408,21 +416,21 @@ export interface Face { * * @reject {Error|ServiceError} - The error object. */ - verifyWithPersonGroupWithHttpOperationResponse(faceId: string, personId: string, personGroupId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + verifyFaceToPersonWithHttpOperationResponse(faceId: string, personGroupId: string, personId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Verify whether two faces belong to a same person. Compares a face Id with a * Person Id * - * @param {string} faceId faceId the face, comes from Face - Detect - * - * @param {string} personId Specify a certain person in a person group. - * personId is created in Persons.Create. + * @param {uuid} faceId FaceId the face, comes from Face - Detect * * @param {string} personGroupId Using existing personGroupId and personId for * fast loading a specified person. personGroupId is created in Person * Groups.Create. * + * @param {uuid} personId Specify a certain person in a person group. personId + * is created in Persons.Create. + * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -450,9 +458,9 @@ export interface Face { * * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. */ - verifyWithPersonGroup(faceId: string, personId: string, personGroupId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; - verifyWithPersonGroup(faceId: string, personId: string, personGroupId: string, callback: ServiceCallback): void; - verifyWithPersonGroup(faceId: string, personId: string, personGroupId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + verifyFaceToPerson(faceId: string, personGroupId: string, personId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + verifyFaceToPerson(faceId: string, personGroupId: string, personId: string, callback: ServiceCallback): void; + verifyFaceToPerson(faceId: string, personGroupId: string, personId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** @@ -484,7 +492,7 @@ export interface Face { * * @reject {Error|ServiceError} - The error object. */ - detectInStreamWithHttpOperationResponse(image: stream.Readable, options?: { returnFaceId? : boolean, returnFaceLandmarks? : boolean, returnFaceAttributes? : string[], customHeaders? : { [headerName: string]: string; } }): Promise>; + detectWithStreamWithHttpOperationResponse(image: stream.Readable, options?: { returnFaceId? : boolean, returnFaceLandmarks? : boolean, returnFaceAttributes? : string[], customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Detect human faces in an image and returns face locations, and optionally @@ -530,58 +538,54 @@ export interface Face { * * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. */ - detectInStream(image: stream.Readable, options?: { returnFaceId? : boolean, returnFaceLandmarks? : boolean, returnFaceAttributes? : string[], customHeaders? : { [headerName: string]: string; } }): Promise; - detectInStream(image: stream.Readable, callback: ServiceCallback): void; - detectInStream(image: stream.Readable, options: { returnFaceId? : boolean, returnFaceLandmarks? : boolean, returnFaceAttributes? : string[], customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + detectWithStream(image: stream.Readable, options?: { returnFaceId? : boolean, returnFaceLandmarks? : boolean, returnFaceAttributes? : string[], customHeaders? : { [headerName: string]: string; } }): Promise; + detectWithStream(image: stream.Readable, callback: ServiceCallback): void; + detectWithStream(image: stream.Readable, options: { returnFaceId? : boolean, returnFaceLandmarks? : boolean, returnFaceAttributes? : string[], customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } /** * @class - * Person + * PersonGroupPerson * __NOTE__: An instance of this class is automatically created for an - * instance of the FaceAPIClient. + * instance of the FaceClient. */ -export interface Person { +export interface PersonGroupPerson { /** * Create a new person in a specified person group. * - * @param {string} personGroupId Specifying the target person group to create - * the person. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * - * @param {string} [options.name] Display name of the target person. The - * maximum length is 128. + * @param {string} [options.name] User defined name, maximum length is 128. * - * @param {string} [options.userData] Optional fields for user-provided data - * attached to a person. Size limit is 16KB. + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. * * @param {object} [options.customHeaders] Headers that will be added to the * request * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - createWithHttpOperationResponse(personGroupId: string, options?: { name? : string, userData? : string, customHeaders? : { [headerName: string]: string; } }): Promise>; + createWithHttpOperationResponse(personGroupId: string, options?: { name? : string, userData? : string, customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Create a new person in a specified person group. * - * @param {string} personGroupId Specifying the target person group to create - * the person. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * - * @param {string} [options.name] Display name of the target person. The - * maximum length is 128. + * @param {string} [options.name] User defined name, maximum length is 128. * - * @param {string} [options.userData] Optional fields for user-provided data - * attached to a person. Size limit is 16KB. + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -593,7 +597,7 @@ export interface Person { * * {Promise} A promise is returned. * - * @resolve {CreatePersonResult} - The deserialized result object. + * @resolve {Person} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -601,16 +605,16 @@ export interface Person { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {CreatePersonResult} [result] - The deserialized result object if an error did not occur. - * See {@link CreatePersonResult} for more information. + * {Person} [result] - The deserialized result object if an error did not occur. + * See {@link Person} 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(personGroupId: string, options?: { name? : string, userData? : string, customHeaders? : { [headerName: string]: string; } }): Promise; - create(personGroupId: string, callback: ServiceCallback): void; - create(personGroupId: string, options: { name? : string, userData? : string, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + create(personGroupId: string, options?: { name? : string, userData? : string, customHeaders? : { [headerName: string]: string; } }): Promise; + create(personGroupId: string, callback: ServiceCallback): void; + create(personGroupId: string, options: { name? : string, userData? : string, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** @@ -618,7 +622,7 @@ export interface Person { * (including personId, name, userData and persistedFaceIds of registered faces * of the person). * - * @param {string} personGroupId personGroupId of the target person group. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * @@ -637,14 +641,14 @@ export interface Person { * * @reject {Error|ServiceError} - The error object. */ - listWithHttpOperationResponse(personGroupId: string, options?: { start? : string, top? : number, customHeaders? : { [headerName: string]: string; } }): Promise>; + listWithHttpOperationResponse(personGroupId: string, options?: { start? : string, top? : number, customHeaders? : { [headerName: string]: string; } }): Promise>; /** * List all persons in a person group, and retrieve person information * (including personId, name, userData and persistedFaceIds of registered faces * of the person). * - * @param {string} personGroupId personGroupId of the target person group. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * @@ -678,19 +682,18 @@ export interface Person { * * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. */ - list(personGroupId: string, options?: { start? : string, top? : number, customHeaders? : { [headerName: string]: string; } }): Promise; - list(personGroupId: string, callback: ServiceCallback): void; - list(personGroupId: string, options: { start? : string, top? : number, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + list(personGroupId: string, options?: { start? : string, top? : number, customHeaders? : { [headerName: string]: string; } }): Promise; + list(personGroupId: string, callback: ServiceCallback): void; + list(personGroupId: string, options: { start? : string, top? : number, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** * Delete an existing person from a person group. Persisted face images of the * person will also be deleted. * - * @param {string} personGroupId Specifying the person group containing the - * person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId The target personId to delete. + * @param {uuid} personId Id referencing a particular person. * * @param {object} [options] Optional Parameters. * @@ -709,10 +712,9 @@ export interface Person { * Delete an existing person from a person group. Persisted face images of the * person will also be deleted. * - * @param {string} personGroupId Specifying the person group containing the - * person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId The target personId to delete. + * @param {uuid} personId Id referencing a particular person. * * @param {object} [options] Optional Parameters. * @@ -749,10 +751,9 @@ export interface Person { * Retrieve a person's information, including registered persisted faces, name * and userData. * - * @param {string} personGroupId Specifying the person group containing the - * target person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId Specifying the target person. + * @param {uuid} personId Id referencing a particular person. * * @param {object} [options] Optional Parameters. * @@ -761,20 +762,19 @@ export interface Person { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - getWithHttpOperationResponse(personGroupId: string, personId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + getWithHttpOperationResponse(personGroupId: string, personId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Retrieve a person's information, including registered persisted faces, name * and userData. * - * @param {string} personGroupId Specifying the person group containing the - * target person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId Specifying the target person. + * @param {uuid} personId Id referencing a particular person. * * @param {object} [options] Optional Parameters. * @@ -788,7 +788,7 @@ export interface Person { * * {Promise} A promise is returned. * - * @resolve {PersonResult} - The deserialized result object. + * @resolve {Person} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -796,33 +796,31 @@ export interface Person { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {PersonResult} [result] - The deserialized result object if an error did not occur. - * See {@link PersonResult} for more information. + * {Person} [result] - The deserialized result object if an error did not occur. + * See {@link Person} 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(personGroupId: string, personId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; - get(personGroupId: string, personId: string, callback: ServiceCallback): void; - get(personGroupId: string, personId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + get(personGroupId: string, personId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + get(personGroupId: string, personId: string, callback: ServiceCallback): void; + get(personGroupId: string, personId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** * Update name or userData of a person. * - * @param {string} personGroupId Specifying the person group containing the - * target person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId personId of the target person. + * @param {uuid} personId Id referencing a particular person. * * @param {object} [options] Optional Parameters. * - * @param {string} [options.name] Display name of the target person. The - * maximum length is 128. + * @param {string} [options.name] User defined name, maximum length is 128. * - * @param {string} [options.userData] Optional fields for user-provided data - * attached to a person. Size limit is 16KB. + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -838,18 +836,16 @@ export interface Person { /** * Update name or userData of a person. * - * @param {string} personGroupId Specifying the person group containing the - * target person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId personId of the target person. + * @param {uuid} personId Id referencing a particular person. * * @param {object} [options] Optional Parameters. * - * @param {string} [options.name] Display name of the target person. The - * maximum length is 128. + * @param {string} [options.name] User defined name, maximum length is 128. * - * @param {string} [options.userData] Optional fields for user-provided data - * attached to a person. Size limit is 16KB. + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -884,13 +880,12 @@ export interface Person { * Delete a face from a person. Relative image for the persisted face will also * be deleted. * - * @param {string} personGroupId Specifying the person group containing the - * target person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId Specifying the person that the target persisted - * face belong to. + * @param {uuid} personId Id referencing a particular person. * - * @param {string} persistedFaceId The persisted face to remove. + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. * * @param {object} [options] Optional Parameters. * @@ -909,13 +904,12 @@ export interface Person { * Delete a face from a person. Relative image for the persisted face will also * be deleted. * - * @param {string} personGroupId Specifying the person group containing the - * target person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId Specifying the person that the target persisted - * face belong to. + * @param {uuid} personId Id referencing a particular person. * - * @param {string} persistedFaceId The persisted face to remove. + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. * * @param {object} [options] Optional Parameters. * @@ -952,14 +946,12 @@ export interface Person { * Retrieve information about a persisted face (specified by persistedFaceId, * personId and its belonging personGroupId). * - * @param {string} personGroupId Specifying the person group containing the - * target person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId Specifying the target person that the face belongs - * to. + * @param {uuid} personId Id referencing a particular person. * - * @param {string} persistedFaceId The persistedFaceId of the target persisted - * face of the person. + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. * * @param {object} [options] Optional Parameters. * @@ -968,24 +960,22 @@ export interface Person { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - getFaceWithHttpOperationResponse(personGroupId: string, personId: string, persistedFaceId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + getFaceWithHttpOperationResponse(personGroupId: string, personId: string, persistedFaceId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Retrieve information about a persisted face (specified by persistedFaceId, * personId and its belonging personGroupId). * - * @param {string} personGroupId Specifying the person group containing the - * target person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId Specifying the target person that the face belongs - * to. + * @param {uuid} personId Id referencing a particular person. * - * @param {string} persistedFaceId The persistedFaceId of the target persisted - * face of the person. + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. * * @param {object} [options] Optional Parameters. * @@ -999,7 +989,7 @@ export interface Person { * * {Promise} A promise is returned. * - * @resolve {PersonFaceResult} - The deserialized result object. + * @resolve {PersistedFace} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -1007,33 +997,32 @@ export interface Person { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {PersonFaceResult} [result] - The deserialized result object if an error did not occur. - * See {@link PersonFaceResult} for more information. + * {PersistedFace} [result] - The deserialized result object if an error did not occur. + * See {@link PersistedFace} 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. */ - getFace(personGroupId: string, personId: string, persistedFaceId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; - getFace(personGroupId: string, personId: string, persistedFaceId: string, callback: ServiceCallback): void; - getFace(personGroupId: string, personId: string, persistedFaceId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + getFace(personGroupId: string, personId: string, persistedFaceId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + getFace(personGroupId: string, personId: string, persistedFaceId: string, callback: ServiceCallback): void; + getFace(personGroupId: string, personId: string, persistedFaceId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** * Update a person persisted face's userData field. * - * @param {string} personGroupId Specifying the person group containing the - * target person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId personId of the target person. + * @param {uuid} personId Id referencing a particular person. * - * @param {string} persistedFaceId persistedFaceId of target face, which is - * persisted and will not expire. + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. * * @param {object} [options] Optional Parameters. * * @param {string} [options.userData] User-provided data attached to the face. - * The size limit is 1KB + * The size limit is 1KB. * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -1049,18 +1038,17 @@ export interface Person { /** * Update a person persisted face's userData field. * - * @param {string} personGroupId Specifying the person group containing the - * target person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId personId of the target person. + * @param {uuid} personId Id referencing a particular person. * - * @param {string} persistedFaceId persistedFaceId of target face, which is - * persisted and will not expire. + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. * * @param {object} [options] Optional Parameters. * * @param {string} [options.userData] User-provided data attached to the face. - * The size limit is 1KB + * The size limit is 1KB. * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -1095,17 +1083,16 @@ export interface Person { * Add a representative face to a person for identification. The input face is * specified as an image with a targetFace rectangle. * - * @param {string} personGroupId Specifying the person group containing the - * target person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId Target person that the face is added to. + * @param {uuid} personId Id referencing a particular person. * - * @param {string} url + * @param {string} url Publicly reachable URL of an image * * @param {object} [options] Optional Parameters. * - * @param {string} [options.userData] User-specified data about the target face - * to add for any purpose. The maximum length is 1KB. + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. * * @param {array} [options.targetFace] A face rectangle to specify the target * face to be added to a person in the format of @@ -1119,27 +1106,26 @@ export interface Person { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - addPersonFaceWithHttpOperationResponse(personGroupId: string, personId: string, url: string, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise>; + addPersonFaceFromUrlWithHttpOperationResponse(personGroupId: string, personId: string, url: string, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Add a representative face to a person for identification. The input face is * specified as an image with a targetFace rectangle. * - * @param {string} personGroupId Specifying the person group containing the - * target person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId Target person that the face is added to. + * @param {uuid} personId Id referencing a particular person. * - * @param {string} url + * @param {string} url Publicly reachable URL of an image * * @param {object} [options] Optional Parameters. * - * @param {string} [options.userData] User-specified data about the target face - * to add for any purpose. The maximum length is 1KB. + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. * * @param {array} [options.targetFace] A face rectangle to specify the target * face to be added to a person in the format of @@ -1158,7 +1144,7 @@ export interface Person { * * {Promise} A promise is returned. * - * @resolve {PersistedFaceResult} - The deserialized result object. + * @resolve {PersistedFace} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -1166,33 +1152,32 @@ export interface Person { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {PersistedFaceResult} [result] - The deserialized result object if an error did not occur. - * See {@link PersistedFaceResult} for more information. + * {PersistedFace} [result] - The deserialized result object if an error did not occur. + * See {@link PersistedFace} 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. */ - addPersonFace(personGroupId: string, personId: string, url: string, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise; - addPersonFace(personGroupId: string, personId: string, url: string, callback: ServiceCallback): void; - addPersonFace(personGroupId: string, personId: string, url: string, options: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + addPersonFaceFromUrl(personGroupId: string, personId: string, url: string, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise; + addPersonFaceFromUrl(personGroupId: string, personId: string, url: string, callback: ServiceCallback): void; + addPersonFaceFromUrl(personGroupId: string, personId: string, url: string, options: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** * Add a representative face to a person for identification. The input face is * specified as an image with a targetFace rectangle. * - * @param {string} personGroupId Specifying the person group containing the - * target person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId Target person that the face is added to. + * @param {uuid} personId Id referencing a particular person. * * @param {object} image An image stream. * * @param {object} [options] Optional Parameters. * - * @param {string} [options.userData] User-specified data about the target face - * to add for any purpose. The maximum length is 1KB. + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. * * @param {array} [options.targetFace] A face rectangle to specify the target * face to be added to a person in the format of @@ -1206,27 +1191,26 @@ export interface Person { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - addPersonFaceFromStreamWithHttpOperationResponse(personGroupId: string, personId: string, image: stream.Readable, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise>; + addPersonFaceFromStreamWithHttpOperationResponse(personGroupId: string, personId: string, image: stream.Readable, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Add a representative face to a person for identification. The input face is * specified as an image with a targetFace rectangle. * - * @param {string} personGroupId Specifying the person group containing the - * target person. + * @param {string} personGroupId Id referencing a particular person group. * - * @param {string} personId Target person that the face is added to. + * @param {uuid} personId Id referencing a particular person. * * @param {object} image An image stream. * * @param {object} [options] Optional Parameters. * - * @param {string} [options.userData] User-specified data about the target face - * to add for any purpose. The maximum length is 1KB. + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. * * @param {array} [options.targetFace] A face rectangle to specify the target * face to be added to a person in the format of @@ -1245,7 +1229,7 @@ export interface Person { * * {Promise} A promise is returned. * - * @resolve {PersistedFaceResult} - The deserialized result object. + * @resolve {PersistedFace} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -1253,39 +1237,39 @@ export interface Person { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {PersistedFaceResult} [result] - The deserialized result object if an error did not occur. - * See {@link PersistedFaceResult} for more information. + * {PersistedFace} [result] - The deserialized result object if an error did not occur. + * See {@link PersistedFace} 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. */ - addPersonFaceFromStream(personGroupId: string, personId: string, image: stream.Readable, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise; - addPersonFaceFromStream(personGroupId: string, personId: string, image: stream.Readable, callback: ServiceCallback): void; - addPersonFaceFromStream(personGroupId: string, personId: string, image: stream.Readable, options: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + addPersonFaceFromStream(personGroupId: string, personId: string, image: stream.Readable, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise; + addPersonFaceFromStream(personGroupId: string, personId: string, image: stream.Readable, callback: ServiceCallback): void; + addPersonFaceFromStream(personGroupId: string, personId: string, image: stream.Readable, options: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } /** * @class - * PersonGroup + * PersonGroupOperations * __NOTE__: An instance of this class is automatically created for an - * instance of the FaceAPIClient. + * instance of the FaceClient. */ -export interface PersonGroup { +export interface PersonGroupOperations { /** * Create a new person group with specified personGroupId, name and * user-provided userData. * - * @param {string} personGroupId User-provided personGroupId as a string. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * - * @param {string} [options.name] Name of the face list, maximum length is 128. + * @param {string} [options.name] User defined name, maximum length is 128. * - * @param {string} [options.userData] Optional user defined data for the face - * list. Length should not exceed 16KB. + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -1302,14 +1286,14 @@ export interface PersonGroup { * Create a new person group with specified personGroupId, name and * user-provided userData. * - * @param {string} personGroupId User-provided personGroupId as a string. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * - * @param {string} [options.name] Name of the face list, maximum length is 128. + * @param {string} [options.name] User defined name, maximum length is 128. * - * @param {string} [options.userData] Optional user defined data for the face - * list. Length should not exceed 16KB. + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -1344,8 +1328,7 @@ export interface PersonGroup { * Delete an existing person group. Persisted face images of all people in the * person group will also be deleted. * - * @param {string} personGroupId The personGroupId of the person group to be - * deleted. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * @@ -1364,8 +1347,7 @@ export interface PersonGroup { * Delete an existing person group. Persisted face images of all people in the * person group will also be deleted. * - * @param {string} personGroupId The personGroupId of the person group to be - * deleted. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * @@ -1401,7 +1383,7 @@ export interface PersonGroup { /** * Retrieve the information of a person group, including its name and userData. * - * @param {string} personGroupId personGroupId of the target person group. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * @@ -1410,16 +1392,16 @@ export interface PersonGroup { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - getWithHttpOperationResponse(personGroupId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + getWithHttpOperationResponse(personGroupId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Retrieve the information of a person group, including its name and userData. * - * @param {string} personGroupId personGroupId of the target person group. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * @@ -1433,7 +1415,7 @@ export interface PersonGroup { * * {Promise} A promise is returned. * - * @resolve {PersonGroupResult} - The deserialized result object. + * @resolve {PersonGroup} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -1441,31 +1423,30 @@ export interface PersonGroup { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {PersonGroupResult} [result] - The deserialized result object if an error did not occur. - * See {@link PersonGroupResult} for more information. + * {PersonGroup} [result] - The deserialized result object if an error did not occur. + * See {@link PersonGroup} 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(personGroupId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; - get(personGroupId: string, callback: ServiceCallback): void; - get(personGroupId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + get(personGroupId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + get(personGroupId: string, callback: ServiceCallback): void; + get(personGroupId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** * Update an existing person group's display name and userData. The properties * which does not appear in request body will not be updated. * - * @param {string} personGroupId personGroupId of the person group to be - * updated. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * - * @param {string} [options.name] Name of the face list, maximum length is 128. + * @param {string} [options.name] User defined name, maximum length is 128. * - * @param {string} [options.userData] Optional user defined data for the face - * list. Length should not exceed 16KB. + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -1482,15 +1463,14 @@ export interface PersonGroup { * Update an existing person group's display name and userData. The properties * which does not appear in request body will not be updated. * - * @param {string} personGroupId personGroupId of the person group to be - * updated. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * - * @param {string} [options.name] Name of the face list, maximum length is 128. + * @param {string} [options.name] User defined name, maximum length is 128. * - * @param {string} [options.userData] Optional user defined data for the face - * list. Length should not exceed 16KB. + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -1524,7 +1504,7 @@ export interface PersonGroup { /** * Retrieve the training status of a person group (completed or ongoing). * - * @param {string} personGroupId personGroupId of target person group. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * @@ -1533,16 +1513,16 @@ export interface PersonGroup { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - getTrainingStatusWithHttpOperationResponse(personGroupId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + getTrainingStatusWithHttpOperationResponse(personGroupId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Retrieve the training status of a person group (completed or ongoing). * - * @param {string} personGroupId personGroupId of target person group. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * @@ -1556,7 +1536,7 @@ export interface PersonGroup { * * {Promise} A promise is returned. * - * @resolve {TrainingStatus1} - The deserialized result object. + * @resolve {TrainingStatus} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -1564,16 +1544,16 @@ export interface PersonGroup { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {TrainingStatus1} [result] - The deserialized result object if an error did not occur. - * See {@link TrainingStatus1} for more information. + * {TrainingStatus} [result] - The deserialized result object if an error did not occur. + * See {@link TrainingStatus} 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. */ - getTrainingStatus(personGroupId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; - getTrainingStatus(personGroupId: string, callback: ServiceCallback): void; - getTrainingStatus(personGroupId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + getTrainingStatus(personGroupId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + getTrainingStatus(personGroupId: string, callback: ServiceCallback): void; + getTrainingStatus(personGroupId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** @@ -1595,7 +1575,7 @@ export interface PersonGroup { * * @reject {Error|ServiceError} - The error object. */ - listWithHttpOperationResponse(options?: { start? : string, top? : number, customHeaders? : { [headerName: string]: string; } }): Promise>; + listWithHttpOperationResponse(options?: { start? : string, top? : number, customHeaders? : { [headerName: string]: string; } }): Promise>; /** * List person groups and their information. @@ -1631,16 +1611,16 @@ export interface PersonGroup { * * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. */ - list(options?: { start? : string, top? : number, customHeaders? : { [headerName: string]: string; } }): Promise; - list(callback: ServiceCallback): void; - list(options: { start? : string, top? : number, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + list(options?: { start? : string, top? : number, customHeaders? : { [headerName: string]: string; } }): Promise; + list(callback: ServiceCallback): void; + list(options: { start? : string, top? : number, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** * Queue a person group training task, the training task may not be started * immediately. * - * @param {string} personGroupId Target person group to be trained. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * @@ -1659,7 +1639,7 @@ export interface PersonGroup { * Queue a person group training task, the training task may not be started * immediately. * - * @param {string} personGroupId Target person group to be trained. + * @param {string} personGroupId Id referencing a particular person group. * * @param {object} [options] Optional Parameters. * @@ -1694,11 +1674,11 @@ export interface PersonGroup { /** * @class - * FaceList + * FaceListOperations * __NOTE__: An instance of this class is automatically created for an - * instance of the FaceAPIClient. + * instance of the FaceClient. */ -export interface FaceList { +export interface FaceListOperations { /** @@ -1709,10 +1689,10 @@ export interface FaceList { * * @param {object} [options] Optional Parameters. * - * @param {string} [options.name] Name of the face list, maximum length is 128. + * @param {string} [options.name] User defined name, maximum length is 128. * - * @param {string} [options.userData] Optional user defined data for the face - * list. Length should not exceed 16KB. + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -1733,10 +1713,10 @@ export interface FaceList { * * @param {object} [options] Optional Parameters. * - * @param {string} [options.name] Name of the face list, maximum length is 128. + * @param {string} [options.name] User defined name, maximum length is 128. * - * @param {string} [options.userData] Optional user defined data for the face - * list. Length should not exceed 16KB. + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -1770,7 +1750,7 @@ export interface FaceList { /** * Retrieve a face list's information. * - * @param {string} faceListId Id referencing a Face List. + * @param {string} faceListId Id referencing a particular face list. * * @param {object} [options] Optional Parameters. * @@ -1779,16 +1759,16 @@ export interface FaceList { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - getWithHttpOperationResponse(faceListId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + getWithHttpOperationResponse(faceListId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Retrieve a face list's information. * - * @param {string} faceListId Id referencing a Face List. + * @param {string} faceListId Id referencing a particular face list. * * @param {object} [options] Optional Parameters. * @@ -1802,7 +1782,7 @@ export interface FaceList { * * {Promise} A promise is returned. * - * @resolve {GetFaceListResult} - The deserialized result object. + * @resolve {FaceList} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -1810,29 +1790,29 @@ export interface FaceList { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {GetFaceListResult} [result] - The deserialized result object if an error did not occur. - * See {@link GetFaceListResult} for more information. + * {FaceList} [result] - The deserialized result object if an error did not occur. + * See {@link FaceList} 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(faceListId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; - get(faceListId: string, callback: ServiceCallback): void; - get(faceListId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + get(faceListId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + get(faceListId: string, callback: ServiceCallback): void; + get(faceListId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** * Update information of a face list. * - * @param {string} faceListId Id referencing a Face List. + * @param {string} faceListId Id referencing a particular face list. * * @param {object} [options] Optional Parameters. * - * @param {string} [options.name] Name of the face list, maximum length is 128. + * @param {string} [options.name] User defined name, maximum length is 128. * - * @param {string} [options.userData] Optional user defined data for the face - * list. Length should not exceed 16KB. + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -1848,14 +1828,14 @@ export interface FaceList { /** * Update information of a face list. * - * @param {string} faceListId Id referencing a Face List. + * @param {string} faceListId Id referencing a particular face list. * * @param {object} [options] Optional Parameters. * - * @param {string} [options.name] Name of the face list, maximum length is 128. + * @param {string} [options.name] User defined name, maximum length is 128. * - * @param {string} [options.userData] Optional user defined data for the face - * list. Length should not exceed 16KB. + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. * * @param {object} [options.customHeaders] Headers that will be added to the * request @@ -1890,7 +1870,7 @@ export interface FaceList { * Delete an existing face list according to faceListId. Persisted face images * in the face list will also be deleted. * - * @param {string} faceListId Id referencing a Face List. + * @param {string} faceListId Id referencing a particular face list. * * @param {object} [options] Optional Parameters. * @@ -1909,7 +1889,7 @@ export interface FaceList { * Delete an existing face list according to faceListId. Persisted face images * in the face list will also be deleted. * - * @param {string} faceListId Id referencing a Face List. + * @param {string} faceListId Id referencing a particular face list. * * @param {object} [options] Optional Parameters. * @@ -1957,7 +1937,7 @@ export interface FaceList { * * @reject {Error|ServiceError} - The error object. */ - listWithHttpOperationResponse(options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + listWithHttpOperationResponse(options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Retrieve information about all existing face lists. Only faceListId, name @@ -1989,18 +1969,19 @@ export interface FaceList { * * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. */ - list(options?: { customHeaders? : { [headerName: string]: string; } }): Promise; - list(callback: ServiceCallback): void; - list(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + list(options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + list(callback: ServiceCallback): void; + list(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** * Delete an existing face from a face list (given by a persisitedFaceId and a * faceListId). Persisted image related to the face will also be deleted. * - * @param {string} faceListId faceListId of an existing face list. + * @param {string} faceListId Id referencing a particular face list. * - * @param {string} persistedFaceId persistedFaceId of an existing face. + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. * * @param {object} [options] Optional Parameters. * @@ -2019,9 +2000,10 @@ export interface FaceList { * Delete an existing face from a face list (given by a persisitedFaceId and a * faceListId). Persisted image related to the face will also be deleted. * - * @param {string} faceListId faceListId of an existing face list. + * @param {string} faceListId Id referencing a particular face list. * - * @param {string} persistedFaceId persistedFaceId of an existing face. + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. * * @param {object} [options] Optional Parameters. * @@ -2059,14 +2041,14 @@ export interface FaceList { * targetFace rectangle. It returns a persistedFaceId representing the added * face, and persistedFaceId will not expire. * - * @param {string} faceListId Id referencing a Face List. + * @param {string} faceListId Id referencing a particular face list. * - * @param {string} url + * @param {string} url Publicly reachable URL of an image * * @param {object} [options] Optional Parameters. * - * @param {string} [options.userData] User-specified data about the face list - * for any purpose. The maximum length is 1KB. + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. * * @param {array} [options.targetFace] A face rectangle to specify the target * face to be added to a person in the format of @@ -2080,25 +2062,25 @@ export interface FaceList { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - addFaceWithHttpOperationResponse(faceListId: string, url: string, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise>; + addFaceFromUrlWithHttpOperationResponse(faceListId: string, url: string, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Add a face to a face list. The input face is specified as an image with a * targetFace rectangle. It returns a persistedFaceId representing the added * face, and persistedFaceId will not expire. * - * @param {string} faceListId Id referencing a Face List. + * @param {string} faceListId Id referencing a particular face list. * - * @param {string} url + * @param {string} url Publicly reachable URL of an image * * @param {object} [options] Optional Parameters. * - * @param {string} [options.userData] User-specified data about the face list - * for any purpose. The maximum length is 1KB. + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. * * @param {array} [options.targetFace] A face rectangle to specify the target * face to be added to a person in the format of @@ -2117,7 +2099,7 @@ export interface FaceList { * * {Promise} A promise is returned. * - * @resolve {PersistedFaceResult} - The deserialized result object. + * @resolve {PersistedFace} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -2125,16 +2107,16 @@ export interface FaceList { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {PersistedFaceResult} [result] - The deserialized result object if an error did not occur. - * See {@link PersistedFaceResult} for more information. + * {PersistedFace} [result] - The deserialized result object if an error did not occur. + * See {@link PersistedFace} 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. */ - addFace(faceListId: string, url: string, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise; - addFace(faceListId: string, url: string, callback: ServiceCallback): void; - addFace(faceListId: string, url: string, options: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + addFaceFromUrl(faceListId: string, url: string, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise; + addFaceFromUrl(faceListId: string, url: string, callback: ServiceCallback): void; + addFaceFromUrl(faceListId: string, url: string, options: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** @@ -2142,12 +2124,14 @@ export interface FaceList { * targetFace rectangle. It returns a persistedFaceId representing the added * face, and persistedFaceId will not expire. * - * @param {string} faceListId Id referencing a Face List. + * @param {string} faceListId Id referencing a particular face list. + * + * @param {object} image An image stream. * * @param {object} [options] Optional Parameters. * - * @param {string} [options.userData] User-specified data about the face list - * for any purpose. The maximum length is 1KB. + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. * * @param {array} [options.targetFace] A face rectangle to specify the target * face to be added to a person in the format of @@ -2161,23 +2145,25 @@ export interface FaceList { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - addFaceFromStreamWithHttpOperationResponse(faceListId: string, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise>; + addFaceFromStreamWithHttpOperationResponse(faceListId: string, image: stream.Readable, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Add a face to a face list. The input face is specified as an image with a * targetFace rectangle. It returns a persistedFaceId representing the added * face, and persistedFaceId will not expire. * - * @param {string} faceListId Id referencing a Face List. + * @param {string} faceListId Id referencing a particular face list. + * + * @param {object} image An image stream. * * @param {object} [options] Optional Parameters. * - * @param {string} [options.userData] User-specified data about the face list - * for any purpose. The maximum length is 1KB. + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. * * @param {array} [options.targetFace] A face rectangle to specify the target * face to be added to a person in the format of @@ -2196,7 +2182,7 @@ export interface FaceList { * * {Promise} A promise is returned. * - * @resolve {PersistedFaceResult} - The deserialized result object. + * @resolve {PersistedFace} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -2204,14 +2190,14 @@ export interface FaceList { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {PersistedFaceResult} [result] - The deserialized result object if an error did not occur. - * See {@link PersistedFaceResult} for more information. + * {PersistedFace} [result] - The deserialized result object if an error did not occur. + * See {@link PersistedFace} 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. */ - addFaceFromStream(faceListId: string, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise; - addFaceFromStream(faceListId: string, callback: ServiceCallback): void; - addFaceFromStream(faceListId: string, options: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + addFaceFromStream(faceListId: string, image: stream.Readable, options?: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }): Promise; + addFaceFromStream(faceListId: string, image: stream.Readable, callback: ServiceCallback): void; + addFaceFromStream(faceListId: string, image: stream.Readable, options: { userData? : string, targetFace? : number[], customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } diff --git a/lib/services/face/lib/operations/index.js b/lib/services/face/lib/operations/index.js index f4ecf097be..d3ce008a0a 100644 --- a/lib/services/face/lib/operations/index.js +++ b/lib/services/face/lib/operations/index.js @@ -15,6 +15,6 @@ 'use strict'; exports.Face = require('./face'); -exports.Person = require('./person'); -exports.PersonGroup = require('./personGroup'); -exports.FaceList = require('./faceList'); +exports.PersonGroupPerson = require('./personGroupPerson'); +exports.PersonGroupOperations = require('./personGroupOperations'); +exports.FaceListOperations = require('./faceListOperations'); diff --git a/lib/services/face/lib/operations/personGroupOperations.js b/lib/services/face/lib/operations/personGroupOperations.js new file mode 100644 index 0000000000..32beb1cc70 --- /dev/null +++ b/lib/services/face/lib/operations/personGroupOperations.js @@ -0,0 +1,1627 @@ +/* + * 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; + +/** + * Create a new person group with specified personGroupId, name and + * user-provided userData. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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 _create(personGroupId, 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.'); + } + let name = (options && options.name !== undefined) ? options.name : undefined; + let userData = (options && options.userData !== undefined) ? options.userData : undefined; + // 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (name !== null && name !== undefined && typeof name.valueOf() !== 'string') { + throw new Error('name must be of type string.'); + } + if (name !== null && name !== undefined) { + if (name.length > 128) + { + throw new Error('"name" should satisfy the constraint - "MaxLength": 128'); + } + } + if (userData !== null && userData !== undefined && typeof userData.valueOf() !== 'string') { + throw new Error('userData must be of type string.'); + } + if (userData !== null && userData !== undefined) { + if (userData.length > 16384) + { + throw new Error('"userData" should satisfy the constraint - "MaxLength": 16384'); + } + } + } catch (error) { + return callback(error); + } + let body; + if ((name !== null && name !== undefined) || (userData !== null && userData !== undefined)) { + body = new client.models['NameAndUserDataContract'](); + body.name = name; + body.userData = userData; + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + + // 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 (body !== null && body !== undefined) { + let requestModelMapper = new client.models['NameAndUserDataContract']().mapper(); + requestModel = client.serialize(requestModelMapper, body, 'body'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(body, 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 !== 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['APIError']().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); + }); +} + +/** + * Delete an existing person group. Persisted face images of all people in the + * person group will also be deleted. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @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(personGroupId, 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + + // 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 !== 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['APIError']().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); + }); +} + +/** + * Retrieve the information of a person group, including its name and userData. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @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 PersonGroup} 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(personGroupId, 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + + // 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['APIError']().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['PersonGroup']().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); + }); +} + +/** + * Update an existing person group's display name and userData. The properties + * which does not appear in request body will not be updated. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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 _update(personGroupId, 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.'); + } + let name = (options && options.name !== undefined) ? options.name : undefined; + let userData = (options && options.userData !== undefined) ? options.userData : undefined; + // 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (name !== null && name !== undefined && typeof name.valueOf() !== 'string') { + throw new Error('name must be of type string.'); + } + if (name !== null && name !== undefined) { + if (name.length > 128) + { + throw new Error('"name" should satisfy the constraint - "MaxLength": 128'); + } + } + if (userData !== null && userData !== undefined && typeof userData.valueOf() !== 'string') { + throw new Error('userData must be of type string.'); + } + if (userData !== null && userData !== undefined) { + if (userData.length > 16384) + { + throw new Error('"userData" should satisfy the constraint - "MaxLength": 16384'); + } + } + } catch (error) { + return callback(error); + } + let body; + if ((name !== null && name !== undefined) || (userData !== null && userData !== undefined)) { + body = new client.models['NameAndUserDataContract'](); + body.name = name; + body.userData = userData; + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + + // 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 (body !== null && body !== undefined) { + let requestModelMapper = new client.models['NameAndUserDataContract']().mapper(); + requestModel = client.serialize(requestModelMapper, body, 'body'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(body, 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 !== 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['APIError']().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); + }); +} + +/** + * Retrieve the training status of a person group (completed or ongoing). + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @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 TrainingStatus} 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 _getTrainingStatus(personGroupId, 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}/training'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + + // 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['APIError']().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['TrainingStatus']().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); + }); +} + +/** + * List person groups and their information. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.start] List person groups from the least + * personGroupId greater than the "start". + * + * @param {number} [options.top] The number of person groups to list. + * + * @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. + * + * {array} [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 _list(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.'); + } + let start = (options && options.start !== undefined) ? options.start : undefined; + let top = (options && options.top !== undefined) ? options.top : 1000; + // 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 (start !== null && start !== undefined && typeof start.valueOf() !== 'string') { + throw new Error('start must be of type string.'); + } + if (start !== null && start !== undefined) { + if (start.length > 64) + { + throw new Error('"start" should satisfy the constraint - "MaxLength": 64'); + } + } + if (top !== null && top !== undefined && typeof top !== 'number') { + throw new Error('top must be of type number.'); + } + if (top !== null && top !== undefined) { + if (top > 1000) + { + throw new Error('"top" should satisfy the constraint - "InclusiveMaximum": 1000'); + } + if (top < 1) + { + throw new Error('"top" should satisfy the constraint - "InclusiveMinimum": 1'); + } + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + let queryParameters = []; + if (start !== null && start !== undefined) { + queryParameters.push('start=' + encodeURIComponent(start)); + } + if (top !== null && top !== undefined) { + queryParameters.push('top=' + encodeURIComponent(top.toString())); + } + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // 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['APIError']().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 = { + required: false, + serializedName: 'parsedResponse', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'PersonGroupElementType', + type: { + name: 'Composite', + className: 'PersonGroup' + } + } + } + }; + 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); + }); +} + +/** + * Queue a person group training task, the training task may not be started + * immediately. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @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 _train(personGroupId, 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}/train'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + + // 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 !== 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['APIError']().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 PersonGroupOperations. */ +class PersonGroupOperations { + /** + * Create a PersonGroupOperations. + * @param {FaceClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._create = _create; + this._deleteMethod = _deleteMethod; + this._get = _get; + this._update = _update; + this._getTrainingStatus = _getTrainingStatus; + this._list = _list; + this._train = _train; + } + + /** + * Create a new person group with specified personGroupId, name and + * user-provided userData. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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(personGroupId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._create(personGroupId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Create a new person group with specified personGroupId, name and + * user-provided userData. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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. + */ + create(personGroupId, 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(personGroupId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._create(personGroupId, options, optionalCallback); + } + } + + /** + * Delete an existing person group. Persisted face images of all people in the + * person group will also be deleted. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @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(personGroupId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._deleteMethod(personGroupId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Delete an existing person group. Persisted face images of all people in the + * person group will also be deleted. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @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(personGroupId, 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(personGroupId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._deleteMethod(personGroupId, options, optionalCallback); + } + } + + /** + * Retrieve the information of a person group, including its name and userData. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @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(personGroupId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._get(personGroupId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Retrieve the information of a person group, including its name and userData. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @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 {PersonGroup} - 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 PersonGroup} 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(personGroupId, 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(personGroupId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._get(personGroupId, options, optionalCallback); + } + } + + /** + * Update an existing person group's display name and userData. The properties + * which does not appear in request body will not be updated. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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(personGroupId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._update(personGroupId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Update an existing person group's display name and userData. The properties + * which does not appear in request body will not be updated. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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. + */ + update(personGroupId, 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(personGroupId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._update(personGroupId, options, optionalCallback); + } + } + + /** + * Retrieve the training status of a person group (completed or ongoing). + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @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. + */ + getTrainingStatusWithHttpOperationResponse(personGroupId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._getTrainingStatus(personGroupId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Retrieve the training status of a person group (completed or ongoing). + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @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 {TrainingStatus} - 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 TrainingStatus} 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. + */ + getTrainingStatus(personGroupId, 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._getTrainingStatus(personGroupId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._getTrainingStatus(personGroupId, options, optionalCallback); + } + } + + /** + * List person groups and their information. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.start] List person groups from the least + * personGroupId greater than the "start". + * + * @param {number} [options.top] The number of person groups to list. + * + * @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. + */ + listWithHttpOperationResponse(options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._list(options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * List person groups and their information. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.start] List person groups from the least + * personGroupId greater than the "start". + * + * @param {number} [options.top] The number of person groups to list. + * + * @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 {Array} - 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. + * + * {array} [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. + */ + list(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._list(options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._list(options, optionalCallback); + } + } + + /** + * Queue a person group training task, the training task may not be started + * immediately. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @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. + */ + trainWithHttpOperationResponse(personGroupId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._train(personGroupId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Queue a person group training task, the training task may not be started + * immediately. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @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. + */ + train(personGroupId, 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._train(personGroupId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._train(personGroupId, options, optionalCallback); + } + } + +} + +module.exports = PersonGroupOperations; diff --git a/lib/services/face/lib/operations/personGroupPerson.js b/lib/services/face/lib/operations/personGroupPerson.js new file mode 100644 index 0000000000..92f012e710 --- /dev/null +++ b/lib/services/face/lib/operations/personGroupPerson.js @@ -0,0 +1,2616 @@ +/* + * 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; + +/** + * Create a new person in a specified person group. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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 Person} 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(personGroupId, 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.'); + } + let name = (options && options.name !== undefined) ? options.name : undefined; + let userData = (options && options.userData !== undefined) ? options.userData : undefined; + // 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (name !== null && name !== undefined && typeof name.valueOf() !== 'string') { + throw new Error('name must be of type string.'); + } + if (name !== null && name !== undefined) { + if (name.length > 128) + { + throw new Error('"name" should satisfy the constraint - "MaxLength": 128'); + } + } + if (userData !== null && userData !== undefined && typeof userData.valueOf() !== 'string') { + throw new Error('userData must be of type string.'); + } + if (userData !== null && userData !== undefined) { + if (userData.length > 16384) + { + throw new Error('"userData" should satisfy the constraint - "MaxLength": 16384'); + } + } + } catch (error) { + return callback(error); + } + let body; + if ((name !== null && name !== undefined) || (userData !== null && userData !== undefined)) { + body = new client.models['NameAndUserDataContract'](); + body.name = name; + body.userData = userData; + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}/persons'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + + // 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 (body !== null && body !== undefined) { + let requestModelMapper = new client.models['NameAndUserDataContract']().mapper(); + requestModel = client.serialize(requestModelMapper, body, 'body'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(body, 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 !== 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['APIError']().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['Person']().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); + }); +} + +/** + * List all persons in a person group, and retrieve person information + * (including personId, name, userData and persistedFaceIds of registered faces + * of the person). + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.start] Starting person id to return (used to list a + * range of persons). + * + * @param {number} [options.top] Number of persons to return starting with the + * person id indicated by the 'start' parameter. + * + * @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. + * + * {array} [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 _list(personGroupId, 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.'); + } + let start = (options && options.start !== undefined) ? options.start : undefined; + let top = (options && options.top !== undefined) ? options.top : undefined; + // 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (start !== null && start !== undefined && typeof start.valueOf() !== 'string') { + throw new Error('start must be of type string.'); + } + if (top !== null && top !== undefined && typeof top !== 'number') { + throw new Error('top must be of type number.'); + } + if (top !== null && top !== undefined) { + if (top > 1000) + { + throw new Error('"top" should satisfy the constraint - "InclusiveMaximum": 1000'); + } + if (top < 1) + { + throw new Error('"top" should satisfy the constraint - "InclusiveMinimum": 1'); + } + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}/persons'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + let queryParameters = []; + if (start !== null && start !== undefined) { + queryParameters.push('start=' + encodeURIComponent(start)); + } + if (top !== null && top !== undefined) { + queryParameters.push('top=' + encodeURIComponent(top.toString())); + } + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // 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['APIError']().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 = { + required: false, + serializedName: 'parsedResponse', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'PersonElementType', + type: { + name: 'Composite', + className: 'Person' + } + } + } + }; + 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); + }); +} + +/** + * Delete an existing person from a person group. Persisted face images of the + * person will also be deleted. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @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(personGroupId, personId, 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (personId === null || personId === undefined || typeof personId.valueOf() !== 'string' || !msRest.isValidUuid(personId)) { + throw new Error('personId cannot be null or undefined and it must be of type string and must be a valid uuid.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}/persons/{personId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + requestUrl = requestUrl.replace('{personId}', encodeURIComponent(personId.toString())); + + // 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 !== 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['APIError']().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); + }); +} + +/** + * Retrieve a person's information, including registered persisted faces, name + * and userData. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @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 Person} 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(personGroupId, personId, 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (personId === null || personId === undefined || typeof personId.valueOf() !== 'string' || !msRest.isValidUuid(personId)) { + throw new Error('personId cannot be null or undefined and it must be of type string and must be a valid uuid.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}/persons/{personId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + requestUrl = requestUrl.replace('{personId}', encodeURIComponent(personId.toString())); + + // 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['APIError']().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['Person']().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); + }); +} + +/** + * Update name or userData of a person. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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 _update(personGroupId, personId, 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.'); + } + let name = (options && options.name !== undefined) ? options.name : undefined; + let userData = (options && options.userData !== undefined) ? options.userData : undefined; + // 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (personId === null || personId === undefined || typeof personId.valueOf() !== 'string' || !msRest.isValidUuid(personId)) { + throw new Error('personId cannot be null or undefined and it must be of type string and must be a valid uuid.'); + } + if (name !== null && name !== undefined && typeof name.valueOf() !== 'string') { + throw new Error('name must be of type string.'); + } + if (name !== null && name !== undefined) { + if (name.length > 128) + { + throw new Error('"name" should satisfy the constraint - "MaxLength": 128'); + } + } + if (userData !== null && userData !== undefined && typeof userData.valueOf() !== 'string') { + throw new Error('userData must be of type string.'); + } + if (userData !== null && userData !== undefined) { + if (userData.length > 16384) + { + throw new Error('"userData" should satisfy the constraint - "MaxLength": 16384'); + } + } + } catch (error) { + return callback(error); + } + let body; + if ((name !== null && name !== undefined) || (userData !== null && userData !== undefined)) { + body = new client.models['NameAndUserDataContract'](); + body.name = name; + body.userData = userData; + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}/persons/{personId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + requestUrl = requestUrl.replace('{personId}', encodeURIComponent(personId.toString())); + + // 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 (body !== null && body !== undefined) { + let requestModelMapper = new client.models['NameAndUserDataContract']().mapper(); + requestModel = client.serialize(requestModelMapper, body, 'body'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(body, 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 !== 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['APIError']().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); + }); +} + +/** + * Delete a face from a person. Relative image for the persisted face will also + * be deleted. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. + * + * @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 _deleteFace(personGroupId, personId, persistedFaceId, 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (personId === null || personId === undefined || typeof personId.valueOf() !== 'string' || !msRest.isValidUuid(personId)) { + throw new Error('personId cannot be null or undefined and it must be of type string and must be a valid uuid.'); + } + if (persistedFaceId === null || persistedFaceId === undefined || typeof persistedFaceId.valueOf() !== 'string' || !msRest.isValidUuid(persistedFaceId)) { + throw new Error('persistedFaceId cannot be null or undefined and it must be of type string and must be a valid uuid.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}/persons/{personId}/persistedFaces/{persistedFaceId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + requestUrl = requestUrl.replace('{personId}', encodeURIComponent(personId.toString())); + requestUrl = requestUrl.replace('{persistedFaceId}', encodeURIComponent(persistedFaceId.toString())); + + // 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 !== 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['APIError']().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); + }); +} + +/** + * Retrieve information about a persisted face (specified by persistedFaceId, + * personId and its belonging personGroupId). + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. + * + * @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 PersistedFace} 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 _getFace(personGroupId, personId, persistedFaceId, 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (personId === null || personId === undefined || typeof personId.valueOf() !== 'string' || !msRest.isValidUuid(personId)) { + throw new Error('personId cannot be null or undefined and it must be of type string and must be a valid uuid.'); + } + if (persistedFaceId === null || persistedFaceId === undefined || typeof persistedFaceId.valueOf() !== 'string' || !msRest.isValidUuid(persistedFaceId)) { + throw new Error('persistedFaceId cannot be null or undefined and it must be of type string and must be a valid uuid.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}/persons/{personId}/persistedFaces/{persistedFaceId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + requestUrl = requestUrl.replace('{personId}', encodeURIComponent(personId.toString())); + requestUrl = requestUrl.replace('{persistedFaceId}', encodeURIComponent(persistedFaceId.toString())); + + // 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['APIError']().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['PersistedFace']().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); + }); +} + +/** + * Update a person persisted face's userData field. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-provided data attached to the face. + * The size limit is 1KB. + * + * @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 _updateFace(personGroupId, personId, persistedFaceId, 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.'); + } + let userData = (options && options.userData !== undefined) ? options.userData : undefined; + // 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (personId === null || personId === undefined || typeof personId.valueOf() !== 'string' || !msRest.isValidUuid(personId)) { + throw new Error('personId cannot be null or undefined and it must be of type string and must be a valid uuid.'); + } + if (persistedFaceId === null || persistedFaceId === undefined || typeof persistedFaceId.valueOf() !== 'string' || !msRest.isValidUuid(persistedFaceId)) { + throw new Error('persistedFaceId cannot be null or undefined and it must be of type string and must be a valid uuid.'); + } + if (userData !== null && userData !== undefined && typeof userData.valueOf() !== 'string') { + throw new Error('userData must be of type string.'); + } + if (userData !== null && userData !== undefined) { + if (userData.length > 1024) + { + throw new Error('"userData" should satisfy the constraint - "MaxLength": 1024'); + } + } + } catch (error) { + return callback(error); + } + let body; + if (userData !== null && userData !== undefined) { + body = new client.models['UpdatePersonFaceRequest'](); + body.userData = userData; + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}/persons/{personId}/persistedFaces/{persistedFaceId}'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + requestUrl = requestUrl.replace('{personId}', encodeURIComponent(personId.toString())); + requestUrl = requestUrl.replace('{persistedFaceId}', encodeURIComponent(persistedFaceId.toString())); + + // 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 (body !== null && body !== undefined) { + let requestModelMapper = new client.models['UpdatePersonFaceRequest']().mapper(); + requestModel = client.serialize(requestModelMapper, body, 'body'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(body, 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 !== 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['APIError']().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); + }); +} + +/** + * Add a representative face to a person for identification. The input face is + * specified as an image with a targetFace rectangle. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {string} url Publicly reachable URL of an image + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. + * + * @param {array} [options.targetFace] A face rectangle to specify the target + * face to be added to a person in the format of + * "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If + * there is more than one face in the image, targetFace is required to specify + * which face to add. No targetFace means there is only one face detected in + * the entire image. + * + * @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 PersistedFace} 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 _addPersonFaceFromUrl(personGroupId, personId, url, 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.'); + } + let userData = (options && options.userData !== undefined) ? options.userData : undefined; + let targetFace = (options && options.targetFace !== undefined) ? options.targetFace : undefined; + // 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (personId === null || personId === undefined || typeof personId.valueOf() !== 'string' || !msRest.isValidUuid(personId)) { + throw new Error('personId cannot be null or undefined and it must be of type string and must be a valid uuid.'); + } + if (userData !== null && userData !== undefined && typeof userData.valueOf() !== 'string') { + throw new Error('userData must be of type string.'); + } + if (userData !== null && userData !== undefined) { + if (userData.length > 1024) + { + throw new Error('"userData" should satisfy the constraint - "MaxLength": 1024'); + } + } + if (Array.isArray(targetFace)) { + for (let i = 0; i < targetFace.length; i++) { + if (targetFace[i] !== null && targetFace[i] !== undefined && typeof targetFace[i] !== 'number') { + throw new Error('targetFace[i] must be of type number.'); + } + } + } + if (url === null || url === undefined || typeof url.valueOf() !== 'string') { + throw new Error('url cannot be null or undefined and it must be of type string.'); + } + } catch (error) { + return callback(error); + } + let imageUrl; + if (url !== null && url !== undefined) { + imageUrl = new client.models['ImageUrl'](); + imageUrl.url = url; + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}/persons/{personId}/persistedFaces'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + requestUrl = requestUrl.replace('{personId}', encodeURIComponent(personId.toString())); + let queryParameters = []; + if (userData !== null && userData !== undefined) { + queryParameters.push('userData=' + encodeURIComponent(userData)); + } + if (targetFace !== null && targetFace !== undefined) { + queryParameters.push('targetFace=' + encodeURIComponent(targetFace.join(','))); + } + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // 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 (imageUrl !== null && imageUrl !== undefined) { + let requestModelMapper = new client.models['ImageUrl']().mapper(); + requestModel = client.serialize(requestModelMapper, imageUrl, 'imageUrl'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(imageUrl, 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 !== 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['APIError']().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['PersistedFace']().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); + }); +} + +/** + * Add a representative face to a person for identification. The input face is + * specified as an image with a targetFace rectangle. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {object} image An image stream. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. + * + * @param {array} [options.targetFace] A face rectangle to specify the target + * face to be added to a person in the format of + * "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If + * there is more than one face in the image, targetFace is required to specify + * which face to add. No targetFace means there is only one face detected in + * the entire image. + * + * @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 PersistedFace} 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 _addPersonFaceFromStream(personGroupId, personId, image, 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.'); + } + let userData = (options && options.userData !== undefined) ? options.userData : undefined; + let targetFace = (options && options.targetFace !== undefined) ? options.targetFace : undefined; + // 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 (personGroupId === null || personGroupId === undefined || typeof personGroupId.valueOf() !== 'string') { + throw new Error('personGroupId cannot be null or undefined and it must be of type string.'); + } + if (personGroupId !== null && personGroupId !== undefined) { + if (personGroupId.length > 64) + { + throw new Error('"personGroupId" should satisfy the constraint - "MaxLength": 64'); + } + if (personGroupId.match(/^[a-z0-9-_]+$/) === null) + { + throw new Error('"personGroupId" should satisfy the constraint - "Pattern": /^[a-z0-9-_]+$/'); + } + } + if (personId === null || personId === undefined || typeof personId.valueOf() !== 'string' || !msRest.isValidUuid(personId)) { + throw new Error('personId cannot be null or undefined and it must be of type string and must be a valid uuid.'); + } + if (userData !== null && userData !== undefined && typeof userData.valueOf() !== 'string') { + throw new Error('userData must be of type string.'); + } + if (userData !== null && userData !== undefined) { + if (userData.length > 1024) + { + throw new Error('"userData" should satisfy the constraint - "MaxLength": 1024'); + } + } + if (Array.isArray(targetFace)) { + for (let i = 0; i < targetFace.length; i++) { + if (targetFace[i] !== null && targetFace[i] !== undefined && typeof targetFace[i] !== 'number') { + throw new Error('targetFace[i] must be of type number.'); + } + } + } + if (image === null || image === undefined) { + throw new Error('image cannot be null or undefined and it must be of type object.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'persongroups/{personGroupId}/persons/{personId}/persistedFaces'; + requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint); + requestUrl = requestUrl.replace('{personGroupId}', encodeURIComponent(personGroupId)); + requestUrl = requestUrl.replace('{personId}', encodeURIComponent(personId.toString())); + let queryParameters = []; + if (userData !== null && userData !== undefined) { + queryParameters.push('userData=' + encodeURIComponent(userData)); + } + if (targetFace !== null && targetFace !== undefined) { + queryParameters.push('targetFace=' + encodeURIComponent(targetFace.join(','))); + } + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'POST'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/octet-stream'; + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + // Serialize Request + let requestContent = image; + httpRequest.body = requestContent; + // 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['APIError']().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['PersistedFace']().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 PersonGroupPerson. */ +class PersonGroupPerson { + /** + * Create a PersonGroupPerson. + * @param {FaceClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._create = _create; + this._list = _list; + this._deleteMethod = _deleteMethod; + this._get = _get; + this._update = _update; + this._deleteFace = _deleteFace; + this._getFace = _getFace; + this._updateFace = _updateFace; + this._addPersonFaceFromUrl = _addPersonFaceFromUrl; + this._addPersonFaceFromStream = _addPersonFaceFromStream; + } + + /** + * Create a new person in a specified person group. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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(personGroupId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._create(personGroupId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Create a new person in a specified person group. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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 {Person} - 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 Person} 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(personGroupId, 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(personGroupId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._create(personGroupId, options, optionalCallback); + } + } + + /** + * List all persons in a person group, and retrieve person information + * (including personId, name, userData and persistedFaceIds of registered faces + * of the person). + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.start] Starting person id to return (used to list a + * range of persons). + * + * @param {number} [options.top] Number of persons to return starting with the + * person id indicated by the 'start' parameter. + * + * @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. + */ + listWithHttpOperationResponse(personGroupId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._list(personGroupId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * List all persons in a person group, and retrieve person information + * (including personId, name, userData and persistedFaceIds of registered faces + * of the person). + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.start] Starting person id to return (used to list a + * range of persons). + * + * @param {number} [options.top] Number of persons to return starting with the + * person id indicated by the 'start' parameter. + * + * @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 {Array} - 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. + * + * {array} [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. + */ + list(personGroupId, 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._list(personGroupId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._list(personGroupId, options, optionalCallback); + } + } + + /** + * Delete an existing person from a person group. Persisted face images of the + * person will also be deleted. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @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(personGroupId, personId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._deleteMethod(personGroupId, personId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Delete an existing person from a person group. Persisted face images of the + * person will also be deleted. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @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(personGroupId, personId, 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(personGroupId, personId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._deleteMethod(personGroupId, personId, options, optionalCallback); + } + } + + /** + * Retrieve a person's information, including registered persisted faces, name + * and userData. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @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(personGroupId, personId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._get(personGroupId, personId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Retrieve a person's information, including registered persisted faces, name + * and userData. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @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 {Person} - 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 Person} 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(personGroupId, personId, 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(personGroupId, personId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._get(personGroupId, personId, options, optionalCallback); + } + } + + /** + * Update name or userData of a person. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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(personGroupId, personId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._update(personGroupId, personId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Update name or userData of a person. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.name] User defined name, maximum length is 128. + * + * @param {string} [options.userData] User specified data. Length should not + * exceed 16KB. + * + * @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. + */ + update(personGroupId, personId, 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(personGroupId, personId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._update(personGroupId, personId, options, optionalCallback); + } + } + + /** + * Delete a face from a person. Relative image for the persisted face will also + * be deleted. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. + * + * @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. + */ + deleteFaceWithHttpOperationResponse(personGroupId, personId, persistedFaceId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._deleteFace(personGroupId, personId, persistedFaceId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Delete a face from a person. Relative image for the persisted face will also + * be deleted. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. + * + * @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. + */ + deleteFace(personGroupId, personId, persistedFaceId, 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._deleteFace(personGroupId, personId, persistedFaceId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._deleteFace(personGroupId, personId, persistedFaceId, options, optionalCallback); + } + } + + /** + * Retrieve information about a persisted face (specified by persistedFaceId, + * personId and its belonging personGroupId). + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. + * + * @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. + */ + getFaceWithHttpOperationResponse(personGroupId, personId, persistedFaceId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._getFace(personGroupId, personId, persistedFaceId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Retrieve information about a persisted face (specified by persistedFaceId, + * personId and its belonging personGroupId). + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. + * + * @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 {PersistedFace} - 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 PersistedFace} 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. + */ + getFace(personGroupId, personId, persistedFaceId, 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._getFace(personGroupId, personId, persistedFaceId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._getFace(personGroupId, personId, persistedFaceId, options, optionalCallback); + } + } + + /** + * Update a person persisted face's userData field. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-provided data attached to the face. + * The size limit is 1KB. + * + * @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. + */ + updateFaceWithHttpOperationResponse(personGroupId, personId, persistedFaceId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._updateFace(personGroupId, personId, persistedFaceId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Update a person persisted face's userData field. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {uuid} persistedFaceId Id referencing a particular persistedFaceId of + * an existing face. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-provided data attached to the face. + * The size limit is 1KB. + * + * @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. + */ + updateFace(personGroupId, personId, persistedFaceId, 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._updateFace(personGroupId, personId, persistedFaceId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._updateFace(personGroupId, personId, persistedFaceId, options, optionalCallback); + } + } + + /** + * Add a representative face to a person for identification. The input face is + * specified as an image with a targetFace rectangle. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {string} url Publicly reachable URL of an image + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. + * + * @param {array} [options.targetFace] A face rectangle to specify the target + * face to be added to a person in the format of + * "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If + * there is more than one face in the image, targetFace is required to specify + * which face to add. No targetFace means there is only one face detected in + * the entire image. + * + * @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. + */ + addPersonFaceFromUrlWithHttpOperationResponse(personGroupId, personId, url, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._addPersonFaceFromUrl(personGroupId, personId, url, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Add a representative face to a person for identification. The input face is + * specified as an image with a targetFace rectangle. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {string} url Publicly reachable URL of an image + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. + * + * @param {array} [options.targetFace] A face rectangle to specify the target + * face to be added to a person in the format of + * "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If + * there is more than one face in the image, targetFace is required to specify + * which face to add. No targetFace means there is only one face detected in + * the entire image. + * + * @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 {PersistedFace} - 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 PersistedFace} 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. + */ + addPersonFaceFromUrl(personGroupId, personId, url, 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._addPersonFaceFromUrl(personGroupId, personId, url, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._addPersonFaceFromUrl(personGroupId, personId, url, options, optionalCallback); + } + } + + /** + * Add a representative face to a person for identification. The input face is + * specified as an image with a targetFace rectangle. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {object} image An image stream. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. + * + * @param {array} [options.targetFace] A face rectangle to specify the target + * face to be added to a person in the format of + * "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If + * there is more than one face in the image, targetFace is required to specify + * which face to add. No targetFace means there is only one face detected in + * the entire image. + * + * @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. + */ + addPersonFaceFromStreamWithHttpOperationResponse(personGroupId, personId, image, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._addPersonFaceFromStream(personGroupId, personId, image, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Add a representative face to a person for identification. The input face is + * specified as an image with a targetFace rectangle. + * + * @param {string} personGroupId Id referencing a particular person group. + * + * @param {uuid} personId Id referencing a particular person. + * + * @param {object} image An image stream. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.userData] User-specified data about the face for + * any purpose. The maximum length is 1KB. + * + * @param {array} [options.targetFace] A face rectangle to specify the target + * face to be added to a person in the format of + * "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If + * there is more than one face in the image, targetFace is required to specify + * which face to add. No targetFace means there is only one face detected in + * the entire image. + * + * @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 {PersistedFace} - 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 PersistedFace} 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. + */ + addPersonFaceFromStream(personGroupId, personId, image, 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._addPersonFaceFromStream(personGroupId, personId, image, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._addPersonFaceFromStream(personGroupId, personId, image, options, optionalCallback); + } + } + +} + +module.exports = PersonGroupPerson; diff --git a/lib/services/face/package.json b/lib/services/face/package.json index 43fe4f224e..0742ce3b32 100644 --- a/lib/services/face/package.json +++ b/lib/services/face/package.json @@ -1,35 +1,24 @@ { "name": "azure-cognitiveservices-face", "author": "Microsoft Corporation", - "contributors": [ - "Xu, Willie " - ], + "description": "FaceClient Library with typescript type definitions for node", "version": "1.0.0-preview", - "description": "Microsoft Azure Cognitive Services Face API Client Library for Node.js", - "tags": [ - "azure", - "sdk" - ], + "dependencies": { + "ms-rest": "^2.3.3" + }, "keywords": [ "node", "azure" ], - "main": "./lib/faceAPIClient.js", - "types": "./lib/faceAPIClient.d.ts", "license": "MIT", - "dependencies": { - "ms-rest": "^2.2.5", - "ms-rest-azure": "^2.5.0" - }, - "homepage": "http://github.com/Azure/azure-sdk-for-node", + "main": "./lib/faceClient.js", + "types": "./lib/faceClient.d.ts", + "homepage": "http://github.com/azure/azure-sdk-for-node", "repository": { "type": "git", - "url": "git@github.com:Azure/azure-sdk-for-node.git" + "url": "https://github.com/azure/azure-sdk-for-node.git" }, "bugs": { "url": "http://github.com/Azure/azure-sdk-for-node/issues" - }, - "scripts": { - "test": "npm -s run-script jshint" } -} \ No newline at end of file +}