UNPKG

@google-cloud/vision

Version:

Google Cloud Vision API client for Node.js

1,047 lines 81.6 kB
"use strict"; // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // ** This file is automatically generated by gapic-generator-typescript. ** // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** Object.defineProperty(exports, "__esModule", { value: true }); exports.ProductSearchClient = void 0; const gax = require("google-gax"); const path = require("path"); const gapicConfig = require("./product_search_client_config.json"); const google_gax_1 = require("google-gax"); const version = require('../../../package.json').version; /** * Manages Products and ProductSets of reference images for use in product * search. It uses the following resource model: * * - The API has a collection of {@link google.cloud.vision.v1.ProductSet|ProductSet} resources, named * `projects/* /locations/* /productSets/*`, which acts as a way to put different * products into groups to limit identification. * * In parallel, * * - The API has a collection of {@link google.cloud.vision.v1.Product|Product} resources, named * `projects/* /locations/* /products/*` * * - Each {@link google.cloud.vision.v1.Product|Product} has a collection of {@link google.cloud.vision.v1.ReferenceImage|ReferenceImage} resources, named * `projects/* /locations/* /products/* /referenceImages/*` * @class * @memberof v1 */ class ProductSearchClient { /** * Construct an instance of ProductSearchClient. * * @param {object} [options] - The configuration object. See the subsequent * parameters for more details. * @param {object} [options.credentials] - Credentials object. * @param {string} [options.credentials.client_email] * @param {string} [options.credentials.private_key] * @param {string} [options.email] - Account email address. Required when * using a .pem or .p12 keyFilename. * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or * .p12 key downloaded from the Google Developers Console. If you provide * a path to a JSON file, the projectId option below is not necessary. * NOTE: .pem and .p12 require you to specify options.email as well. * @param {number} [options.port] - The port on which to connect to * the remote host. * @param {string} [options.projectId] - The project ID from the Google * Developer's Console, e.g. 'grape-spaceship-123'. We will also check * the environment variable GCLOUD_PROJECT for your project ID. If your * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ constructor(opts) { this._terminated = false; this.descriptors = { page: {}, stream: {}, longrunning: {}, batching: {}, }; // Ensure that options include the service address and port. const staticMembers = this.constructor; const servicePath = opts && opts.servicePath ? opts.servicePath : opts && opts.apiEndpoint ? opts.apiEndpoint : staticMembers.servicePath; const port = opts && opts.port ? opts.port : staticMembers.port; if (!opts) { opts = { servicePath, port }; } opts.servicePath = opts.servicePath || servicePath; opts.port = opts.port || port; // users can override the config from client side, like retry codes name. // The detailed structure of the clientConfig can be found here: https://github.com/googleapis/gax-nodejs/blob/master/src/gax.ts#L546 // The way to override client config for Showcase API: // // const customConfig = {"interfaces": {"google.showcase.v1beta1.Echo": {"methods": {"Echo": {"retry_codes_name": "idempotent", "retry_params_name": "default"}}}}} // const showcaseClient = new showcaseClient({ projectId, customConfig }); opts.clientConfig = opts.clientConfig || {}; // If we're running in browser, it's OK to omit `fallback` since // google-gax has `browser` field in its `package.json`. // For Electron (which does not respect `browser` field), // pass `{fallback: true}` to the ProductSearchClient constructor. this._gaxModule = opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = this.constructor.scopes; this._gaxGrpc = new this._gaxModule.GrpcClient(opts); // Save options to use in initialize() method. this._opts = opts; // Save the auth object to the client, for use by other methods. this.auth = this._gaxGrpc.auth; // Determine the client header string. const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); } // Load the applicable protos. // For Node.js, pass the path to JSON proto file. // For browsers, pass the JSON content. const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json'); this._protos = this._gaxGrpc.loadProto(opts.fallback ? // eslint-disable-next-line @typescript-eslint/no-var-requires require('../../protos/protos.json') : nodejsProtoPath); // This API contains "path templates"; forward-slash-separated // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this.pathTemplates = { locationPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}'), productPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/products/{product}'), productSetPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/productSets/{product_set}'), referenceImagePathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}'), }; // Some of the methods on this service return "paged" results, // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. this.descriptors.page = { listProductSets: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'productSets'), listProducts: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'products'), listReferenceImages: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'referenceImages'), listProductsInProductSet: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'products'), }; // This API contains "long-running operations", which return a // an Operation object that allows for tracking of the operation, // rather than holding a request open. const protoFilesRoot = opts.fallback ? this._gaxModule.protobuf.Root.fromJSON( // eslint-disable-next-line @typescript-eslint/no-var-requires require('../../protos/protos.json')) : this._gaxModule.protobuf.loadSync(nodejsProtoPath); this.operationsClient = this._gaxModule .lro({ auth: this.auth, grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined, }) .operationsClient(opts); const importProductSetsResponse = protoFilesRoot.lookup('.google.cloud.vision.v1.ImportProductSetsResponse'); const importProductSetsMetadata = protoFilesRoot.lookup('.google.cloud.vision.v1.BatchOperationMetadata'); const purgeProductsResponse = protoFilesRoot.lookup('.google.protobuf.Empty'); const purgeProductsMetadata = protoFilesRoot.lookup('.google.cloud.vision.v1.BatchOperationMetadata'); this.descriptors.longrunning = { importProductSets: new this._gaxModule.LongrunningDescriptor(this.operationsClient, importProductSetsResponse.decode.bind(importProductSetsResponse), importProductSetsMetadata.decode.bind(importProductSetsMetadata)), purgeProducts: new this._gaxModule.LongrunningDescriptor(this.operationsClient, purgeProductsResponse.decode.bind(purgeProductsResponse), purgeProductsMetadata.decode.bind(purgeProductsMetadata)), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings('google.cloud.vision.v1.ProductSearch', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') }); // Set up a dictionary of "inner API calls"; the core implementation // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this.innerApiCalls = {}; } /** * Initialize the client. * Performs asynchronous operations (such as authentication) and prepares the client. * This function will be called automatically when any class method is called for the * first time, but if you need to initialize it before calling an actual method, * feel free to call initialize() directly. * * You can await on this method if you want to make sure the client is initialized. * * @returns {Promise} A promise that resolves to an authenticated service stub. */ initialize() { // If the client stub promise is already initialized, return immediately. if (this.productSearchStub) { return this.productSearchStub; } // Put together the "service stub" for // google.cloud.vision.v1.ProductSearch. this.productSearchStub = this._gaxGrpc.createStub(this._opts.fallback ? this._protos.lookupService('google.cloud.vision.v1.ProductSearch') : // eslint-disable-next-line @typescript-eslint/no-explicit-any this._protos.google.cloud.vision.v1.ProductSearch, this._opts); // Iterate over each of the methods that the service provides // and create an API call method for each. const productSearchStubMethods = [ 'createProductSet', 'listProductSets', 'getProductSet', 'updateProductSet', 'deleteProductSet', 'createProduct', 'listProducts', 'getProduct', 'updateProduct', 'deleteProduct', 'createReferenceImage', 'deleteReferenceImage', 'listReferenceImages', 'getReferenceImage', 'addProductToProductSet', 'removeProductFromProductSet', 'listProductsInProductSet', 'importProductSets', 'purgeProducts', ]; for (const methodName of productSearchStubMethods) { const callPromise = this.productSearchStub.then(stub => (...args) => { if (this._terminated) { return Promise.reject('The client has already been closed.'); } const func = stub[methodName]; return func.apply(stub, args); }, (err) => () => { throw err; }); const apiCall = this._gaxModule.createApiCall(callPromise, this._defaults[methodName], this.descriptors.page[methodName] || this.descriptors.stream[methodName] || this.descriptors.longrunning[methodName]); this.innerApiCalls[methodName] = apiCall; } return this.productSearchStub; } /** * The DNS address for this API service. */ static get servicePath() { return 'vision.googleapis.com'; } /** * The DNS address for this API service - same as servicePath(), * exists for compatibility reasons. */ static get apiEndpoint() { return 'vision.googleapis.com'; } /** * The port for this API service. */ static get port() { return 443; } /** * The scopes needed to make gRPC calls for every method defined * in this service. */ static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision', ]; } /** * Return the project ID used by this class. * @param {function(Error, string)} callback - the callback to * be called with the current project Id. */ getProjectId(callback) { if (callback) { this.auth.getProjectId(callback); return; } return this.auth.getProjectId(); } /** * Creates and returns a new ProductSet resource. * * Possible errors: * * * Returns INVALID_ARGUMENT if display_name is missing, or is longer than * 4096 characters. * * @param {Object} request * The request object that will be sent. * @param {string} request.parent * Required. The project in which the ProductSet should be created. * * Format is `projects/PROJECT_ID/locations/LOC_ID`. * @param {google.cloud.vision.v1.ProductSet} request.productSet * Required. The ProductSet to create. * @param {string} request.productSetId * A user-supplied resource id for this ProductSet. If set, the server will * attempt to use this value as the resource id. If it is already in use, an * error is returned with code ALREADY_EXISTS. Must be at most 128 characters * long. It cannot contain the character `/`. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [ProductSet]{@link google.cloud.vision.v1.ProductSet}. * The promise has a method named "cancel" which cancels the ongoing API call. */ createProductSet(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ parent: request.parent || '', }); this.initialize(); return this.innerApiCalls.createProductSet(request, options, callback); } /** * Gets information associated with a ProductSet. * * Possible errors: * * * Returns NOT_FOUND if the ProductSet does not exist. * * @param {Object} request * The request object that will be sent. * @param {string} request.name * Required. Resource name of the ProductSet to get. * * Format is: * `projects/PROJECT_ID/locations/LOG_ID/productSets/PRODUCT_SET_ID` * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [ProductSet]{@link google.cloud.vision.v1.ProductSet}. * The promise has a method named "cancel" which cancels the ongoing API call. */ getProductSet(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ name: request.name || '', }); this.initialize(); return this.innerApiCalls.getProductSet(request, options, callback); } /** * Makes changes to a ProductSet resource. * Only display_name can be updated currently. * * Possible errors: * * * Returns NOT_FOUND if the ProductSet does not exist. * * Returns INVALID_ARGUMENT if display_name is present in update_mask but * missing from the request or longer than 4096 characters. * * @param {Object} request * The request object that will be sent. * @param {google.cloud.vision.v1.ProductSet} request.productSet * Required. The ProductSet resource which replaces the one on the server. * @param {google.protobuf.FieldMask} request.updateMask * The {@link google.protobuf.FieldMask|FieldMask} that specifies which fields to * update. * If update_mask isn't specified, all mutable fields are to be updated. * Valid mask path is `display_name`. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [ProductSet]{@link google.cloud.vision.v1.ProductSet}. * The promise has a method named "cancel" which cancels the ongoing API call. */ updateProductSet(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ 'product_set.name': request.productSet.name || '', }); this.initialize(); return this.innerApiCalls.updateProductSet(request, options, callback); } /** * Permanently deletes a ProductSet. Products and ReferenceImages in the * ProductSet are not deleted. * * The actual image files are not deleted from Google Cloud Storage. * * @param {Object} request * The request object that will be sent. * @param {string} request.name * Required. Resource name of the ProductSet to delete. * * Format is: * `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID` * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}. * The promise has a method named "cancel" which cancels the ongoing API call. */ deleteProductSet(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ name: request.name || '', }); this.initialize(); return this.innerApiCalls.deleteProductSet(request, options, callback); } /** * Creates and returns a new product resource. * * Possible errors: * * * Returns INVALID_ARGUMENT if display_name is missing or longer than 4096 * characters. * * Returns INVALID_ARGUMENT if description is longer than 4096 characters. * * Returns INVALID_ARGUMENT if product_category is missing or invalid. * * @param {Object} request * The request object that will be sent. * @param {string} request.parent * Required. The project in which the Product should be created. * * Format is * `projects/PROJECT_ID/locations/LOC_ID`. * @param {google.cloud.vision.v1.Product} request.product * Required. The product to create. * @param {string} request.productId * A user-supplied resource id for this Product. If set, the server will * attempt to use this value as the resource id. If it is already in use, an * error is returned with code ALREADY_EXISTS. Must be at most 128 characters * long. It cannot contain the character `/`. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [Product]{@link google.cloud.vision.v1.Product}. * The promise has a method named "cancel" which cancels the ongoing API call. */ createProduct(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ parent: request.parent || '', }); this.initialize(); return this.innerApiCalls.createProduct(request, options, callback); } /** * Gets information associated with a Product. * * Possible errors: * * * Returns NOT_FOUND if the Product does not exist. * * @param {Object} request * The request object that will be sent. * @param {string} request.name * Required. Resource name of the Product to get. * * Format is: * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [Product]{@link google.cloud.vision.v1.Product}. * The promise has a method named "cancel" which cancels the ongoing API call. */ getProduct(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ name: request.name || '', }); this.initialize(); return this.innerApiCalls.getProduct(request, options, callback); } /** * Makes changes to a Product resource. * Only the `display_name`, `description`, and `labels` fields can be updated * right now. * * If labels are updated, the change will not be reflected in queries until * the next index time. * * Possible errors: * * * Returns NOT_FOUND if the Product does not exist. * * Returns INVALID_ARGUMENT if display_name is present in update_mask but is * missing from the request or longer than 4096 characters. * * Returns INVALID_ARGUMENT if description is present in update_mask but is * longer than 4096 characters. * * Returns INVALID_ARGUMENT if product_category is present in update_mask. * * @param {Object} request * The request object that will be sent. * @param {google.cloud.vision.v1.Product} request.product * Required. The Product resource which replaces the one on the server. * product.name is immutable. * @param {google.protobuf.FieldMask} request.updateMask * The {@link google.protobuf.FieldMask|FieldMask} that specifies which fields * to update. * If update_mask isn't specified, all mutable fields are to be updated. * Valid mask paths include `product_labels`, `display_name`, and * `description`. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [Product]{@link google.cloud.vision.v1.Product}. * The promise has a method named "cancel" which cancels the ongoing API call. */ updateProduct(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ 'product.name': request.product.name || '', }); this.initialize(); return this.innerApiCalls.updateProduct(request, options, callback); } /** * Permanently deletes a product and its reference images. * * Metadata of the product and all its images will be deleted right away, but * search queries against ProductSets containing the product may still work * until all related caches are refreshed. * * @param {Object} request * The request object that will be sent. * @param {string} request.name * Required. Resource name of product to delete. * * Format is: * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}. * The promise has a method named "cancel" which cancels the ongoing API call. */ deleteProduct(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ name: request.name || '', }); this.initialize(); return this.innerApiCalls.deleteProduct(request, options, callback); } /** * Creates and returns a new ReferenceImage resource. * * The `bounding_poly` field is optional. If `bounding_poly` is not specified, * the system will try to detect regions of interest in the image that are * compatible with the product_category on the parent product. If it is * specified, detection is ALWAYS skipped. The system converts polygons into * non-rotated rectangles. * * Note that the pipeline will resize the image if the image resolution is too * large to process (above 50MP). * * Possible errors: * * * Returns INVALID_ARGUMENT if the image_uri is missing or longer than 4096 * characters. * * Returns INVALID_ARGUMENT if the product does not exist. * * Returns INVALID_ARGUMENT if bounding_poly is not provided, and nothing * compatible with the parent product's product_category is detected. * * Returns INVALID_ARGUMENT if bounding_poly contains more than 10 polygons. * * @param {Object} request * The request object that will be sent. * @param {string} request.parent * Required. Resource name of the product in which to create the reference image. * * Format is * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`. * @param {google.cloud.vision.v1.ReferenceImage} request.referenceImage * Required. The reference image to create. * If an image ID is specified, it is ignored. * @param {string} request.referenceImageId * A user-supplied resource id for the ReferenceImage to be added. If set, * the server will attempt to use this value as the resource id. If it is * already in use, an error is returned with code ALREADY_EXISTS. Must be at * most 128 characters long. It cannot contain the character `/`. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [ReferenceImage]{@link google.cloud.vision.v1.ReferenceImage}. * The promise has a method named "cancel" which cancels the ongoing API call. */ createReferenceImage(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ parent: request.parent || '', }); this.initialize(); return this.innerApiCalls.createReferenceImage(request, options, callback); } /** * Permanently deletes a reference image. * * The image metadata will be deleted right away, but search queries * against ProductSets containing the image may still work until all related * caches are refreshed. * * The actual image files are not deleted from Google Cloud Storage. * * @param {Object} request * The request object that will be sent. * @param {string} request.name * Required. The resource name of the reference image to delete. * * Format is: * * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID` * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}. * The promise has a method named "cancel" which cancels the ongoing API call. */ deleteReferenceImage(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ name: request.name || '', }); this.initialize(); return this.innerApiCalls.deleteReferenceImage(request, options, callback); } /** * Gets information associated with a ReferenceImage. * * Possible errors: * * * Returns NOT_FOUND if the specified image does not exist. * * @param {Object} request * The request object that will be sent. * @param {string} request.name * Required. The resource name of the ReferenceImage to get. * * Format is: * * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [ReferenceImage]{@link google.cloud.vision.v1.ReferenceImage}. * The promise has a method named "cancel" which cancels the ongoing API call. */ getReferenceImage(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ name: request.name || '', }); this.initialize(); return this.innerApiCalls.getReferenceImage(request, options, callback); } /** * Adds a Product to the specified ProductSet. If the Product is already * present, no change is made. * * One Product can be added to at most 100 ProductSets. * * Possible errors: * * * Returns NOT_FOUND if the Product or the ProductSet doesn't exist. * * @param {Object} request * The request object that will be sent. * @param {string} request.name * Required. The resource name for the ProductSet to modify. * * Format is: * `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID` * @param {string} request.product * Required. The resource name for the Product to be added to this ProductSet. * * Format is: * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}. * The promise has a method named "cancel" which cancels the ongoing API call. */ addProductToProductSet(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ name: request.name || '', }); this.initialize(); return this.innerApiCalls.addProductToProductSet(request, options, callback); } /** * Removes a Product from the specified ProductSet. * * @param {Object} request * The request object that will be sent. * @param {string} request.name * Required. The resource name for the ProductSet to modify. * * Format is: * `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID` * @param {string} request.product * Required. The resource name for the Product to be removed from this ProductSet. * * Format is: * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}. * The promise has a method named "cancel" which cancels the ongoing API call. */ removeProductFromProductSet(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ name: request.name || '', }); this.initialize(); return this.innerApiCalls.removeProductFromProductSet(request, options, callback); } /** * Asynchronous API that imports a list of reference images to specified * product sets based on a list of image information. * * The {@link google.longrunning.Operation|google.longrunning.Operation} API can be used to keep track of the * progress and results of the request. * `Operation.metadata` contains `BatchOperationMetadata`. (progress) * `Operation.response` contains `ImportProductSetsResponse`. (results) * * The input source of this method is a csv file on Google Cloud Storage. * For the format of the csv file please see * {@link google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri|ImportProductSetsGcsSource.csv_file_uri}. * * @param {Object} request * The request object that will be sent. * @param {string} request.parent * Required. The project in which the ProductSets should be imported. * * Format is `projects/PROJECT_ID/locations/LOC_ID`. * @param {google.cloud.vision.v1.ImportProductSetsInputConfig} request.inputConfig * Required. The input content for the list of requests. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [Operation]{@link google.longrunning.Operation}. * The promise has a method named "cancel" which cancels the ongoing API call. */ importProductSets(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ parent: request.parent || '', }); this.initialize(); return this.innerApiCalls.importProductSets(request, options, callback); } /** * Check the status of the long running operation returned by the importProductSets() method. * @param {String} name * The operation name that will be passed. * @returns {Promise} - The promise which resolves to an object. * The decoded operation object has result and metadata field to get information from. * * @example: * const decodedOperation = await checkImportProductSetsProgress(name); * console.log(decodedOperation.result); * console.log(decodedOperation.done); * console.log(decodedOperation.metadata); * */ async checkImportProductSetsProgress(name) { const request = new google_gax_1.operationsProtos.google.longrunning.GetOperationRequest({ name }); const [operation] = await this.operationsClient.getOperation(request); const decodeOperation = new gax.Operation(operation, this.descriptors.longrunning.importProductSets, gax.createDefaultBackoffSettings()); return decodeOperation; } /** * Asynchronous API to delete all Products in a ProductSet or all Products * that are in no ProductSet. * * If a Product is a member of the specified ProductSet in addition to other * ProductSets, the Product will still be deleted. * * It is recommended to not delete the specified ProductSet until after this * operation has completed. It is also recommended to not add any of the * Products involved in the batch delete to a new ProductSet while this * operation is running because those Products may still end up deleted. * * It's not possible to undo the PurgeProducts operation. Therefore, it is * recommended to keep the csv files used in ImportProductSets (if that was * how you originally built the Product Set) before starting PurgeProducts, in * case you need to re-import the data after deletion. * * If the plan is to purge all of the Products from a ProductSet and then * re-use the empty ProductSet to re-import new Products into the empty * ProductSet, you must wait until the PurgeProducts operation has finished * for that ProductSet. * * The {@link google.longrunning.Operation|google.longrunning.Operation} API can be used to keep track of the * progress and results of the request. * `Operation.metadata` contains `BatchOperationMetadata`. (progress) * * @param {Object} request * The request object that will be sent. * @param {google.cloud.vision.v1.ProductSetPurgeConfig} request.productSetPurgeConfig * Specify which ProductSet contains the Products to be deleted. * @param {boolean} request.deleteOrphanProducts * If delete_orphan_products is true, all Products that are not in any * ProductSet will be deleted. * @param {string} request.parent * Required. The project and location in which the Products should be deleted. * * Format is `projects/PROJECT_ID/locations/LOC_ID`. * @param {boolean} request.force * The default value is false. Override this value to true to actually perform * the purge. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is an object representing [Operation]{@link google.longrunning.Operation}. * The promise has a method named "cancel" which cancels the ongoing API call. */ purgeProducts(request, optionsOrCallback, callback) { request = request || {}; let options; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; } else { options = optionsOrCallback; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ parent: request.parent || '', }); this.initialize(); return this.innerApiCalls.purgeProducts(request, options, callback); } /** * Check the status of the long running operation returned by the purgeProducts() method. * @param {String} name * The operation name that will be passed. * @returns {Promise} - The promise which resolves to an object. * The decoded operation object has result and metadata field to get information from. * * @example: * const decodedOperation = await checkPurgeProductsProgress(name); * console.log(decodedOperation.result); * console.log(decodedOperation.done); * console.log(decodedOperation.metadata); * */ async checkPurgeProductsProgress(name) { const request = new google_gax_1.operationsProtos.google.longrunning.GetOperationRequest({ name }); const [operation] = await this.operationsClient.getOperation(request); const decodeOperation = new gax.Operation(operation, this.descriptors.longrunning.purgeProducts, gax.createDefaultBackoffSettings()); return decodeOperation; } /** * Lists ProductSets in an unspecified order. * * Possible errors: * * * Returns INVALID_ARGUMENT if page_size is greater than 100, or less * than 1. * * @param {Object} request * The request object that will be sent. * @param {string} request.parent * Required. The project from which ProductSets should be listed. * * Format is `projects/PROJECT_ID/locations/LOC_ID`. * @param {number} request.pageSize * The maximum number of items to return. Default 10, maximum 100. * @param {string} request.pageToken * The next_page_token returned from a previous List request, if any. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. * The first element of the array is Array of [ProductSet]{@link google.cloud.vision.v1.ProductSet}. * The client library support auto-pagination by default: it will call the API as many * times as needed and will merge results from all the pages into this array. * * When autoPaginate: false is specified through options, the array has three elements. * The first element is Array of [ProductSet]{@link google.cloud.vision.v1.ProductSet} that corresponds to * the one page received from the API server. * If the second element is not null it contains the request object of type [ListProductSetsRequest]{@link google.cloud.vision.v1.ListProductSetsRequest} * that can be used to obtain the next page of the results. * If it is null, the next page does not exist. * The third element contains the raw response received from the API server. Its type is * [ListProductSetsResponse]{@link google.cloud.vision.v1.ListProductSetsResponse}. * * The promise has a method named "cancel" which cancels the ongoing API call. */ listProductSets(request, options