Skip to content
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

migrate code from googleapis/nodejs-retail #2975

Merged
merged 55 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
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 Jan 12, 2021
11ec988
feat: add initial samples (#2)
sofisl Jan 13, 2021
984e0c9
chore: release 1.0.0 (#1)
release-please[bot] Jan 13, 2021
e09d588
chore: release 1.1.0 (#19)
release-please[bot] Mar 2, 2021
4808c12
chore: release 1.1.1 (#48)
release-please[bot] May 13, 2021
082d319
chore: release 1.1.2 (#56)
release-please[bot] May 25, 2021
7bebc1a
chore: release 1.1.3 (#63)
release-please[bot] Jun 25, 2021
edae10b
chore: release 1.1.4 (#68)
release-please[bot] Jul 1, 2021
0e177cc
chore: release 1.1.5 (#70)
release-please[bot] Jul 13, 2021
cf66bc7
chore: release 1.1.6 (#74)
release-please[bot] Jul 16, 2021
c7c8192
chore: release 1.2.0 (#80)
release-please[bot] Aug 2, 2021
acc003d
chore: release 1.2.1 (#92)
release-please[bot] Aug 17, 2021
9f8d53f
chore: release 1.2.2 (#99)
release-please[bot] Sep 10, 2021
3a85df7
chore: release 1.3.0 (#108)
release-please[bot] Oct 19, 2021
b1f9455
chore: release 1.4.0 (#113)
release-please[bot] Nov 4, 2021
c3e2574
chore: release 1.5.0 (#118)
release-please[bot] Nov 29, 2021
86aca25
test: create/delete test resources scripts (#145)
nmykhailets Feb 15, 2022
432c6f0
chore(main): release 1.6.0 (#141)
release-please[bot] Feb 15, 2022
1173bb0
samples: interactive tutorials code samples for search service (#146)
nmykhailets Feb 25, 2022
27428ad
chore(samples): interactive tutorials code samples for import product…
nmykhailets Mar 8, 2022
eca0809
chore(samples): interactive tutorials code samples for write/rejoin/p…
nmykhailets Mar 8, 2022
c70edc6
chore(samples): interactive tutorials code samples for CRUD products …
nmykhailets Mar 8, 2022
d34d524
chore(samples): interactive tutorials code samples for import user ev…
nmykhailets Mar 14, 2022
e29a2ed
fix: remove gcloud_project env variable (#156)
nmykhailets Mar 15, 2022
a705ca4
chore(main): release 1.6.1 (#158)
release-please[bot] Mar 23, 2022
c20eab5
chore(main): release 1.7.0 (#161)
release-please[bot] Apr 4, 2022
5f6e987
feat: Retail Tutorials. If create BQ table is requested, check if it …
t-karasova Apr 8, 2022
72b74c7
chore(main): release 1.8.0 (#168)
release-please[bot] Apr 11, 2022
d0e6d70
fix: read projectId from retailClient.getProjectId (#159)
t-karasova Apr 13, 2022
df7df12
small fix in the script (#173)
t-karasova Apr 21, 2022
a7caa4c
chore(main): release 1.8.1 (#170)
release-please[bot] May 6, 2022
5a6188e
build!: update library to use Node 12 (#181)
sofisl May 20, 2022
c338968
fix(deps): update dependency @google-cloud/bigquery to v6 (#186)
renovate-bot Jun 20, 2022
5efdd94
chore(main): release 2.0.0 (#184)
release-please[bot] Jun 30, 2022
b63bd7a
fix(deps): update dependency @google-cloud/storage to v6 (#185)
renovate-bot Jul 4, 2022
6fcb5c4
samples: bugfix-GRST-147-warn-user-about-fails-on-bucket-creation (#195)
Arakel2811 Jul 28, 2022
753cc1f
samples: fixed number of failures during importing. (#198)
Arakel2811 Jul 29, 2022
82ecff4
samples: properly catch errors (#197)
Arakel2811 Aug 2, 2022
2bea977
samples: corrected eventTime update. (#200)
Arakel2811 Aug 2, 2022
bf2e326
samples: removed bigquery.admin from {retail.admin,editor,bigquery.ad…
Arakel2811 Aug 23, 2022
7db53cb
samples: GRST-149 set inventory tutorial add created product detailed…
Arakel2811 Aug 23, 2022
98849be
GRST 159 warn user about fails on user environment setup.sh (#201)
Arakel2811 Aug 24, 2022
73550e0
samples: long running operations - removed delays, added correct logi…
Arakel2811 Sep 9, 2022
a3e4a55
samples: remove unused region tags (#212)
Arakel2811 Sep 16, 2022
436240e
samples(tests): removed unused times. (#211)
Arakel2811 Sep 16, 2022
49533bb
samples: environment setup twice error. (#213)
Arakel2811 Sep 16, 2022
aaec045
samples: improved massage in case of an empty search result (#214)
Arakel2811 Sep 20, 2022
c09774d
feat: Model Services, BatchRemoveCatalogAttributes, ExactSearchableOp…
gcf-owl-bot[bot] Sep 20, 2022
73c064b
chore(main): release 2.1.0 (#193)
release-please[bot] Sep 20, 2022
439ee1f
samples: moved console.log placements in add/remove fulfillment and s…
Arakel2811 Sep 23, 2022
f032a03
samples: removed region tags from events and search directories (#216)
Arakel2811 Sep 26, 2022
99ebfb0
chore(main): release 2.1.1 (#225)
release-please[bot] Nov 16, 2022
ad0fec5
Merge remote-tracking branch 'migration/main' into nodejs-retail-migr…
kweinmeister Jan 11, 2023
7997894
add tests and CODEOWNERS update
kweinmeister Jan 11, 2023
56d04e6
add auto-label entry
kweinmeister Jan 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/auto-label.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ path:
mediatranslation: "mediatranslation"
memorystore: "memorystore"
monitoring: "monitoring"
retail: "retail"
run: "run"
scheduler: "cloudscheduler"
secret-manager: "secretmanager"
Expand Down
Empty file modified .github/workflows/generate.js
100644 → 100755
Empty file.
71 changes: 71 additions & 0 deletions .github/workflows/retail.yaml
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}}
1 change: 1 addition & 0 deletions .github/workflows/workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"monitoring/opencensus",
"monitoring/prometheus",
"monitoring/snippets",
"retail",
"scheduler",
"security-center/snippets",
"service-directory/snippets",
Expand Down
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ texttospeech @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-sample
translate @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
video-intelligence @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
vision @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers

# Self-service
retail @GoogleCloudPlatform/cloud-retail-team @GoogleCloudPlatform/nodejs-samples-reviewers
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

5 changes: 5 additions & 0 deletions retail/.mocharc.json
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"]
}
64 changes: 64 additions & 0 deletions retail/interactive-tutorials/README.md
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
```
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 retail/interactive-tutorials/events/import-user-events-gcs.js
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']];
})()
);
Loading