Skip to content

Commit

Permalink
Add user identity delete example
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x authored Feb 9, 2024
1 parent f8ca650 commit 869d792
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 1 deletion.
114 changes: 114 additions & 0 deletions examples/delete-user-identity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import type { Builder, Command, Describe } from 'landlubber'

import type { AcsCredentialsListResponse } from '@seamapi/http/connect'

import type { Handler } from './index.js'

interface Options {
userIdentityId: string
}

export const command: Command = 'delete-user-identity userIdentityId'

export const describe: Describe = 'Delete a user identity'

export const builder: Builder = {
userIdentityId: {
type: 'string',
describe: 'User identity id to delete',
},
}

export const handler: Handler<Options> = async ({
userIdentityId,
seam,
logger,
}) => {
const waitForEvent =
(eventType: string, idKey: string) =>
async (resource: any): Promise<void> => {
// Application architecture specific logic that waits for an event matching
// event.event_type === eventType && event[idKey] === resource[idKey]
logger.info({ eventType, idKey, resource }, 'Got event')
}

const clientSessions = await seam.clientSessions.list({
// param not implemented
user_identity_id: userIdentityId,

Check failure on line 37 in examples/delete-user-identity.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v18)

Object literal may only specify known properties, and 'user_identity_id' does not exist in type '{ client_session_id?: string | undefined; user_identifier_key?: string | undefined; connect_webview_id?: string | undefined; without_user_identifier_key?: boolean | undefined; }'.

Check failure on line 37 in examples/delete-user-identity.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v20)

Object literal may only specify known properties, and 'user_identity_id' does not exist in type '{ client_session_id?: string | undefined; user_identifier_key?: string | undefined; connect_webview_id?: string | undefined; without_user_identifier_key?: boolean | undefined; }'.
})

for (const clientSession of clientSessions) {
await seam.clientSessions.delete({
client_session_id: clientSession.client_session_id,
})
}

const enrollmentAutomations =
await seam.userIdentities.enrollmentAutomations.list({
user_identity_id: userIdentityId,
})

for (const enrollmentAutomation of enrollmentAutomations) {
// endpoint not implemented
await seam.userIdentities.enrollmentAutomations.delete({

Check failure on line 53 in examples/delete-user-identity.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v18)

Property 'delete' does not exist on type 'SeamHttpUserIdentitiesEnrollmentAutomations'.

Check failure on line 53 in examples/delete-user-identity.ts

View workflow job for this annotation

GitHub Actions / Typecheck (Node.js v20)

Property 'delete' does not exist on type 'SeamHttpUserIdentitiesEnrollmentAutomations'.
enrollment_automation_id: enrollmentAutomation.enrollment_automation_id,
})
}

await Promise.all(
enrollmentAutomations.map(
// event not implemented
waitForEvent('enrollment_automation.deleted', 'enrollment_automation_id'),
),
)

const phones = await seam.phones.list({
owner_user_identity_id: userIdentityId,
})

for (const phone of phones) {
await seam.phones.deactivate({
device_id: phone.device_id,
})
}

// event not implemented
await Promise.all(phones.map(waitForEvent('phone.deactivated', 'device_id')))

for (const phone of phones) {
await seam.devices.delete({
device_id: phone.device_id,
})
}

const acsUsers = await seam.acs.users.list({
user_identity_id: userIdentityId,
})

const deletedCredentials: AcsCredentialsListResponse['acs_credentials'] = []

for (const acsUser of acsUsers) {
const credentials = await seam.acs.credentials.list({
acs_user_id: acsUser.acs_user_id,
})

for (const credential of credentials) {
await seam.acs.credentials.delete({
acs_credential_id: credential.acs_credential_id,
})
}

deletedCredentials.concat(credentials)
}

// event not implemented
await Promise.all(
deletedCredentials.map(
waitForEvent('acs_credential.deleted', 'acs_credential_id'),
),
)

await seam.userIdentities.delete({
user_identity_id: userIdentityId,
})
}
3 changes: 2 additions & 1 deletion examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import landlubber, {

import { SeamHttp } from '@seamapi/http/connect'

import * as deleteUserIdentity from './delete-user-identity.js'
import * as locks from './locks.js'
import * as unlock from './unlock.js'
import * as workspace from './workspace.js'
Expand All @@ -24,7 +25,7 @@ interface ClientContext {
seam: SeamHttp
}

const commands = [locks, unlock, workspace]
const commands = [deleteUserIdentity, locks, unlock, workspace]

const createAppContext: MiddlewareFunction = async (argv) => {
const apiKey = argv['api-key']
Expand Down

0 comments on commit 869d792

Please sign in to comment.