Skip to content

Commit ba51a96

Browse files
fix(adminSDK): resolve type errors
Resolved TypeScript type errors in the adminSDK directory by adding JSDoc annotations and null checks.
1 parent 275a497 commit ba51a96

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

adminSDK/directory/quickstart.gs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ function listUsers() {
2525
orderBy: 'email'
2626
};
2727
try {
28+
if (!AdminDirectory || !AdminDirectory.Users) {
29+
throw new Error('Enable the AdminDirectory Advanced Service.');
30+
}
2831
const response = AdminDirectory.Users.list(optionalArgs);
2932
const users = response.users;
3033
if (!users || users.length === 0) {
@@ -34,11 +37,15 @@ function listUsers() {
3437
// Print the list of user's full name and email
3538
console.log('Users:');
3639
for (const user of users) {
37-
console.log('%s (%s)', user.primaryEmail, user.name.fullName);
40+
if (user.name) {
41+
console.log('%s (%s)', user.primaryEmail, user.name.fullName);
42+
} else {
43+
console.log('%s', user.primaryEmail);
44+
}
3845
}
3946
} catch (err) {
4047
// TODO (developer)- Handle exception from the Directory API
41-
console.log('Failed with error %s', err.message);
48+
console.log('Failed with error %s', /** @type {Error} */ (err).message);
4249
}
4350
}
4451
// [END admin_sdk_directory_quickstart]

adminSDK/reports/quickstart.gs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ function listLogins() {
2525
maxResults: 10
2626
};
2727
try {
28-
const response = AdminReports.Activities.list(userKey, applicationName, optionalArgs);
28+
if (!AdminReports || !AdminReports.Activities) {
29+
throw new Error('Enable the AdminReports Advanced Service.');
30+
}
31+
const response = AdminReports.Activities.list(
32+
userKey, applicationName, optionalArgs);
2933
const activities = response.items;
3034
if (!activities || activities.length === 0) {
3135
console.log('No logins found.');
@@ -34,12 +38,14 @@ function listLogins() {
3438
// Print login events
3539
console.log('Logins:');
3640
for (const activity of activities) {
37-
console.log('%s: %s (%s)', activity.id.time, activity.actor.email,
38-
activity.events[0].name);
41+
if (activity.id && activity.actor && activity.events && activity.events.length > 0) {
42+
console.log('%s: %s (%s)', activity.id.time, activity.actor.email,
43+
activity.events[0].name);
44+
}
3945
}
4046
} catch (err) {
4147
// TODO (developer)- Handle exception from the Report API
42-
console.log('Failed with error %s', err.message);
48+
console.log('Failed with error %s', /** @type {Error} */ (err).message);
4349
}
4450
}
4551
// [END admin_sdk_reports_quickstart]

adminSDK/reseller/quickstart.gs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ function listSubscriptions() {
2323
maxResults: 10
2424
};
2525
try {
26+
if (!AdminReseller || !AdminReseller.Subscriptions) {
27+
throw new Error('Enable the AdminReseller Advanced Service.');
28+
}
2629
const response = AdminReseller.Subscriptions.list(optionalArgs);
2730
const subscriptions = response.subscriptions;
2831
if (!subscriptions || subscriptions.length === 0) {
@@ -31,12 +34,16 @@ function listSubscriptions() {
3134
}
3235
console.log('Subscriptions:');
3336
for (const subscription of subscriptions) {
34-
console.log('%s (%s, %s)', subscription.customerId, subscription.skuId,
35-
subscription.plan.planName);
37+
if (subscription.plan) {
38+
console.log('%s (%s, %s)', subscription.customerId, subscription.skuId,
39+
subscription.plan.planName);
40+
} else {
41+
console.log('%s (%s)', subscription.customerId, subscription.skuId);
42+
}
3643
}
3744
} catch (err) {
3845
// TODO (developer)- Handle exception from the Reseller API
39-
console.log('Failed with error %s', err.message);
46+
console.log('Failed with error %s', /** @type {Error} */ (err).message);
4047
}
4148
}
4249
// [END admin_sdk_reseller_quickstart]

0 commit comments

Comments
 (0)