- Notifications
You must be signed in to change notification settings - Fork 2k
migrate code from googleapis/nodejs-retail #2975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
55 commits Select commit Hold shift + click to select a range
d699018 feat!: initial stub of library
sofisl 11ec988 feat: add initial samples (#2)
sofisl 984e0c9 chore: release 1.0.0 (#1)
release-please[bot] e09d588 chore: release 1.1.0 (#19)
release-please[bot] 4808c12 chore: release 1.1.1 (#48)
release-please[bot] 082d319 chore: release 1.1.2 (#56)
release-please[bot] 7bebc1a chore: release 1.1.3 (#63)
release-please[bot] edae10b chore: release 1.1.4 (#68)
release-please[bot] 0e177cc chore: release 1.1.5 (#70)
release-please[bot] cf66bc7 chore: release 1.1.6 (#74)
release-please[bot] c7c8192 chore: release 1.2.0 (#80)
release-please[bot] acc003d chore: release 1.2.1 (#92)
release-please[bot] 9f8d53f chore: release 1.2.2 (#99)
release-please[bot] 3a85df7 chore: release 1.3.0 (#108)
release-please[bot] b1f9455 chore: release 1.4.0 (#113)
release-please[bot] c3e2574 chore: release 1.5.0 (#118)
release-please[bot] 86aca25 test: create/delete test resources scripts (#145)
nmykhailets 432c6f0 chore(main): release 1.6.0 (#141)
release-please[bot] 1173bb0 samples: interactive tutorials code samples for search service (#146)
nmykhailets 27428ad chore(samples): interactive tutorials code samples for import product…
nmykhailets eca0809 chore(samples): interactive tutorials code samples for write/rejoin/p…
nmykhailets c70edc6 chore(samples): interactive tutorials code samples for CRUD products …
nmykhailets d34d524 chore(samples): interactive tutorials code samples for import user ev…
nmykhailets e29a2ed fix: remove gcloud_project env variable (#156)
nmykhailets a705ca4 chore(main): release 1.6.1 (#158)
release-please[bot] c20eab5 chore(main): release 1.7.0 (#161)
release-please[bot] 5f6e987 feat: Retail Tutorials. If create BQ table is requested, check if it …
t-karasova 72b74c7 chore(main): release 1.8.0 (#168)
release-please[bot] d0e6d70 fix: read projectId from retailClient.getProjectId (#159)
t-karasova df7df12 small fix in the script (#173)
t-karasova a7caa4c chore(main): release 1.8.1 (#170)
release-please[bot] 5a6188e build!: update library to use Node 12 (#181)
sofisl c338968 fix(deps): update dependency @google-cloud/bigquery to v6 (#186)
renovate-bot 5efdd94 chore(main): release 2.0.0 (#184)
release-please[bot] b63bd7a fix(deps): update dependency @google-cloud/storage to v6 (#185)
renovate-bot 6fcb5c4 samples: bugfix-GRST-147-warn-user-about-fails-on-bucket-creation (#195)
Arakel2811 753cc1f samples: fixed number of failures during importing. (#198)
Arakel2811 82ecff4 samples: properly catch errors (#197)
Arakel2811 2bea977 samples: corrected eventTime update. (#200)
Arakel2811 bf2e326 samples: removed bigquery.admin from {retail.admin,editor,bigquery.ad…
Arakel2811 7db53cb samples: GRST-149 set inventory tutorial add created product detailed…
Arakel2811 98849be GRST 159 warn user about fails on user environment setup.sh (#201)
Arakel2811 73550e0 samples: long running operations - removed delays, added correct logi…
Arakel2811 a3e4a55 samples: remove unused region tags (#212)
Arakel2811 436240e samples(tests): removed unused times. (#211)
Arakel2811 49533bb samples: environment setup twice error. (#213)
Arakel2811 aaec045 samples: improved massage in case of an empty search result (#214)
Arakel2811 c09774d feat: Model Services, BatchRemoveCatalogAttributes, ExactSearchableOp…
gcf-owl-bot[bot] 73c064b chore(main): release 2.1.0 (#193)
release-please[bot] 439ee1f samples: moved console.log placements in add/remove fulfillment and s…
Arakel2811 f032a03 samples: removed region tags from events and search directories (#216)
Arakel2811 99ebfb0 chore(main): release 2.1.1 (#225)
release-please[bot] ad0fec5 Merge remote-tracking branch 'migration/main' into nodejs-retail-migr…
kweinmeister 7997894 add tests and CODEOWNERS update
kweinmeister 56d04e6 add auto-label entry
kweinmeister File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| name: retail | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'retail/**' | ||
| - '.github/workflows/retail.yaml' | ||
| pull_request: | ||
| paths: | ||
| - 'retail/**' | ||
| - '.github/workflows/retail.yaml' | ||
| pull_request_target: | ||
| types: [labeled] | ||
| paths: | ||
| - 'retail/**' | ||
| - '.github/workflows/retail.yaml' | ||
| schedule: | ||
| - cron: '0 0 * * 0' | ||
| jobs: | ||
| test: | ||
| if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }} | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 60 | ||
| permissions: | ||
| contents: 'write' | ||
| pull-requests: 'write' | ||
| id-token: 'write' | ||
| steps: | ||
| - uses: actions/checkout@v3.1.0 | ||
| with: | ||
| ref: ${{github.event.pull_request.head.sha}} | ||
| - uses: 'google-github-actions/auth@v1.0.0' | ||
| with: | ||
| workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider' | ||
| service_account: 'kokoro-system-test@long-door-651.iam.gserviceaccount.com' | ||
| create_credentials_file: 'true' | ||
| access_token_lifetime: 600s | ||
| - uses: actions/setup-node@v3.5.1 | ||
| with: | ||
| node-version: 16 | ||
| - run: npm install | ||
| working-directory: retail | ||
| - run: npm test | ||
| working-directory: retail | ||
| env: | ||
| MOCHA_REPORTER_SUITENAME: retail | ||
| MOCHA_REPORTER_OUTPUT: retail_sponge_log.xml | ||
| MOCHA_REPORTER: xunit | ||
| - if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }} | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| try { | ||
| await github.rest.issues.removeLabel({ | ||
| name: 'actions:force-run', | ||
| owner: 'GoogleCloudPlatform', | ||
| repo: 'nodejs-docs-samples', | ||
| issue_number: context.payload.pull_request.number | ||
| }); | ||
| } catch (e) { | ||
| if (!e.message.includes('Label does not exist')) { | ||
| throw e; | ||
| } | ||
| } | ||
| - if: ${{ github.event_name == 'schedule' && always() }} | ||
| run: | | ||
| curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L | ||
| chmod +x ./flakybot | ||
| ./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "timeout": "600000", | ||
| "recursive": true, | ||
| "spec": ["test/*.js", "interactive-tutorials/test/*.js"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| | ||
| ## Get started with Google Cloud Retail | ||
| | ||
| ### Select your project and enable the Retail API | ||
| | ||
| Google Cloud organizes resources into projects. This lets you | ||
| collect all the related resources for a single application in one place. | ||
| | ||
| If you don't have a Google Cloud project yet or you're not the Owner of an existing one, you can | ||
| [create a new project](https://console.cloud.google.com/projectcreate). | ||
| | ||
| After the project is created, set your PROJECT_ID to a ```project``` variable. | ||
| 1. Run the following command in Terminal: | ||
| ```bash | ||
| gcloud config set project <YOUR_PROJECT_ID> | ||
| ``` | ||
| | ||
| 1. Check that the Retail API is enabled for your Project in the [Admin Console](https://console.cloud.google.com/ai/retail/). | ||
| | ||
| ### Set up authentication | ||
| | ||
| To run a code sample from the Cloud Shell, you need to authenticate. To do this, use the Application Default Credentials. | ||
| | ||
| 1. Set your user credentials to authenticate your requests to the Retail API | ||
| | ||
| ```bash | ||
| gcloud auth application-default login | ||
| ``` | ||
| | ||
| 1. Type `Y` and press **Enter**. Click the link in Terminal. A browser window should appear asking you to log in using your Google account. | ||
| | ||
| 1. Provide the Google Auth Library with access to your credentials and paste the code from the browser to the Terminal. | ||
| | ||
| 1. Run the code sample and check the Retail API in action. | ||
| | ||
| **Note**: Click the copy button on the side of the code box to paste the command in the Cloud Shell terminal and run it. | ||
| | ||
| ### Set the GCLOUD_PROJECT environment variable | ||
| | ||
| Because you are going to run the code samples in your own Google Cloud project, you should specify the **project_number** as an environment variable. It will be used in every request to the Retail API. | ||
| | ||
| 1. You can find the ```project_number``` in the **Home/Dashboard/Project Info card**. | ||
| | ||
| 1. Set the environment variable with the following command: | ||
| ```bash | ||
| export GCLOUD_PROJECT=<YOUR_GCLOUD_PROJECT> | ||
| ``` | ||
| | ||
| ### Install Google Cloud Retail libraries | ||
| | ||
| To install all the dependencies, run | ||
| | ||
| ``` | ||
| cd cloudshell_open/nodejs-retail | ||
| npm install | ||
| ``` | ||
| | ||
| ### Running the code samples | ||
| Samples are in the `search/`, `products/`, `events/` directories. | ||
| To execute an individual code sample, invoke `node` with a file as a parameter at the command line prompt, e.g.: | ||
| | ||
| ``` | ||
| node search/search-simple-query.js | ||
| ``` |
84 changes: 84 additions & 0 deletions 84 retail/interactive-tutorials/events/import-user-events-big-query.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // Copyright 2022 Google Inc. All Rights Reserved. | ||
| // | ||
| // 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 | ||
| // | ||
| // http://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. | ||
| | ||
| 'use strict'; | ||
| | ||
| async function main(datasetId) { | ||
| // Imports the Google Cloud client library. | ||
| const {UserEventServiceClient} = require('@google-cloud/retail').v2; | ||
| | ||
| // Instantiates a client. | ||
| const retailClient = new UserEventServiceClient(); | ||
| | ||
| const projectId = await retailClient.getProjectId(); | ||
| const dataSchema = 'user_event'; | ||
| const tableId = 'events'; // TO CHECK ERROR HANDLING USE THE TABLE OF INVALID USER EVENTS | ||
| | ||
| // Placement | ||
| const parent = `projects/${projectId}/locations/global/catalogs/default_catalog`; // TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE | ||
| | ||
| // The desired input location of the data. | ||
| const inputConfig = { | ||
| bigQuerySource: { | ||
| projectId, | ||
| datasetId, | ||
| tableId, | ||
| dataSchema, | ||
| }, | ||
| }; | ||
| | ||
| const IResponseParams = { | ||
| IImportUserEventsResponse: 0, | ||
| IImportMetadata: 1, | ||
| IOperation: 2, | ||
| }; | ||
| | ||
| const callImportUserEvents = async () => { | ||
| // Construct request | ||
| const request = { | ||
| parent, | ||
| inputConfig, | ||
| }; | ||
| | ||
| console.log('Import request: ', request); | ||
| | ||
| // Run request | ||
| const [operation] = await retailClient.importUserEvents(request); | ||
| const response = await operation.promise(); | ||
| const result = response[IResponseParams.IImportMetadata]; | ||
| console.log( | ||
| `Number of successfully imported events: ${result.successCount | 0}` | ||
| ); | ||
| console.log( | ||
| `Number of failures during the importing: ${result.failureCount | 0}` | ||
| ); | ||
| console.log(`Operation result: ${JSON.stringify(response)}`); | ||
| }; | ||
| | ||
| console.log('Start events import'); | ||
| await callImportUserEvents(); | ||
| console.log('Events import finished'); | ||
| } | ||
| | ||
| process.on('unhandledRejection', err => { | ||
| console.error(err.message); | ||
| process.exitCode = 1; | ||
| }); | ||
| | ||
| main( | ||
| ...(() => { | ||
| const argv = process.argv.slice(2); | ||
| return argv.length ? argv : ['user_events']; | ||
| })() | ||
| ); |
91 changes: 91 additions & 0 deletions 91 retail/interactive-tutorials/events/import-user-events-gcs.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Copyright 2022 Google Inc. All Rights Reserved. | ||
| // | ||
| // 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 | ||
| // | ||
| // http://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. | ||
| | ||
| 'use strict'; | ||
| | ||
| async function main(bucketName) { | ||
| // Imports the Google Cloud client library. | ||
| const {UserEventServiceClient} = require('@google-cloud/retail').v2; | ||
| | ||
| // Instantiates a client. | ||
| const retailClient = new UserEventServiceClient(); | ||
| | ||
| const projectId = await retailClient.getProjectId(); | ||
| | ||
| //TODO(developer) set the environment variable value which will be used as the bucket name | ||
| const gcsBucket = `gs://${bucketName}`; | ||
| const gcsErrorsBucket = `gs://${bucketName}/error`; | ||
| const gcsEventsObject = 'user_events.json'; // TO CHECK ERROR HANDLING USE THE JSON WITH INVALID USER EVENTS | ||
| | ||
| // Placement | ||
| const parent = `projects/${projectId}/locations/global/catalogs/default_catalog`; // TO CHECK ERROR HANDLING PASTE THE INVALID CATALOG NAME HERE | ||
| | ||
| // The desired input location of the data. | ||
| const inputConfig = { | ||
| gcsSource: { | ||
| inputUris: [gcsBucket + '/' + gcsEventsObject], | ||
| dataSchema: 'user_event', | ||
| }, | ||
| }; | ||
| | ||
| // The desired location of errors incurred during the Import. | ||
| const errorsConfig = { | ||
| gcsPrefix: gcsErrorsBucket, | ||
| }; | ||
| | ||
| const IResponseParams = { | ||
| IImportUserEventsResponse: 0, | ||
| IImportMetadata: 1, | ||
| IOperation: 2, | ||
| }; | ||
| | ||
| const callImportUserEvents = async () => { | ||
| // Construct request | ||
| const request = { | ||
| parent, | ||
| inputConfig, | ||
| errorsConfig, | ||
| }; | ||
| | ||
| console.log('Import request: ', request); | ||
| | ||
| // Run request | ||
| const [operation] = await retailClient.importUserEvents(request); | ||
| const response = await operation.promise(); | ||
| const result = response[IResponseParams.IImportMetadata]; | ||
| console.log( | ||
| `Number of successfully imported events: ${result.successCount | 0}` | ||
| ); | ||
| console.log( | ||
| `Number of failures during the importing: ${result.failureCount | 0}` | ||
| ); | ||
| console.log(`Operation result: ${JSON.stringify(response)}`); | ||
| }; | ||
| | ||
| console.log('Start events import'); | ||
| await callImportUserEvents(); | ||
| console.log('Events import finished'); | ||
| } | ||
| | ||
| process.on('unhandledRejection', err => { | ||
| console.error(err.message); | ||
| process.exitCode = 1; | ||
| }); | ||
| | ||
| main( | ||
| ...(() => { | ||
| const argv = process.argv.slice(2); | ||
| return argv.length ? argv : [process.env['EVENTS_BUCKET_NAME']]; | ||
| })() | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kweinmeister I presume you're intending to create this GitHub team?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It already exists, we're good to go.