diff --git a/samples/interactive-tutorials/events/purge-user-events.js b/samples/interactive-tutorials/events/purge-user-events.js index e63c9f2c..3815fa78 100644 --- a/samples/interactive-tutorials/events/purge-user-events.js +++ b/samples/interactive-tutorials/events/purge-user-events.js @@ -21,11 +21,14 @@ async function main() { const {UserEventServiceClient} = require('@google-cloud/retail').v2; const utils = require('../setup/setup-cleanup'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new UserEventServiceClient(); + + const projectId = await retailClient.getProjectId(); const visitorId = 'test_visitor_id'; // Placement - const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog`; + const parent = `projects/${projectId}/locations/global/catalogs/default_catalog`; // The filter string to specify the events to be deleted with a // length limit of 5,000 characters. @@ -34,9 +37,6 @@ async function main() { // Actually perform the purge. const force = true; - // Instantiates a client. - const retailClient = new UserEventServiceClient(); - const callPurgeUserEvents = async () => { // Construct request const request = { diff --git a/samples/interactive-tutorials/events/rejoin-user-events.js b/samples/interactive-tutorials/events/rejoin-user-events.js index 82e73a54..90bdcf39 100644 --- a/samples/interactive-tutorials/events/rejoin-user-events.js +++ b/samples/interactive-tutorials/events/rejoin-user-events.js @@ -21,11 +21,14 @@ async function main() { const {UserEventServiceClient} = require('@google-cloud/retail').v2; const utils = require('../setup/setup-cleanup'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new UserEventServiceClient(); + + const projectId = await retailClient.getProjectId(); const visitorId = 'test_visitor_id'; // Placement - const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog`; // TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE + const parent = `projects/${projectId}/locations/global/catalogs/default_catalog`; // TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE const UserEventRejoinScope = { USER_EVENT_REJOIN_SCOPE_UNSPECIFIED: 0, @@ -36,9 +39,6 @@ async function main() { // events to be rejoined with the latest product catalog const userEventRejoinScope = UserEventRejoinScope.UNJOINED_EVENTS; - // Instantiates a client. - const retailClient = new UserEventServiceClient(); - const callRejoinUserEvents = async () => { // Construct request const request = { diff --git a/samples/interactive-tutorials/events/write-user-event.js b/samples/interactive-tutorials/events/write-user-event.js index 6763abbd..fbcbf04d 100644 --- a/samples/interactive-tutorials/events/write-user-event.js +++ b/samples/interactive-tutorials/events/write-user-event.js @@ -21,11 +21,14 @@ async function main() { const {UserEventServiceClient} = require('@google-cloud/retail').v2; const utils = require('../setup/setup-cleanup'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new UserEventServiceClient(); + + const projectId = await retailClient.getProjectId(); const visitorId = 'test_visitor_id'; // Placement - const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog`; // TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE + const parent = `projects/${projectId}/locations/global/catalogs/default_catalog`; // TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE // User event to write const userEvent = { @@ -36,9 +39,6 @@ async function main() { }, }; - // Instantiates a client. - const retailClient = new UserEventServiceClient(); - const callWriteUserEvent = async () => { // Construct request const request = { diff --git a/samples/interactive-tutorials/product/add-fulfillment-places.js b/samples/interactive-tutorials/product/add-fulfillment-places.js index 9612d1c8..dcb9972a 100644 --- a/samples/interactive-tutorials/product/add-fulfillment-places.js +++ b/samples/interactive-tutorials/product/add-fulfillment-places.js @@ -21,11 +21,14 @@ async function main(generatedProductId) { const {ProductServiceClient} = require('@google-cloud/retail').v2; const utils = require('../setup/setup-cleanup'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new ProductServiceClient(); + + const projectId = await retailClient.getProjectId(); // Create product const createdProduct = await utils.createProduct( - projectNumber, + projectId, generatedProductId ); @@ -50,9 +53,6 @@ async function main(generatedProductId) { // at most 1 day and processed once the product is created const allowMissing = true; - // Instantiates a client. - const retailClient = new ProductServiceClient(); - const calladdFulfillmentPlaces = async () => { // Construct request const request = { diff --git a/samples/interactive-tutorials/product/create-product.js b/samples/interactive-tutorials/product/create-product.js index a385af3c..6823b29b 100644 --- a/samples/interactive-tutorials/product/create-product.js +++ b/samples/interactive-tutorials/product/create-product.js @@ -21,10 +21,13 @@ async function main(generatedProductId) { const {ProductServiceClient} = require('@google-cloud/retail').v2; const utils = require('../setup/setup-cleanup'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new ProductServiceClient(); + + const projectId = await retailClient.getProjectId(); // The parent catalog resource name - const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch`; + const parent = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch`; // The ID to use for the product const productId = generatedProductId @@ -45,9 +48,6 @@ async function main(generatedProductId) { availability: 'IN_STOCK', }; - // Instantiates a client. - const retailClient = new ProductServiceClient(); - const callCreateProduct = async () => { // Construct request const request = { diff --git a/samples/interactive-tutorials/product/crud-product.js b/samples/interactive-tutorials/product/crud-product.js index a4c3ea1e..bbf98d01 100644 --- a/samples/interactive-tutorials/product/crud-product.js +++ b/samples/interactive-tutorials/product/crud-product.js @@ -20,10 +20,13 @@ async function main(generatedProductId) { // Imports the Google Cloud client library. const {ProductServiceClient} = require('@google-cloud/retail').v2; - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new ProductServiceClient(); + + const projectId = await retailClient.getProjectId(); // The parent catalog resource name - const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch`; + const parent = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch`; // The ID to use for the product const productId = generatedProductId @@ -63,9 +66,6 @@ async function main(generatedProductId) { availability: 'OUT_OF_STOCK', }; - // Instantiates a client. - const retailClient = new ProductServiceClient(); - const callCreateProduct = async () => { // Construct request const request = { diff --git a/samples/interactive-tutorials/product/delete-product.js b/samples/interactive-tutorials/product/delete-product.js index daee6c17..6965c0ea 100644 --- a/samples/interactive-tutorials/product/delete-product.js +++ b/samples/interactive-tutorials/product/delete-product.js @@ -21,17 +21,17 @@ async function main(generatedProductId) { const {ProductServiceClient} = require('@google-cloud/retail').v2; const utils = require('../setup/setup-cleanup'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new ProductServiceClient(); + + const projectId = await retailClient.getProjectId(); // Create product - const product = await utils.createProduct(projectNumber, generatedProductId); + const product = await utils.createProduct(projectId, generatedProductId); // Full resource name of Product const name = product.name; - // Instantiates a client. - const retailClient = new ProductServiceClient(); - const callDeleteProduct = async () => { // Construct request const request = { diff --git a/samples/interactive-tutorials/product/get-product.js b/samples/interactive-tutorials/product/get-product.js index ef015d8e..d9ae4913 100644 --- a/samples/interactive-tutorials/product/get-product.js +++ b/samples/interactive-tutorials/product/get-product.js @@ -21,17 +21,17 @@ async function main(generatedProductId) { const {ProductServiceClient} = require('@google-cloud/retail').v2; const utils = require('../setup/setup-cleanup'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new ProductServiceClient(); + + const projectId = await retailClient.getProjectId(); // Create product - const product = await utils.createProduct(projectNumber, generatedProductId); + const product = await utils.createProduct(projectId, generatedProductId); // Full resource name of Product const name = product.name; - // Instantiates a client. - const retailClient = new ProductServiceClient(); - const callGetProduct = async () => { // Construct request const request = { diff --git a/samples/interactive-tutorials/product/get-products-list.js b/samples/interactive-tutorials/product/get-products-list.js index cffc1465..63317a05 100644 --- a/samples/interactive-tutorials/product/get-products-list.js +++ b/samples/interactive-tutorials/product/get-products-list.js @@ -20,14 +20,14 @@ async function main() { // Imports the Google Cloud client library. const {ProductServiceClient} = require('@google-cloud/retail').v2; - const projectNumber = process.env['GCLOUD_PROJECT']; - - // Placement - const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch`; - // Instantiates a client. const retailClient = new ProductServiceClient(); + const projectId = await retailClient.getProjectId(); + + // Placement + const parent = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch`; + async function callListProducts() { console.log('Start get products list'); // Construct request diff --git a/samples/interactive-tutorials/product/import-products-big-query-table.js b/samples/interactive-tutorials/product/import-products-big-query-table.js index 2b9c3c84..52724046 100644 --- a/samples/interactive-tutorials/product/import-products-big-query-table.js +++ b/samples/interactive-tutorials/product/import-products-big-query-table.js @@ -20,15 +20,17 @@ async function main() { // Imports the Google Cloud client library. const {ProductServiceClient} = require('@google-cloud/retail').v2; - const projectNumber = process.env['GCLOUD_PROJECT']; - const projectId = process.env['PROJECT_ID']; + // Instantiates a client. + const retailClient = new ProductServiceClient(); + + const projectId = await retailClient.getProjectId(); const datasetId = 'products'; const tableId = 'products'; // TO CHECK ERROR HANDLING USE THE TABLE WITH INVALID PRODUCTS const dataSchema = 'product'; // Placement - const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch`; // TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE + const parent = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch`; // TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE // The desired input location of the data. const inputConfig = { @@ -55,9 +57,6 @@ async function main() { // The mode of reconciliation between existing products and the products to be imported. const reconciliationMode = reconciliationModes.INCREMENTAL; - // Instantiates a client. - const retailClient = new ProductServiceClient(); - const callImportProducts = async () => { // Construct request const request = { diff --git a/samples/interactive-tutorials/product/import-products-gcs.js b/samples/interactive-tutorials/product/import-products-gcs.js index d5ddaa42..e07e9ee7 100644 --- a/samples/interactive-tutorials/product/import-products-gcs.js +++ b/samples/interactive-tutorials/product/import-products-gcs.js @@ -20,14 +20,17 @@ async function main(bucketName) { // Imports the Google Cloud client library. const {ProductServiceClient} = require('@google-cloud/retail').v2; - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new ProductServiceClient(); + + const projectId = await retailClient.getProjectId(); const gcsBucket = `gs://${bucketName}`; const gcsErrorsBucket = `gs://${bucketName}/error`; const gcsProductsObject = 'products.json'; // TO CHECK ERROR HANDLING USE THE JSON WITH INVALID PRODUCT // Placement - const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch`; //TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE + const parent = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch`; //TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE // The desired input location of the data. const inputConfig = { @@ -48,9 +51,6 @@ async function main(bucketName) { IOperation: 2, }; - // Instantiates a client. - const retailClient = new ProductServiceClient(); - const callImportProducts = async () => { // Construct request const request = { diff --git a/samples/interactive-tutorials/product/import-products-inline-source.js b/samples/interactive-tutorials/product/import-products-inline-source.js index 396646b2..4dea2f0b 100644 --- a/samples/interactive-tutorials/product/import-products-inline-source.js +++ b/samples/interactive-tutorials/product/import-products-inline-source.js @@ -21,10 +21,13 @@ async function main(id1, id2) { const {ProductServiceClient} = require('@google-cloud/retail').v2; const utils = require('../setup/setup-cleanup'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new ProductServiceClient(); + + const projectId = await retailClient.getProjectId(); // Placement - const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch`; + const parent = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch`; const product1 = { id: id1 ? id1 : Math.random().toString(36).slice(2).toUpperCase(), @@ -89,9 +92,6 @@ async function main(id1, id2) { IOperation: 2, }; - // Instantiates a client. - const retailClient = new ProductServiceClient(); - const callImportProducts = async () => { // Construct request const request = { @@ -118,7 +118,7 @@ async function main(id1, id2) { console.log('Import products finished'); // Delete imported products - await utils.deleteProductsByIds(projectNumber, [product1.id, product2.id]); + await utils.deleteProductsByIds(projectId, [product1.id, product2.id]); console.log('Products deleted'); // [END retail_import_products_from_inline_source] } diff --git a/samples/interactive-tutorials/product/remove-fulfillment-places.js b/samples/interactive-tutorials/product/remove-fulfillment-places.js index 3e5ce00d..217a72b9 100644 --- a/samples/interactive-tutorials/product/remove-fulfillment-places.js +++ b/samples/interactive-tutorials/product/remove-fulfillment-places.js @@ -21,11 +21,14 @@ async function main(generatedProductId) { const {ProductServiceClient} = require('@google-cloud/retail').v2; const utils = require('../setup/setup-cleanup'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new ProductServiceClient(); + + const projectId = await retailClient.getProjectId(); // Create product const createdProduct = await utils.createProduct( - projectNumber, + projectId, generatedProductId, true ); @@ -47,9 +50,6 @@ async function main(generatedProductId) { seconds: Math.round(Date.now() / 1000), }; - // Instantiates a client. - const retailClient = new ProductServiceClient(); - const callRemoveFulfillmentPlaces = async () => { // Construct request const request = { diff --git a/samples/interactive-tutorials/product/set-inventory.js b/samples/interactive-tutorials/product/set-inventory.js index 28f1ca5d..1b849ceb 100644 --- a/samples/interactive-tutorials/product/set-inventory.js +++ b/samples/interactive-tutorials/product/set-inventory.js @@ -21,11 +21,14 @@ async function main(generatedProductId) { const {ProductServiceClient} = require('@google-cloud/retail').v2; const utils = require('../setup/setup-cleanup'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new ProductServiceClient(); + + const projectId = await retailClient.getProjectId(); // Create product const createdProduct = await utils.createProduct( - projectNumber, + projectId, generatedProductId ); @@ -61,9 +64,6 @@ async function main(generatedProductId) { // inventory update will still be processed and retained for at most 1 day until the product is created const allowMissing = true; - // Instantiates a client. - const retailClient = new ProductServiceClient(); - const callSetInventory = async () => { // Construct request const request = { diff --git a/samples/interactive-tutorials/product/update-product.js b/samples/interactive-tutorials/product/update-product.js index 30a2da2a..dd309d50 100644 --- a/samples/interactive-tutorials/product/update-product.js +++ b/samples/interactive-tutorials/product/update-product.js @@ -21,11 +21,14 @@ async function main(generatedProductId) { const {ProductServiceClient} = require('@google-cloud/retail').v2; const utils = require('../setup/setup-cleanup'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new ProductServiceClient(); + + const projectId = await retailClient.getProjectId(); // Create product const createdProduct = await utils.createProduct( - projectNumber, + projectId, generatedProductId ); @@ -51,9 +54,6 @@ async function main(generatedProductId) { availability: 'OUT_OF_STOCK', }; - // Instantiates a client. - const retailClient = new ProductServiceClient(); - const callUpdateProduct = async () => { // Construct request const request = { diff --git a/samples/interactive-tutorials/search/search-simple-query.js b/samples/interactive-tutorials/search/search-simple-query.js index 7a5bd036..ae56a861 100644 --- a/samples/interactive-tutorials/search/search-simple-query.js +++ b/samples/interactive-tutorials/search/search-simple-query.js @@ -21,10 +21,13 @@ async function main() { // Imports the Google Cloud client library. const {SearchServiceClient} = require('@google-cloud/retail'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new SearchServiceClient(); + + const projectId = await retailClient.getProjectId(); // Placement is used to identify the Serving Config name. - const placement = `projects/${projectNumber}/locations/global/catalogs/default_catalog/placements/default_search`; + const placement = `projects/${projectId}/locations/global/catalogs/default_catalog/placements/default_search`; // Raw search query. const query = 'Hoodie'; //TRY DIFFERENT QUERY PHRASES @@ -35,9 +38,6 @@ async function main() { // Maximum number of Products to return. const pageSize = 10; - // Instantiates a client. - const retailClient = new SearchServiceClient(); - const IResponseParams = { ISearchResult: 0, ISearchRequest: 1, diff --git a/samples/interactive-tutorials/search/search-with-boost-spec.js b/samples/interactive-tutorials/search/search-with-boost-spec.js index 52db62db..6021635f 100644 --- a/samples/interactive-tutorials/search/search-with-boost-spec.js +++ b/samples/interactive-tutorials/search/search-with-boost-spec.js @@ -22,10 +22,13 @@ async function main() { // Imports the Google Cloud client library. const {SearchServiceClient} = require('@google-cloud/retail'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client + const retailClient = new SearchServiceClient(); + + const projectId = await retailClient.getProjectId(); // Placement is used to identify the Serving Config name. - const placement = `projects/${projectNumber}/locations/global/catalogs/default_catalog/placements/default_search`; + const placement = `projects/${projectId}/locations/global/catalogs/default_catalog/placements/default_search`; // Raw search query. const query = 'Hoodie'; @@ -46,9 +49,6 @@ async function main() { // Maximum number of Products to return. const pageSize = 10; - // Instantiates a client - const retailClient = new SearchServiceClient(); - const IResponseParams = { ISearchResult: 0, ISearchRequest: 1, diff --git a/samples/interactive-tutorials/search/search-with-facet-spec.js b/samples/interactive-tutorials/search/search-with-facet-spec.js index 7205c874..3fcac810 100644 --- a/samples/interactive-tutorials/search/search-with-facet-spec.js +++ b/samples/interactive-tutorials/search/search-with-facet-spec.js @@ -21,10 +21,13 @@ async function main() { // Imports the Google Cloud client library. const {SearchServiceClient} = require('@google-cloud/retail'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new SearchServiceClient(); + + const projectId = await retailClient.getProjectId(); // Placement is used to identify the Serving Config name. - const placement = `projects/${projectNumber}/locations/global/catalogs/default_catalog/placements/default_search`; + const placement = `projects/${projectId}/locations/global/catalogs/default_catalog/placements/default_search`; // Raw search query. const query = 'Tee'; @@ -38,9 +41,6 @@ async function main() { // Maximum number of Products to return. const pageSize = 10; - // Instantiates a client. - const retailClient = new SearchServiceClient(); - const IResponseParams = { ISearchResult: 0, ISearchRequest: 1, diff --git a/samples/interactive-tutorials/search/search-with-filtering.js b/samples/interactive-tutorials/search/search-with-filtering.js index 3147809d..c3d45108 100644 --- a/samples/interactive-tutorials/search/search-with-filtering.js +++ b/samples/interactive-tutorials/search/search-with-filtering.js @@ -21,10 +21,13 @@ async function main() { // Imports the Google Cloud client library. const {SearchServiceClient} = require('@google-cloud/retail'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new SearchServiceClient(); + + const projectId = await retailClient.getProjectId(); // Placement is used to identify the Serving Config name. - const placement = `projects/${projectNumber}/locations/global/catalogs/default_catalog/placements/default_search`; + const placement = `projects/${projectId}/locations/global/catalogs/default_catalog/placements/default_search`; // Raw search query. const query = 'Tee'; @@ -39,9 +42,6 @@ async function main() { // Maximum number of Products to return. const pageSize = 10; - // Instantiates a client. - const retailClient = new SearchServiceClient(); - const IResponseParams = { ISearchResult: 0, ISearchRequest: 1, diff --git a/samples/interactive-tutorials/search/search-with-ordering.js b/samples/interactive-tutorials/search/search-with-ordering.js index af99188f..d179f294 100644 --- a/samples/interactive-tutorials/search/search-with-ordering.js +++ b/samples/interactive-tutorials/search/search-with-ordering.js @@ -21,10 +21,13 @@ async function main() { // Imports the Google Cloud client library. const {SearchServiceClient} = require('@google-cloud/retail'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client + const retailClient = new SearchServiceClient(); + + const projectId = await retailClient.getProjectId(); // Placement is used to identify the Serving Config name. - const placement = `projects/${projectNumber}/locations/global/catalogs/default_catalog/placements/default_search`; + const placement = `projects/${projectId}/locations/global/catalogs/default_catalog/placements/default_search`; // Raw search query. const query = 'Hoodie'; @@ -38,9 +41,6 @@ async function main() { // Maximum number of Products to return. const pageSize = 10; - // Instantiates a client - const retailClient = new SearchServiceClient(); - const IResponseParams = { ISearchResult: 0, ISearchRequest: 1, diff --git a/samples/interactive-tutorials/search/search-with-pagination.js b/samples/interactive-tutorials/search/search-with-pagination.js index 3158f356..7a153302 100644 --- a/samples/interactive-tutorials/search/search-with-pagination.js +++ b/samples/interactive-tutorials/search/search-with-pagination.js @@ -20,10 +20,13 @@ async function main() { // Imports the Google Cloud client library. const {SearchServiceClient} = require('@google-cloud/retail'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new SearchServiceClient(); + + const projectId = await retailClient.getProjectId(); // Placement is used to identify the Serving Config name. - const placement = `projects/${projectNumber}/locations/global/catalogs/default_catalog/placements/default_search`; + const placement = `projects/${projectId}/locations/global/catalogs/default_catalog/placements/default_search`; // Raw search query. const query = 'Hoodie'; @@ -40,9 +43,6 @@ async function main() { //A page token received from a previous search call. let pageToken = ''; - // Instantiates a client. - const retailClient = new SearchServiceClient(); - const IResponseParams = { ISearchResult: 0, ISearchRequest: 1, diff --git a/samples/interactive-tutorials/search/search-with-query-expansion-spec.js b/samples/interactive-tutorials/search/search-with-query-expansion-spec.js index e70387f9..e5bc7d65 100644 --- a/samples/interactive-tutorials/search/search-with-query-expansion-spec.js +++ b/samples/interactive-tutorials/search/search-with-query-expansion-spec.js @@ -20,10 +20,13 @@ async function main() { // Imports the Google Cloud client library. const {SearchServiceClient} = require('@google-cloud/retail'); - const projectNumber = process.env['GCLOUD_PROJECT']; + // Instantiates a client. + const retailClient = new SearchServiceClient(); + + const projectId = await retailClient.getProjectId(); // Placement is used to identify the Serving Config name. - const placement = `projects/${projectNumber}/locations/global/catalogs/default_catalog/placements/default_search`; + const placement = `projects/${projectId}/locations/global/catalogs/default_catalog/placements/default_search`; // Raw search query. const query = 'Google Youth Hero Tee Grey'; @@ -40,9 +43,6 @@ async function main() { //Maximum number of products to return const pageSize = 10; - // Instantiates a client. - const retailClient = new SearchServiceClient(); - const IResponseParams = { ISearchResult: 0, ISearchRequest: 1, diff --git a/samples/interactive-tutorials/setup/setup-cleanup.js b/samples/interactive-tutorials/setup/setup-cleanup.js index a0561c32..4889f429 100644 --- a/samples/interactive-tutorials/setup/setup-cleanup.js +++ b/samples/interactive-tutorials/setup/setup-cleanup.js @@ -280,9 +280,9 @@ const uploadDataToBqTable = async (datasetId, tableId, source, schemaFile) => { }; const writeUserEvent = async visitorId => { - const projectNumber = process.env['GCLOUD_PROJECT']; - const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog`; const retailClient = new UserEventServiceClient(); + const projectId = await retailClient.getProjectId(); + const parent = `projects/${projectId}/locations/global/catalogs/default_catalog`; const userEvent = { eventType: 'detail-page-view', diff --git a/samples/interactive-tutorials/test-resources-setup/create-test-resources.js b/samples/interactive-tutorials/test-resources-setup/create-test-resources.js index dc7e47b5..3baba0a1 100644 --- a/samples/interactive-tutorials/test-resources-setup/create-test-resources.js +++ b/samples/interactive-tutorials/test-resources-setup/create-test-resources.js @@ -18,7 +18,8 @@ async function main() { const {ProductServiceClient} = require('@google-cloud/retail').v2; const utils = require('../setup/setup-cleanup'); - const projectNumber = process.env['GCLOUD_PROJECT']; + const retailClient = new ProductServiceClient(); + const projectId = await retailClient.getProjectId(); const productsBucketName = process.env['BUCKET_NAME']; const eventsBucketName = process.env['EVENTS_BUCKET_NAME']; @@ -37,7 +38,7 @@ async function main() { const productsSourceFile = 'interactive-tutorials/resources/products.json'; const eventsSourceFile = 'interactive-tutorials/resources/user_events.json'; - const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch`; + const parent = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch`; const inputConfig = { gcsSource: { @@ -56,8 +57,6 @@ async function main() { IOperation: 2, }; - const retailClient = new ProductServiceClient(); - const importProducts = async () => { // Construct request const request = { diff --git a/samples/interactive-tutorials/test-resources-setup/remove-test-resources.js b/samples/interactive-tutorials/test-resources-setup/remove-test-resources.js index 614add70..27450449 100644 --- a/samples/interactive-tutorials/test-resources-setup/remove-test-resources.js +++ b/samples/interactive-tutorials/test-resources-setup/remove-test-resources.js @@ -15,9 +15,11 @@ 'use strict'; async function main() { + const {ProductServiceClient} = require('@google-cloud/retail').v2; const utils = require('../setup/setup-cleanup'); - const projectNumber = process.env['GCLOUD_PROJECT']; + const retailClient = new ProductServiceClient(); + const projectId = await retailClient.getProjectId(); const productsBucketName = process.env['BUCKET_NAME']; const eventsBucketName = process.env['EVENTS_BUCKET_NAME']; @@ -25,7 +27,7 @@ async function main() { const productsDataset = 'products'; const eventsDataset = 'user_events'; - const parent = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch`; + const parent = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch`; await utils.deleteBucket(productsBucketName); await utils.deleteBucket(eventsBucketName); diff --git a/samples/interactive-tutorials/test/create-product.test.js b/samples/interactive-tutorials/test/create-product.test.js index 060cdc07..75c263e3 100644 --- a/samples/interactive-tutorials/test/create-product.test.js +++ b/samples/interactive-tutorials/test/create-product.test.js @@ -27,11 +27,14 @@ const cwd = path.join(__dirname, '..'); describe('Create product', () => { const retailClient = new ProductServiceClient(); const productId = Math.random().toString(36).slice(2).toUpperCase(); - const projectNumber = process.env['GCLOUD_PROJECT']; - const name = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch/products/${productId}`; + let projectId; + let name; let stdout; before(async () => { + projectId = await retailClient.getProjectId(); + name = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch/products/${productId}`; + stdout = execSync( `node interactive-tutorials/product/create-product.js ${productId}`, {cwd} diff --git a/samples/interactive-tutorials/test/crud-product.test.js b/samples/interactive-tutorials/test/crud-product.test.js index b7f83bf8..1301aee9 100644 --- a/samples/interactive-tutorials/test/crud-product.test.js +++ b/samples/interactive-tutorials/test/crud-product.test.js @@ -26,25 +26,29 @@ const cwd = path.join(__dirname, '..'); describe('CRUD product', () => { const retailClient = new ProductServiceClient(); const productId = Math.random().toString(36).slice(2).toUpperCase(); - const projectNumber = process.env['GCLOUD_PROJECT']; - const name = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch/products/${productId}`; - const product = { - productId, - name, - title: 'Updated Nest Mini', - type: 'PRIMARY', - categories: ['Updated Speakers and displays'], - brands: ['Updated Google'], - priceInfo: { - price: 20.0, - originalPrice: 25.5, - currencyCode: 'EUR', - }, - availability: 'OUT_OF_STOCK', - }; + let projectId; + let name; + let product; let stdout; before(async () => { + projectId = await retailClient.getProjectId(); + name = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch/products/${productId}`; + product = { + productId, + name, + title: 'Updated Nest Mini', + type: 'PRIMARY', + categories: ['Updated Speakers and displays'], + brands: ['Updated Google'], + priceInfo: { + price: 20.0, + originalPrice: 25.5, + currencyCode: 'EUR', + }, + availability: 'OUT_OF_STOCK', + }; + stdout = execSync( `node interactive-tutorials/product/crud-product.js ${productId}`, {cwd} diff --git a/samples/interactive-tutorials/test/delete-product.test.js b/samples/interactive-tutorials/test/delete-product.test.js index 18b8d9db..77cb4dde 100644 --- a/samples/interactive-tutorials/test/delete-product.test.js +++ b/samples/interactive-tutorials/test/delete-product.test.js @@ -27,11 +27,14 @@ const cwd = path.join(__dirname, '..'); describe('Delete product', () => { const retailClient = new ProductServiceClient(); const productId = Math.random().toString(36).slice(2).toUpperCase(); - const projectNumber = process.env['GCLOUD_PROJECT']; - const name = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch/products/${productId}`; + let projectId; + let name; let stdout; before(async () => { + projectId = await retailClient.getProjectId(); + name = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch/products/${productId}`; + stdout = execSync( `node interactive-tutorials/product/delete-product.js ${productId}`, {cwd} diff --git a/samples/interactive-tutorials/test/get-product.test.js b/samples/interactive-tutorials/test/get-product.test.js index 7898314b..f5673b8d 100644 --- a/samples/interactive-tutorials/test/get-product.test.js +++ b/samples/interactive-tutorials/test/get-product.test.js @@ -26,11 +26,14 @@ const cwd = path.join(__dirname, '..'); describe('Get product', () => { const retailClient = new ProductServiceClient(); const productId = Math.random().toString(36).slice(2).toUpperCase(); - const projectNumber = process.env['GCLOUD_PROJECT']; - const name = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch/products/${productId}`; + let projectId; + let name; let stdout; before(async () => { + projectId = await retailClient.getProjectId(); + name = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch/products/${productId}`; + stdout = execSync( `node interactive-tutorials/product/get-product.js ${productId}`, {cwd} diff --git a/samples/interactive-tutorials/test/import-products-inline-source.test.js b/samples/interactive-tutorials/test/import-products-inline-source.test.js index 319bca5e..44a0ac00 100644 --- a/samples/interactive-tutorials/test/import-products-inline-source.test.js +++ b/samples/interactive-tutorials/test/import-products-inline-source.test.js @@ -26,24 +26,27 @@ const cwd = path.join(__dirname, '..'); describe('Import product from inline source', () => { const retailClient = new ProductServiceClient(); - const projectNumber = process.env['GCLOUD_PROJECT']; const id1 = Math.random().toString(36).slice(2).toUpperCase(); const id2 = Math.random().toString(36).slice(2).toUpperCase(); - const product1 = { - id: id1, - name: `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch/products/${id1}`, - }; - - const product2 = { - id: id2, - name: `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch/products/${id2}`, - }; - + let projectId; + let product1; + let product2; let stdout; before(async () => { + projectId = await retailClient.getProjectId(); + product1 = { + id: id1, + name: `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch/products/${id1}`, + }; + + product2 = { + id: id2, + name: `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch/products/${id2}`, + }; + stdout = execSync( `node interactive-tutorials/product/import-products-inline-source.js ${product1.id} ${product2.id}`, {cwd} diff --git a/samples/interactive-tutorials/test/search-simple-query.test.js b/samples/interactive-tutorials/test/search-simple-query.test.js index ff74a29d..9b54fcb9 100644 --- a/samples/interactive-tutorials/test/search-simple-query.test.js +++ b/samples/interactive-tutorials/test/search-simple-query.test.js @@ -45,13 +45,8 @@ describe('Search simple query', () => { describe('Search simple query sample result', () => { const retailClient = new SearchServiceClient(); - - const projectNumber = process.env['GCLOUD_PROJECT']; - const request = { - placement: `projects/${projectNumber}/locations/global/catalogs/default_catalog/placements/default_search`, - query: 'Hoodie', - visitorId: '12345', - }; + let projectId; + let request; const IResponseParams = { ISearchResult: 0, ISearchRequest: 1, @@ -60,6 +55,12 @@ describe('Search simple query', () => { let response = []; before(async () => { + projectId = await retailClient.getProjectId(); + request = { + placement: `projects/${projectId}/locations/global/catalogs/default_catalog/placements/default_search`, + query: 'Hoodie', + visitorId: '12345', + }; response = await retailClient.search(request, {autoPaginate: false}); }); diff --git a/samples/interactive-tutorials/test/search-with-boost-spec.test.js b/samples/interactive-tutorials/test/search-with-boost-spec.test.js index 54d07dfd..5d741d3b 100644 --- a/samples/interactive-tutorials/test/search-with-boost-spec.test.js +++ b/samples/interactive-tutorials/test/search-with-boost-spec.test.js @@ -45,17 +45,8 @@ describe('Search with boost spec', () => { describe('Search with boost spec sample result', () => { const retailClient = new SearchServiceClient(); - - const projectNumber = process.env['GCLOUD_PROJECT']; - const request = { - placement: `projects/${projectNumber}/locations/global/catalogs/default_catalog/placements/default_search`, - query: 'Hoodie', - visitorId: '12345', - boostSpec: { - condition: '(colorFamilies: ANY("Blue"))', - boost: 0.0, - }, - }; + let projectId; + let request; const IResponseParams = { ISearchResult: 0, ISearchRequest: 1, @@ -64,6 +55,16 @@ describe('Search with boost spec', () => { let response = []; before(async () => { + projectId = await retailClient.getProjectId(); + request = { + placement: `projects/${projectId}/locations/global/catalogs/default_catalog/placements/default_search`, + query: 'Hoodie', + visitorId: '12345', + boostSpec: { + condition: '(colorFamilies: ANY("Blue"))', + boost: 0.0, + }, + }; response = await retailClient.search(request, {autoPaginate: false}); }); diff --git a/samples/interactive-tutorials/test/search-with-facet-spec.test.js b/samples/interactive-tutorials/test/search-with-facet-spec.test.js index 6f79d3fc..fcd80701 100644 --- a/samples/interactive-tutorials/test/search-with-facet-spec.test.js +++ b/samples/interactive-tutorials/test/search-with-facet-spec.test.js @@ -45,14 +45,8 @@ describe('Search with facet spec', () => { describe('Search with facet spec result', () => { const retailClient = new SearchServiceClient(); - const projectNumber = process.env['GCLOUD_PROJECT']; - const request = { - placement: `projects/${projectNumber}/locations/global/catalogs/default_catalog/placements/default_search`, - query: 'Tee', - visitorId: '12345', - facetSpecs: [{facetKey: {key: 'colorFamilies'}}], - pageSize: 10, - }; + let projectId; + let request; const IResponseParams = { ISearchResult: 0, ISearchRequest: 1, @@ -61,6 +55,14 @@ describe('Search with facet spec', () => { let response = []; before(async () => { + projectId = await retailClient.getProjectId(); + request = { + placement: `projects/${projectId}/locations/global/catalogs/default_catalog/placements/default_search`, + query: 'Tee', + visitorId: '12345', + facetSpecs: [{facetKey: {key: 'colorFamilies'}}], + pageSize: 10, + }; response = await retailClient.search(request, {autoPaginate: false}); }); diff --git a/samples/interactive-tutorials/test/search-with-filtering.test.js b/samples/interactive-tutorials/test/search-with-filtering.test.js index 0aaa1b10..850c41c6 100644 --- a/samples/interactive-tutorials/test/search-with-filtering.test.js +++ b/samples/interactive-tutorials/test/search-with-filtering.test.js @@ -45,13 +45,8 @@ describe('Search with filtering', () => { describe('Search with filtering sample result', () => { const retailClient = new SearchServiceClient(); - const projectNumber = process.env['GCLOUD_PROJECT']; - const request = { - placement: `projects/${projectNumber}/locations/global/catalogs/default_catalog/placements/default_search`, - query: 'Tee', - visitorId: '12345', - filter: '(colorFamilies: ANY("Black"))', - }; + let projectId; + let request; const IResponseParams = { ISearchResult: 0, ISearchRequest: 1, @@ -60,6 +55,13 @@ describe('Search with filtering', () => { let response = []; before(async () => { + projectId = await retailClient.getProjectId(); + request = { + placement: `projects/${projectId}/locations/global/catalogs/default_catalog/placements/default_search`, + query: 'Tee', + visitorId: '12345', + filter: '(colorFamilies: ANY("Black"))', + }; response = await retailClient.search(request, {autoPaginate: false}); }); diff --git a/samples/interactive-tutorials/test/search-with-ordering.test.js b/samples/interactive-tutorials/test/search-with-ordering.test.js index 4ddd6f0c..f05e8a49 100644 --- a/samples/interactive-tutorials/test/search-with-ordering.test.js +++ b/samples/interactive-tutorials/test/search-with-ordering.test.js @@ -45,13 +45,8 @@ describe('Search with ordering', () => { describe('Search with ordering sample result', () => { const retailClient = new SearchServiceClient(); - const projectNumber = process.env['GCLOUD_PROJECT']; - const request = { - placement: `projects/${projectNumber}/locations/global/catalogs/default_catalog/placements/default_search`, - query: 'Hoodie', - visitorId: '12345', - orderBy: 'price desc', - }; + let projectId; + let request; const IResponseParams = { ISearchResult: 0, ISearchRequest: 1, @@ -60,6 +55,13 @@ describe('Search with ordering', () => { let response = []; before(async () => { + projectId = await retailClient.getProjectId(); + request = { + placement: `projects/${projectId}/locations/global/catalogs/default_catalog/placements/default_search`, + query: 'Hoodie', + visitorId: '12345', + orderBy: 'price desc', + }; response = await retailClient.search(request, {autoPaginate: false}); }); diff --git a/samples/interactive-tutorials/test/search-with-pagination.test.js b/samples/interactive-tutorials/test/search-with-pagination.test.js index 59c1c242..cb7166ca 100644 --- a/samples/interactive-tutorials/test/search-with-pagination.test.js +++ b/samples/interactive-tutorials/test/search-with-pagination.test.js @@ -49,18 +49,11 @@ describe('Search with pagination', () => { describe('Search with pagination sample result', () => { const retailClient = new SearchServiceClient(); - const projectNumber = process.env['GCLOUD_PROJECT']; + let projectId; const pageSize = 2; const offset = 0; const pageToken = ''; - const request = { - placement: `projects/${projectNumber}/locations/global/catalogs/default_catalog/placements/default_search`, - query: 'Hoodie', - visitorId: '12345', - pageSize, - offset, - pageToken, - }; + let request; let response; const IResponseParams = { @@ -70,6 +63,15 @@ describe('Search with pagination', () => { }; before(async () => { + projectId = await retailClient.getProjectId(); + request = { + placement: `projects/${projectId}/locations/global/catalogs/default_catalog/placements/default_search`, + query: 'Hoodie', + visitorId: '12345', + pageSize, + offset, + pageToken, + }; response = await retailClient.search(request, {autoPaginate: false}); }); diff --git a/samples/interactive-tutorials/test/search-with-query-expansion-spec.test.js b/samples/interactive-tutorials/test/search-with-query-expansion-spec.test.js index 41452350..2446b263 100644 --- a/samples/interactive-tutorials/test/search-with-query-expansion-spec.test.js +++ b/samples/interactive-tutorials/test/search-with-query-expansion-spec.test.js @@ -47,16 +47,8 @@ describe('Search with query expansion spec', () => { describe('Search with query expansion spec sample result', () => { const retailClient = new SearchServiceClient(); - const projectNumber = process.env['GCLOUD_PROJECT']; - const request = { - placement: `projects/${projectNumber}/locations/global/catalogs/default_catalog/placements/default_search`, - query: 'Google Youth Hero Tee Grey', - visitorId: '12345', - queryExpansionSpec: { - condition: 'AUTO', - }, - pageSize: 10, - }; + let projectId; + let request; const IResponseParams = { ISearchResult: 0, ISearchRequest: 1, @@ -65,6 +57,16 @@ describe('Search with query expansion spec', () => { let response = []; before(async () => { + projectId = await retailClient.getProjectId(); + request = { + placement: `projects/${projectId}/locations/global/catalogs/default_catalog/placements/default_search`, + query: 'Google Youth Hero Tee Grey', + visitorId: '12345', + queryExpansionSpec: { + condition: 'AUTO', + }, + pageSize: 10, + }; response = await retailClient.search(request, {autoPaginate: false}); }); diff --git a/samples/interactive-tutorials/test/update-product.test.js b/samples/interactive-tutorials/test/update-product.test.js index 0f50ff29..9035ccaf 100644 --- a/samples/interactive-tutorials/test/update-product.test.js +++ b/samples/interactive-tutorials/test/update-product.test.js @@ -27,25 +27,29 @@ const cwd = path.join(__dirname, '..'); describe('Update product', () => { const retailClient = new ProductServiceClient(); const productId = Math.random().toString(36).slice(2).toUpperCase(); - const projectNumber = process.env['GCLOUD_PROJECT']; - const name = `projects/${projectNumber}/locations/global/catalogs/default_catalog/branches/default_branch/products/${productId}`; - const product = { - productId, - name, - title: 'Updated Nest Mini', - type: 'PRIMARY', - categories: ['Updated Speakers and displays'], - brands: ['Updated Google'], - priceInfo: { - price: 20.0, - originalPrice: 25.5, - currencyCode: 'EUR', - }, - availability: 'OUT_OF_STOCK', - }; + let projectId; + let name; + let product; let stdout; before(async () => { + projectId = await retailClient.getProjectId(); + name = `projects/${projectId}/locations/global/catalogs/default_catalog/branches/default_branch/products/${productId}`; + product = { + productId, + name, + title: 'Updated Nest Mini', + type: 'PRIMARY', + categories: ['Updated Speakers and displays'], + brands: ['Updated Google'], + priceInfo: { + price: 20.0, + originalPrice: 25.5, + currencyCode: 'EUR', + }, + availability: 'OUT_OF_STOCK', + }; + stdout = execSync( `node interactive-tutorials/product/update-product.js ${productId}`, {cwd}