|
1 | 1 | import { AutoPaginatable } from '../common/utils/pagination'; |
2 | 2 | import { WorkOS } from '../workos'; |
| 3 | +import { List, ListResponse } from '../common/interfaces'; |
3 | 4 | import { |
| 5 | + CreateItContactOptions, |
4 | 6 | CreateOrganizationOptions, |
5 | 7 | CreateOrganizationRequestOptions, |
| 8 | + DeleteItContactOptions, |
| 9 | + InviteItContactOptions, |
| 10 | + ItContact, |
| 11 | + ItContactResponse, |
| 12 | + ListItContactsOptions, |
6 | 13 | ListOrganizationsOptions, |
7 | 14 | Organization, |
8 | 15 | OrganizationResponse, |
| 16 | + RevokeItContactOptions, |
9 | 17 | UpdateOrganizationOptions, |
10 | 18 | } from './interfaces'; |
11 | 19 | import { |
| 20 | + deserializeItContact, |
12 | 21 | deserializeOrganization, |
| 22 | + serializeCreateItContactOptions, |
13 | 23 | serializeCreateOrganizationOptions, |
| 24 | + serializeInviteItContactOptions, |
14 | 25 | serializeUpdateOrganizationOptions, |
15 | 26 | } from './serializers'; |
16 | 27 |
|
@@ -151,4 +162,113 @@ export class Organizations { |
151 | 162 |
|
152 | 163 | return deserializeOrganization(data); |
153 | 164 | } |
| 165 | + |
| 166 | + /** |
| 167 | + * List IT Contacts |
| 168 | + * |
| 169 | + * Get the IT Contacts for an Organization. |
| 170 | + * @param options - Object containing the Organization ID. |
| 171 | + * @returns {Promise<List<ItContact>>} |
| 172 | + * @throws {AuthorizationException} 403 |
| 173 | + * @throws {NotFoundException} 404 |
| 174 | + */ |
| 175 | + async listItContacts( |
| 176 | + options: ListItContactsOptions, |
| 177 | + ): Promise<List<ItContact>> { |
| 178 | + const { organizationId } = options; |
| 179 | + |
| 180 | + const { data } = await this.workos.get<ListResponse<ItContactResponse>>( |
| 181 | + `/organizations/${organizationId}/it_contacts`, |
| 182 | + ); |
| 183 | + |
| 184 | + return { |
| 185 | + object: data.object, |
| 186 | + data: data.data.map(deserializeItContact), |
| 187 | + listMetadata: { |
| 188 | + before: data.list_metadata.before, |
| 189 | + after: data.list_metadata.after, |
| 190 | + }, |
| 191 | + }; |
| 192 | + } |
| 193 | + |
| 194 | + /** |
| 195 | + * Create an IT Contact |
| 196 | + * |
| 197 | + * Add an IT Contact to an Organization. No Admin Portal invitation is sent, |
| 198 | + * though the contact is notified if the Organization has a connection |
| 199 | + * certificate nearing expiry. |
| 200 | + * @param options - Object containing the Organization ID and the email address. |
| 201 | + * @returns {Promise<ItContact>} |
| 202 | + * @throws {AuthorizationException} 403 |
| 203 | + * @throws {NotFoundException} 404 |
| 204 | + * @throws {ConflictException} 409 |
| 205 | + * @throws {UnprocessableEntityException} 422 |
| 206 | + */ |
| 207 | + async createItContact(options: CreateItContactOptions): Promise<ItContact> { |
| 208 | + const { organizationId, ...payload } = options; |
| 209 | + |
| 210 | + const { data } = await this.workos.post<ItContactResponse>( |
| 211 | + `/organizations/${organizationId}/it_contacts`, |
| 212 | + serializeCreateItContactOptions(payload), |
| 213 | + ); |
| 214 | + |
| 215 | + return deserializeItContact(data); |
| 216 | + } |
| 217 | + |
| 218 | + /** |
| 219 | + * Delete an IT Contact |
| 220 | + * |
| 221 | + * Remove an IT Contact from an Organization and revoke the contact's active |
| 222 | + * setup links. |
| 223 | + * @param options - Object containing the Organization ID and the IT Contact ID. |
| 224 | + * @returns {Promise<void>} |
| 225 | + * @throws {AuthorizationException} 403 |
| 226 | + * @throws {NotFoundException} 404 |
| 227 | + */ |
| 228 | + async deleteItContact(options: DeleteItContactOptions): Promise<void> { |
| 229 | + const { organizationId, contactId } = options; |
| 230 | + |
| 231 | + await this.workos.delete( |
| 232 | + `/organizations/${organizationId}/it_contacts/${contactId}`, |
| 233 | + ); |
| 234 | + } |
| 235 | + |
| 236 | + /** |
| 237 | + * Invite an IT Contact |
| 238 | + * |
| 239 | + * Create an Admin Portal setup link and email it to the IT Contact. An |
| 240 | + * Organization can have at most one active invitation. |
| 241 | + * @param options - Object containing the Organization ID, the IT Contact ID and the intents. |
| 242 | + * @returns {Promise<void>} |
| 243 | + * @throws {AuthorizationException} 403 |
| 244 | + * @throws {NotFoundException} 404 |
| 245 | + * @throws {ConflictException} 409 |
| 246 | + * @throws {UnprocessableEntityException} 422 |
| 247 | + */ |
| 248 | + async inviteItContact(options: InviteItContactOptions): Promise<void> { |
| 249 | + const { organizationId, contactId, ...payload } = options; |
| 250 | + |
| 251 | + await this.workos.post( |
| 252 | + `/organizations/${organizationId}/it_contacts/${contactId}/invite`, |
| 253 | + serializeInviteItContactOptions(payload), |
| 254 | + ); |
| 255 | + } |
| 256 | + |
| 257 | + /** |
| 258 | + * Revoke an IT Contact's invitation |
| 259 | + * |
| 260 | + * Revoke the Organization's active Admin Portal invitation. |
| 261 | + * @param options - Object containing the Organization ID and the IT Contact ID. |
| 262 | + * @returns {Promise<void>} |
| 263 | + * @throws {AuthorizationException} 403 |
| 264 | + * @throws {NotFoundException} 404 |
| 265 | + */ |
| 266 | + async revokeItContact(options: RevokeItContactOptions): Promise<void> { |
| 267 | + const { organizationId, contactId } = options; |
| 268 | + |
| 269 | + await this.workos.post( |
| 270 | + `/organizations/${organizationId}/it_contacts/${contactId}/revoke`, |
| 271 | + {}, |
| 272 | + ); |
| 273 | + } |
154 | 274 | } |
0 commit comments