import {z} from 'zod' export type SecurityPermissionX = {type?: ('NONE' | 'Account' | 'AccountHistory' | 'AccountCallHistory' | 'AccountBulkStatuses' | 'IpWhitelist' | 'PhoneNumber' | 'PhoneNumberServiceActivation' | 'PhoneNumberInventory' | 'Product' | 'ProductCallingPlan' | 'ProductGroups' | 'ProductUsers' | 'Reports' | 'RoutePlan' | 'SipCredentials' | 'EU_DeviceSwapCreate' | 'EU_Account' | 'EU_AccountMedia' | 'EU_CallHistory' | 'EU_Device' | 'EU_DeviceSwap' | 'EU_DeviceLine' | 'EU_IVR' | 'EU_LineAppearance' | 'EU_LineHardware' | 'EU_LineHuntGroup' | 'EU_Voicemail' | 'EU_VoicemailMessage' | 'EU_VoicemailUnlock' | 'EU_Telephone' | 'EU_SipTrunk' | 'EU_User' | 'EU_UserResetPassword' | 'EU_History' | 'EU_BUSINESS_LINE' | 'EU_BUSINESS_LINE_PROVISIONING' | 'EU_BUSINESS_LINE_VOICEMAIL' | 'EU_BUSINESS_LINE_HUNT_GROUP' | 'EU_911_ADDRESS' | 'EU_TELEPHONE_DESTINATION' | 'EU_ENDUSER_REPURPOSE' | 'ALIANZA_MasterRoutePlan' | 'ALIANZA_TogglzAdmin' | 'ANY_END_USER' | 'ANY_MANAGEMENT_USER' | 'ANY_ALIANZA_USER') | undefined, accessType?: ('NONE' | 'READ_MYUSER' | 'READ' | 'EDIT_MYUSER' | 'EDIT' | 'CREATE_MYUSER' | 'CREATE' | 'DELETE_MYUSER' | 'DELETE' | 'DENIED') | undefined}; export type SecurityRoleX = {id?: string | undefined, partitionId?: string | undefined, name?: string | undefined, userType?: ('AccountUser' | 'EndUser' | 'ManagementUser' | 'AlianzaUser' | 'BusinessLines') | undefined, userCount?: number | undefined, permissions?: Array | undefined}; export type UpdateApiV2PartitionPartitionIdSecuritySecurityIdArgs = {partitionId: string, securityId: string, body: SecurityRoleX}; export type UpdateApiV2PartitionPartitionIdSecuritySecurityIdOptions = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const securityPermissionX = z.object({type: z.enum(["NONE", "Account", "AccountHistory", "AccountCallHistory", "AccountBulkStatuses", "IpWhitelist", "PhoneNumber", "PhoneNumberServiceActivation", "PhoneNumberInventory", "Product", "ProductCallingPlan", "ProductGroups", "ProductUsers", "Reports", "RoutePlan", "SipCredentials", "EU_DeviceSwapCreate", "EU_Account", "EU_AccountMedia", "EU_CallHistory", "EU_Device", "EU_DeviceSwap", "EU_DeviceLine", "EU_IVR", "EU_LineAppearance", "EU_LineHardware", "EU_LineHuntGroup", "EU_Voicemail", "EU_VoicemailMessage", "EU_VoicemailUnlock", "EU_Telephone", "EU_SipTrunk", "EU_User", "EU_UserResetPassword", "EU_History", "EU_BUSINESS_LINE", "EU_BUSINESS_LINE_PROVISIONING", "EU_BUSINESS_LINE_VOICEMAIL", "EU_BUSINESS_LINE_HUNT_GROUP", "EU_911_ADDRESS", "EU_TELEPHONE_DESTINATION", "EU_ENDUSER_REPURPOSE", "ALIANZA_MasterRoutePlan", "ALIANZA_TogglzAdmin", "ANY_END_USER", "ANY_MANAGEMENT_USER", "ANY_ALIANZA_USER"]).optional(), accessType: z.enum(["NONE", "READ_MYUSER", "READ", "EDIT_MYUSER", "EDIT", "CREATE_MYUSER", "CREATE", "DELETE_MYUSER", "DELETE", "DENIED"]).optional()}); export const securityRoleX = z.object({id: z.string().optional(), partitionId: z.string().optional(), name: z.string().optional(), userType: z.enum(["AccountUser", "EndUser", "ManagementUser", "AlianzaUser", "BusinessLines"]).optional(), userCount: z.number().int().optional(), permissions: z.array(securityPermissionX).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update Security Role * * PUT /v2/partition/{partitionId}/security/{securityId} */ export const updateApiV2PartitionPartitionIdSecuritySecurityId = async (args: UpdateApiV2PartitionPartitionIdSecuritySecurityIdArgs, options?: UpdateApiV2PartitionPartitionIdSecuritySecurityIdOptions) => { const {baseUrl = "https://api.alianza.com", fetch: fetchFn = fetch, XAuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/partition/${encodeURIComponent(String(args.partitionId))}/security/${encodeURIComponent(String(args.securityId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(securityRoleX, await res.json()) };