Skip to content

Commit 2a3551a

Browse files
authored
Merge branch 'main' into header-checker-missing
2 parents 5c66d13 + 3a7ad1c commit 2a3551a

73 files changed

Lines changed: 10103 additions & 37 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

healthcare/fhir/getFhirResource.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const main = (
2929
auth: new google.auth.GoogleAuth({
3030
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
3131
}),
32+
responseType: 'json',
3233
});
3334

3435
const getFhirResource = async () => {
@@ -42,11 +43,18 @@ const main = (
4243
const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/${resourceType}/${resourceId}`;
4344
const request = {name};
4445

45-
const resource =
46-
await healthcare.projects.locations.datasets.fhirStores.fhir.read(
47-
request
46+
try {
47+
const resource =
48+
await healthcare.projects.locations.datasets.fhirStores.fhir.read(
49+
request
50+
);
51+
console.log(`Got ${resourceType} resource:\n`, resource.data);
52+
} catch (error) {
53+
console.error(
54+
`Error getting ${resourceType} resource:`,
55+
error.message || error
4856
);
49-
console.log(`Got ${resourceType} resource:\n`, resource.data);
57+
}
5058
};
5159

5260
getFhirResource();

healthcare/fhir/importFhirResources.js

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const main = (
2828
auth: new google.auth.GoogleAuth({
2929
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
3030
}),
31+
responseType: 'json',
3132
});
3233
const sleep = ms => {
3334
return new Promise(resolve => setTimeout(resolve, ms));
@@ -50,32 +51,48 @@ const main = (
5051
},
5152
},
5253
};
54+
try {
55+
const operation =
56+
await healthcare.projects.locations.datasets.fhirStores.import(request);
57+
const operationName = operation.data.name;
5358

54-
const operation =
55-
await healthcare.projects.locations.datasets.fhirStores.import(request);
56-
const operationName = operation.data.name;
59+
console.log(`Import operation started: ${operationName}`);
5760

58-
const operationRequest = {name: operationName};
61+
let done = false;
62+
let operationStatus;
63+
let attempts = 0;
5964

60-
// Wait twenty seconds for the LRO to finish.
61-
await sleep(20000);
65+
while (!done && attempts < 100) {
66+
console.log('Waiting for import operation to complete...');
67+
attempts++;
68+
await sleep(5000); // Wait 5 seconds between polls
6269

63-
// Check the LRO's status
64-
const operationStatus =
65-
await healthcare.projects.locations.datasets.operations.get(
66-
operationRequest
67-
);
70+
operationStatus =
71+
await healthcare.projects.locations.datasets.operations.get({
72+
name: operationName,
73+
});
6874

69-
const success = operationStatus.data.metadata.counter.success;
75+
done = operationStatus.data.done;
76+
}
7077

71-
if (typeof success !== 'undefined') {
72-
console.log(
73-
`Import FHIR resources succeeded. ${success} resources imported.`
74-
);
75-
} else {
76-
console.log(
77-
'Imported FHIR resources failed. Details available in Cloud Logging at the following URL:\n',
78-
operationStatus.data.metadata.logsUrl
78+
if (operationStatus.data.error) {
79+
console.error(
80+
'Import FHIR resources failed:',
81+
operationStatus.data.error
82+
);
83+
} else if (done) {
84+
const successCount =
85+
operationStatus.data.metadata?.counter?.success || 0;
86+
console.log(
87+
`Import FHIR resources succeeded. ${successCount} resources imported.`
88+
);
89+
} else {
90+
console.error('Import operation timed out in the sample.');
91+
}
92+
} catch (error) {
93+
console.error(
94+
'An error occurred during the import process:',
95+
error.message || error
7996
);
8097
}
8198
};

healthcare/fhir/listFhirStores.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const main = (
2626
auth: new google.auth.GoogleAuth({
2727
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
2828
}),
29+
responseType: 'json',
2930
});
3031

3132
const listFhirStores = async () => {
@@ -36,9 +37,13 @@ const main = (
3637
const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;
3738
const request = {parent};
3839

39-
const fhirStores =
40-
await healthcare.projects.locations.datasets.fhirStores.list(request);
41-
console.log(JSON.stringify(fhirStores.data));
40+
try {
41+
const fhirStores =
42+
await healthcare.projects.locations.datasets.fhirStores.list(request);
43+
console.log(JSON.stringify(fhirStores.data));
44+
} catch (error) {
45+
console.error('Error listing FHIR stores:', error.message || error);
46+
}
4247
};
4348

4449
listFhirStores();

healthcare/fhir/updateFhirResource.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const main = (
3030
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
3131
}),
3232
headers: {'Content-Type': 'application/fhir+json'},
33+
responseType: 'json',
3334
});
3435

3536
const updateFhirResource = async () => {
@@ -47,11 +48,18 @@ const main = (
4748
const body = {resourceType: resourceType, id: resourceId, active: true};
4849
const request = {name, requestBody: body};
4950

50-
const resource =
51-
await healthcare.projects.locations.datasets.fhirStores.fhir.update(
52-
request
51+
try {
52+
const resource =
53+
await healthcare.projects.locations.datasets.fhirStores.fhir.update(
54+
request
55+
);
56+
console.log(`Updated ${resourceType} resource:\n`, resource.data);
57+
} catch (error) {
58+
console.error(
59+
`Error updating ${resourceType} resource:`,
60+
error.message || error
5361
);
54-
console.log(`Updated ${resourceType} resource:\n`, resource.data);
62+
}
5563
};
5664

5765
updateFhirResource();

recaptcha_enterprise/demosite/app/controllers/controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Label = {
3232
// Parse config file and read available reCAPTCHA actions. All reCAPTCHA actions registered in the client
3333
// should be mapped in the config file. This will be used to verify if the token obtained during assessment
3434
// corresponds to the claimed action.
35-
const propertiesReader = require('properties-reader');
35+
const {propertiesReader} = require('properties-reader');
3636
const PROPERTIES = propertiesReader('config.properties');
3737

3838
const context = {

recaptcha_enterprise/demosite/app/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"license": "Apache-2.0",
66
"author": "Google Inc.",
77
"scripts": {
8+
"start": "node index.js",
89
"test": "echo \"Error: no test specified\" && exit 1"
910
},
1011
"engines": {
@@ -16,10 +17,10 @@
1617
"url": "https://github.com/googleapis/google-cloud-node.git"
1718
},
1819
"dependencies": {
19-
"@google-cloud/recaptcha-enterprise": "^5.5.0",
20-
"body-parser": "^1.20.0",
21-
"express": "^4.18.1",
20+
"@google-cloud/recaptcha-enterprise": "^6.4.0",
21+
"body-parser": "^2.2.2",
22+
"express": "^5.2.1",
2223
"mustache-express": "^1.3.2",
23-
"properties-reader": "^2.2.0"
24+
"properties-reader": "^3.0.1"
2425
}
25-
}
26+
}

spanner/batch-write.js

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
// sample-metadata:
17+
// title: Batch Write
18+
// usage: node batch-write.js <INSTANCE_ID> <DATABASE_ID> <PROJECT_ID>
19+
20+
'use strict';
21+
22+
async function main(
23+
instanceId = 'my-instance',
24+
databaseId = 'my-database',
25+
projectId = 'my-project-id'
26+
) {
27+
// [START spanner_batch_write_at_least_once]
28+
29+
// Imports the Google Cloud client library
30+
const {Spanner, MutationGroup} = require('@google-cloud/spanner');
31+
32+
/**
33+
* TODO(developer): Uncomment the following lines before running the sample.
34+
*/
35+
// const instanceId = 'my-instance';
36+
// const databaseId = 'my-database';
37+
// const projectId = 'my-project-id';
38+
39+
// Creates a client
40+
const spanner = new Spanner({
41+
projectId: projectId,
42+
});
43+
44+
// Gets a reference to a Cloud Spanner instance and database
45+
const instance = spanner.instance(instanceId);
46+
const database = instance.database(databaseId);
47+
48+
// Create Mutation Groups
49+
/**
50+
* Related mutations should be placed in a group, such as insert mutations for both a parent and a child row.
51+
* A group must contain related mutations.
52+
* Please see {@link https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.BatchWriteRequest.MutationGroup}
53+
* for more details and examples.
54+
*/
55+
const mutationGroup1 = new MutationGroup();
56+
mutationGroup1.insert('Singers', {
57+
SingerId: 1,
58+
FirstName: 'Scarlet',
59+
LastName: 'Terry',
60+
});
61+
62+
const mutationGroup2 = new MutationGroup();
63+
mutationGroup2.insert('Singers', {
64+
SingerId: 2,
65+
FirstName: 'Marc',
66+
});
67+
mutationGroup2.insert('Singers', {
68+
SingerId: 3,
69+
FirstName: 'Catalina',
70+
LastName: 'Smith',
71+
});
72+
mutationGroup2.insert('Albums', {
73+
AlbumId: 1,
74+
SingerId: 2,
75+
AlbumTitle: 'Total Junk',
76+
});
77+
mutationGroup2.insert('Albums', {
78+
AlbumId: 2,
79+
SingerId: 3,
80+
AlbumTitle: 'Go, Go, Go',
81+
});
82+
83+
const options = {
84+
transactionTag: 'batch-write-tag',
85+
};
86+
87+
try {
88+
await new Promise((resolve, reject) => {
89+
database
90+
.batchWriteAtLeastOnce([mutationGroup1, mutationGroup2], options)
91+
.on('error', err => {
92+
reject(err);
93+
})
94+
.on('data', response => {
95+
// Check the response code of each response to determine whether the mutation group(s) were applied successfully.
96+
if (response.status.code === 0) {
97+
console.log(
98+
`Mutation group indexes ${
99+
response.indexes
100+
}, have been applied with commit timestamp ${Spanner.timestamp(
101+
response.commitTimestamp
102+
).toJSON()}`
103+
);
104+
}
105+
// Mutation groups that fail to commit trigger a response with a non-zero status code.
106+
else {
107+
console.log(
108+
`Mutation group indexes ${response.indexes}, could not be applied with error code ${response.status.code}, and error message ${response.status.message}`
109+
);
110+
}
111+
})
112+
.on('end', () => {
113+
console.log('Request completed successfully');
114+
resolve();
115+
});
116+
});
117+
} catch (err) {
118+
console.log(err);
119+
} finally {
120+
await database.close();
121+
}
122+
// [END spanner_batch_write_at_least_once]
123+
}
124+
125+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)