diff --git a/flows.yaml b/flows.yaml index da132265..d76dd9ef 100644 --- a/flows.yaml +++ b/flows.yaml @@ -2654,10 +2654,10 @@ integrations: path: /users/email group: Users output: SuccessResponse - input: EmailEntity + input: IdEntity models: - EmailEntity: - email: string + IdEntity: + id: string SuccessResponse: success: boolean User: diff --git a/integrations/dialpad/actions/create-user.ts b/integrations/dialpad/actions/create-user.ts index 8f879f28..15055fd3 100644 --- a/integrations/dialpad/actions/create-user.ts +++ b/integrations/dialpad/actions/create-user.ts @@ -1,5 +1,5 @@ -import type { NangoAction, ProxyConfiguration } from '../../models'; -import type { DialpadCreateUser, DialpadUser, User } from '../types'; +import type { NangoAction, ProxyConfiguration, DialpadCreateUser, User } from '../../models'; +import type { DialpadUser } from '../types'; import { dialpadCreateUserSchema } from '../schema.zod.js'; /** @@ -33,14 +33,14 @@ export default async function createUser(input: DialpadCreateUser, nango: NangoA retries: 10 }; - const response = await nango.post<{ resource: DialpadUser }>(config); + const response = await nango.post(config); - const newUser = response.data.resource; + const newUser = response.data; const user: User = { - id: newUser.id, - firstName: newUser.first_name, - lastName: newUser.last_name, - email: newUser.emails + id: newUser.id ? newUser.id.toString() : '', + firstName: newUser.first_name || '', + lastName: newUser.last_name || '', + email: parsedInput.data.email }; return user; diff --git a/integrations/dialpad/actions/delete-user.ts b/integrations/dialpad/actions/delete-user.ts index a0e542d6..5a1e7134 100644 --- a/integrations/dialpad/actions/delete-user.ts +++ b/integrations/dialpad/actions/delete-user.ts @@ -1,13 +1,8 @@ -import type { NangoAction, ProxyConfiguration, SuccessResponse, EmailEntity } from '../../models'; -import { emailEntitySchema } from '../schema.zod.js'; +import type { NangoAction, ProxyConfiguration, SuccessResponse, IdEntity } from '../../models'; +import { idEntitySchema } from '../schema.zod.js'; -/** - * Executes the delete user action by validating email input, fetching the user ID, - * and making the API call to Dialpad to delete the user. - * API Reference: https://developers.dialpad.com/reference/usersdelete - */ -export default async function runAction(nango: NangoAction, input: EmailEntity): Promise { - const parsedInput = emailEntitySchema.safeParse(input); +export default async function runAction(nango: NangoAction, input: IdEntity): Promise { + const parsedInput = idEntitySchema.safeParse(input); if (!parsedInput.success) { for (const error of parsedInput.error.errors) { @@ -15,22 +10,13 @@ export default async function runAction(nango: NangoAction, input: EmailEntity): } throw new nango.ActionError({ - message: 'Invalid email provided to delete a user' + message: 'Invalid id provided to delete a user' }); } - // Fetch the user ID using the email - const userId = await fetchUserIdByEmail(nango, parsedInput.data.email); - if (!userId) { - throw new nango.ActionError({ - message: `User with email ${parsedInput.data.email} not found` - }); - } - - // Delete the user by ID const config: ProxyConfiguration = { // https://developers.dialpad.com/reference/usersdelete - endpoint: `/api/v2/users/${encodeURIComponent(userId)}`, + endpoint: `/api/v2/users/${encodeURIComponent(parsedInput.data.id)}`, retries: 10 }; @@ -40,20 +26,3 @@ export default async function runAction(nango: NangoAction, input: EmailEntity): success: true }; } - -//Fetches the user ID by email from Dialpad. -async function fetchUserIdByEmail(nango: NangoAction, email: string): Promise { - const config: ProxyConfiguration = { - // https://developers.dialpad.com/reference/userslist - endpoint: '/api/v2/users', - params: { - email: encodeURIComponent(email) - }, - retries: 10 - }; - - const response = await nango.get<{ users: { id: string; email: string }[] }>(config); - const user = response.data.users.find((user) => user.email === email); - - return user ? user.id : null; -} diff --git a/integrations/dialpad/nango.yaml b/integrations/dialpad/nango.yaml index d0147d2d..afe04d63 100644 --- a/integrations/dialpad/nango.yaml +++ b/integrations/dialpad/nango.yaml @@ -29,11 +29,11 @@ integrations: path: /users/email group: Users output: SuccessResponse - input: EmailEntity + input: IdEntity models: - EmailEntity: - email: string + IdEntity: + id: string SuccessResponse: success: boolean User: diff --git a/integrations/dialpad/schema.zod.ts b/integrations/dialpad/schema.zod.ts index 29b81f8d..cb7bff4b 100644 --- a/integrations/dialpad/schema.zod.ts +++ b/integrations/dialpad/schema.zod.ts @@ -1,8 +1,8 @@ // Generated by ts-to-zod import { z } from 'zod'; -export const emailEntitySchema = z.object({ - email: z.string() +export const idEntitySchema = z.object({ + id: z.string() }); export const successResponseSchema = z.object({ diff --git a/integrations/dialpad/syncs/users.ts b/integrations/dialpad/syncs/users.ts index 0dbd347a..a28f68ba 100644 --- a/integrations/dialpad/syncs/users.ts +++ b/integrations/dialpad/syncs/users.ts @@ -1,7 +1,7 @@ -import type { NangoSync, ProxyConfiguration } from '../../models'; -import type { DialpadUser, User, UserListParams } from '../types'; +import type { NangoSync, ProxyConfiguration, User } from '../../models'; +import type { DialpadUser } from '../types'; -export default async function fetchData(nango: NangoSync, params?: UserListParams) { +export default async function fetchData(nango: NangoSync) { const proxyConfiguration: ProxyConfiguration = { // https://developers.dialpad.com/reference/userslist endpoint: '/api/v2/users', @@ -10,24 +10,21 @@ export default async function fetchData(nango: NangoSync, params?: UserListParam cursor_name_in_request: 'cursor', cursor_path_in_response: 'cursor', response_path: 'items', - limit: params?.limit || 100, + limit: 100, limit_name_in_request: 'limit' }, params: { - ...(params?.state ? { state: params.state } : {}), - ...(params?.email ? { email: params.email } : {}), - ...(params?.number ? { number: params.number } : {}), - ...(params?.company_admin !== undefined ? { company_admin: String(params.company_admin) } : {}) + state: 'active' } }; for await (const dialpadUsers of nango.paginate(proxyConfiguration)) { const users: User[] = dialpadUsers.map((dialpadUser: DialpadUser) => { return { - id: dialpadUser.id ?? null, - firstName: dialpadUser.first_name ?? null, - lastName: dialpadUser.last_name ?? null, - email: dialpadUser.emails ?? null + id: dialpadUser.id ? dialpadUser.id.toString() : '', + firstName: dialpadUser.first_name || '', + lastName: dialpadUser.last_name || '', + email: dialpadUser.emails && dialpadUser.emails[0] ? dialpadUser.emails[0] : '' }; }); diff --git a/integrations/dialpad/types.ts b/integrations/dialpad/types.ts index e8ba79f0..2cb19051 100644 --- a/integrations/dialpad/types.ts +++ b/integrations/dialpad/types.ts @@ -1,18 +1,3 @@ -export interface EmailEntity { - email: string; -} - -export interface SuccessResponse { - success: boolean; -} - -export interface User { - id: number | null; - email: string[] | null; - firstName: string | null; - lastName: string | null; -} - export type GroupRole = 'admin' | 'operator' | 'supervisor'; export type GroupType = @@ -71,24 +56,3 @@ export interface DialpadUser { status_message: string | null; timezone: string | null; } - -export interface CreateUser { - firstName: string; - lastName: string; - email: string; -} - -export interface DialpadCreateUser extends CreateUser { - license?: string; - officeId?: string; - autoAssign?: boolean; -} - -export interface UserListParams { - cursor?: string; - state?: 'active' | 'all' | 'cancelled' | 'suspended' | 'deleted' | 'pending'; - company_admin?: boolean; - limit?: number; - email?: string; - number?: string; -}