@cyc-seattle/gsuite-sdk 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/directory.d.ts +15 -3
- package/dist/directory.js +42 -0
- package/dist/fake/model.d.ts +1 -0
- package/dist/fake/model.js +8 -0
- package/dist/fake/server.js +10 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,6 +24,8 @@ const members = await new DirectoryClient(auth).listMembers("team@example.org");
|
|
|
24
24
|
const settings = await new GroupSettingsClient(auth).getSettings("team@example.org");
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
`addMember` and `removeMember` are idempotent: adding someone already in a group answers `"already-member"`, raising their role if it's lower, and taking out someone who isn't there answers `"not-member"`. Taking someone out of a group that doesn't exist throws. `getMember` finds a member by any of their addresses, since Google resolves an alias, and answers with their primary address, or `null` if they aren't in the group.
|
|
28
|
+
|
|
27
29
|
### Client options
|
|
28
30
|
|
|
29
31
|
`DirectoryClient` and `GroupSettingsClient` take an optional second argument:
|
package/dist/directory.d.ts
CHANGED
|
@@ -24,11 +24,12 @@ export interface GroupMember {
|
|
|
24
24
|
type?: GroupMemberType;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* Result of adding a member to a group.
|
|
28
|
-
*
|
|
29
|
-
* outcome, not a failure — Google reports it as an HTTP 409.
|
|
27
|
+
* Result of adding a member to a group. Adding is idempotent, so a member who's
|
|
28
|
+
* already there is an expected outcome, not a failure — Google reports it as an HTTP 409.
|
|
30
29
|
*/
|
|
31
30
|
export type AddMemberResult = "added" | "already-member";
|
|
31
|
+
/** Result of taking a member out of a group. Someone who isn't there (HTTP 404) is already out. */
|
|
32
|
+
export type RemoveMemberResult = "removed" | "not-member";
|
|
32
33
|
/**
|
|
33
34
|
* Admin SDK Directory API client for groups and their members.
|
|
34
35
|
*
|
|
@@ -58,6 +59,12 @@ export declare class DirectoryClient {
|
|
|
58
59
|
* Lists all members of a group, following pagination.
|
|
59
60
|
*/
|
|
60
61
|
listMembers(groupKey: string): Promise<GroupMember[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Gets one member of a group by any of their addresses. Google resolves an alias to the member,
|
|
64
|
+
* and answers with their primary address. Returns null when they aren't in the group. A missing
|
|
65
|
+
* group throws.
|
|
66
|
+
*/
|
|
67
|
+
getMember(groupKey: string, memberKey: string): Promise<GroupMember | null>;
|
|
61
68
|
/**
|
|
62
69
|
* Adds a member to a group with the given role. Returns "already-member"
|
|
63
70
|
* instead of throwing when the member is already in the group (HTTP 409),
|
|
@@ -67,6 +74,11 @@ export declare class DirectoryClient {
|
|
|
67
74
|
* than planned is left alone.
|
|
68
75
|
*/
|
|
69
76
|
addMember(groupKey: string, email: string, role: GroupRole): Promise<AddMemberResult>;
|
|
77
|
+
/**
|
|
78
|
+
* Takes a member out of a group. Returns "not-member" instead of throwing when they aren't in it
|
|
79
|
+
* (HTTP 404), since the caller wants them out either way. A missing group throws.
|
|
80
|
+
*/
|
|
81
|
+
removeMember(groupKey: string, email: string): Promise<RemoveMemberResult>;
|
|
70
82
|
/** The 409 path of `addMember`: promotes an existing member up to `role` if they're currently
|
|
71
83
|
* below it, and does nothing otherwise - including when they already outrank it. */
|
|
72
84
|
private promoteIfBelow;
|
package/dist/directory.js
CHANGED
|
@@ -113,6 +113,27 @@ export class DirectoryClient {
|
|
|
113
113
|
} while (pageToken);
|
|
114
114
|
return members;
|
|
115
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Gets one member of a group by any of their addresses. Google resolves an alias to the member,
|
|
118
|
+
* and answers with their primary address. Returns null when they aren't in the group. A missing
|
|
119
|
+
* group throws.
|
|
120
|
+
*/
|
|
121
|
+
async getMember(groupKey, memberKey) {
|
|
122
|
+
winston.debug("Getting group member", { groupKey, memberKey });
|
|
123
|
+
try {
|
|
124
|
+
const member = await safeCall(async () => {
|
|
125
|
+
const response = await this.client.members.get({ groupKey, memberKey });
|
|
126
|
+
return response.data;
|
|
127
|
+
}, this.pacing);
|
|
128
|
+
return convertToGroupMember(member);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (getHttpStatus(error) === 404 && (await this.getGroup(groupKey)) !== null) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
116
137
|
/**
|
|
117
138
|
* Adds a member to a group with the given role. Returns "already-member"
|
|
118
139
|
* instead of throwing when the member is already in the group (HTTP 409),
|
|
@@ -140,6 +161,27 @@ export class DirectoryClient {
|
|
|
140
161
|
throw error;
|
|
141
162
|
}
|
|
142
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Takes a member out of a group. Returns "not-member" instead of throwing when they aren't in it
|
|
166
|
+
* (HTTP 404), since the caller wants them out either way. A missing group throws.
|
|
167
|
+
*/
|
|
168
|
+
async removeMember(groupKey, email) {
|
|
169
|
+
winston.debug("Removing group member", { groupKey, email });
|
|
170
|
+
try {
|
|
171
|
+
await safeCall(async () => {
|
|
172
|
+
await this.client.members.delete({ groupKey, memberKey: email });
|
|
173
|
+
}, this.pacing);
|
|
174
|
+
winston.info("Removed group member", { groupKey, email });
|
|
175
|
+
return "removed";
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
if (getHttpStatus(error) === 404 && (await this.getGroup(groupKey)) !== null) {
|
|
179
|
+
winston.debug("Member not in group", { groupKey, email });
|
|
180
|
+
return "not-member";
|
|
181
|
+
}
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
143
185
|
/** The 409 path of `addMember`: promotes an existing member up to `role` if they're currently
|
|
144
186
|
* below it, and does nothing otherwise - including when they already outrank it. */
|
|
145
187
|
async promoteIfBelow(groupKey, email, role) {
|
package/dist/fake/model.d.ts
CHANGED
|
@@ -77,6 +77,7 @@ export declare class WorkspaceModel {
|
|
|
77
77
|
updateMember(groupKey: string, memberKey: string, body: {
|
|
78
78
|
role?: string | null;
|
|
79
79
|
}): FakeMember;
|
|
80
|
+
deleteMember(groupKey: string, memberKey: string): void;
|
|
80
81
|
getSettings(groupUniqueId: string): GroupSettings;
|
|
81
82
|
patchSettings(groupUniqueId: string, patch: GroupSettings): GroupSettings;
|
|
82
83
|
private requireGroup;
|
package/dist/fake/model.js
CHANGED
|
@@ -174,6 +174,14 @@ export class WorkspaceModel {
|
|
|
174
174
|
}
|
|
175
175
|
return this.toMember(member);
|
|
176
176
|
}
|
|
177
|
+
deleteMember(groupKey, memberKey) {
|
|
178
|
+
const group = this.requireGroup(groupKey);
|
|
179
|
+
const member = this.requireMember(group, memberKey);
|
|
180
|
+
for (const [key, stored] of group.members) {
|
|
181
|
+
if (stored === member)
|
|
182
|
+
group.members.delete(key);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
177
185
|
getSettings(groupUniqueId) {
|
|
178
186
|
return this.toSettings(this.requireSettingsGroup(groupUniqueId));
|
|
179
187
|
}
|
package/dist/fake/server.js
CHANGED
|
@@ -47,6 +47,11 @@ const ROUTES = [
|
|
|
47
47
|
path: new RegExp(`^/admin/directory/v1/groups/${SEGMENT}/members/${SEGMENT}$`),
|
|
48
48
|
handle: (model, [groupKey, memberKey], _, body) => model.updateMember(groupKey, memberKey, asObject(body)),
|
|
49
49
|
},
|
|
50
|
+
{
|
|
51
|
+
method: "DELETE",
|
|
52
|
+
path: new RegExp(`^/admin/directory/v1/groups/${SEGMENT}/members/${SEGMENT}$`),
|
|
53
|
+
handle: (model, [groupKey, memberKey]) => model.deleteMember(groupKey, memberKey),
|
|
54
|
+
},
|
|
50
55
|
{
|
|
51
56
|
method: "GET",
|
|
52
57
|
path: new RegExp(`^/groups/v1/groups/${SEGMENT}$`),
|
|
@@ -116,7 +121,11 @@ async function handle(model, request, response) {
|
|
|
116
121
|
}
|
|
117
122
|
try {
|
|
118
123
|
const result = route.handle(model, match, url, body);
|
|
119
|
-
if (
|
|
124
|
+
if (result === undefined) {
|
|
125
|
+
// A delete answers with no body, as Google's does.
|
|
126
|
+
response.writeHead(204).end();
|
|
127
|
+
}
|
|
128
|
+
else if (url.pathname.startsWith("/groups/v1/") && url.searchParams.get("alt") !== "json") {
|
|
120
129
|
sendAtom(response, result);
|
|
121
130
|
}
|
|
122
131
|
else {
|