import {z} from 'zod' export type GetApiAppResellerV1UsersUserIdArgs = {context: 'RESELLER' | 'RESELLER_MANAGER', userId: string, companyId: string}; export type GetApiAppResellerV1UsersUserIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const appResellerAccountCompanyWS = z.object({id: z.string().optional(), externalId: z.string().nullable().optional(), name: z.string().optional(), createdOn: z.number().optional()}); export const mosiUser = z.object({username: z.string().nullable().optional()}).nullable(); export const role = z.enum(["USER", "APPLICATION", "PARTNER", "PARTNER_READ", "COMPANY", "CLIENT", "CHECKOUT_USER", "BILLING_ADMIN", "SYS_ADMIN", "DEVELOPER", "CHANNEL_PRODUCT_SUPPORT", "CHANNEL_SUPPORT", "CHANNEL_ADMIN", "CORPORATE_ADMIN", "SUPERUSER", "SUPER_SUPPORT", "ANALYTICS_ADMIN", "LAYOUT_DESIGNER", "SALES_SUPPORT", "RESTRICTED_SALES_SUPPORT", "RESELLER", "RESELLER_MANAGER", "TESTER", "MONITORING", "SYSTEM"]); export const appResellerAccountUserCompanyMembershipWS = z.object({company: appResellerAccountCompanyWS.optional(), enabled: z.boolean().optional(), mosiUser: mosiUser.optional(), roles: z.array(role).optional()}); export const attributeType = z.enum(["TEXT", "MULTISELECT"]); export const customAttributeLocalizedValueOptionWS = z.object({optionKey: z.string().optional(), optionLabel: z.string().optional()}); export const customAttributeLightV2WS = z.object({attributeKey: z.string().optional(), attributeType: attributeType.optional(), label: z.string().optional(), value: z.string().optional(), valueKeys: z.array(z.string()).optional(), valueOptions: z.array(customAttributeLocalizedValueOptionWS).optional()}); export const appResellerAccountUserSettingCode = z.enum(["BILLING_ADMIN", "SYS_ADMIN", "DEVELOPER", "TESTER", "CHANNEL_PRODUCT_SUPPORT", "CHANNEL_SUPPORT", "SALES_SUPPORT", "CHANNEL_ADMIN", "RESELLER_MANAGER", "RESELLER", "REFERRAL", "ODSA_SUPPORT"]); export const readWritePermission = z.enum(["READ", "WRITE"]); export const appResellerUserSettingWS = z.object({setting: appResellerAccountUserSettingCode.optional(), permission: readWritePermission.optional(), value: z.string().optional()}); export const appResellerUserActionsWS = z.enum(["RESET_PASSWORD", "SEND_RESET_PASSWORD_EMAIL", "SEND_ACTIVATION_EMAIL", "ACCEPT_SIGNUP_REQUEST", "REMOVE_USER_FROM_COMPANY", "REMOVE_LAST_USER_FROM_COMPANY", "LEAVE_COMPANY", "JOIN_COMPANY", "IMPERSONATE", "REQUEST_ACCOUNT_ACCESS", "CANCEL_REQUEST_ACCOUNT_ACCESS", "ENABLE_USER", "RESET_TWO_FACTOR_AUTHENTICATION", "CHANGE_ACCOUNT_EMAIL", "DISABLE_USER", "MAKE_PURCHASE"]); export const appResellerUserRoleWS = z.object({name: z.string().optional(), permission: readWritePermission.optional()}); export const applicationSummaryStat = z.object({unit: z.string().optional(), children: z.string().optional()}); export const userReadResponse = z.object({id: z.string().optional(), companyId: z.string().optional(), email: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), createdOn: z.number().optional(), activated: z.boolean().optional(), invitationRequired: z.boolean().optional(), enabled: z.boolean().optional(), memberships: z.array(appResellerAccountUserCompanyMembershipWS).optional(), partner: z.string().optional(), numActiveApps: z.number().int().optional(), customAttributes: z.array(customAttributeLightV2WS).optional(), profilePic: z.string().optional(), settings: z.array(appResellerUserSettingWS).optional(), actions: z.array(appResellerUserActionsWS).optional(), availableRoles: z.array(appResellerUserRoleWS).optional(), stats: z.array(applicationSummaryStat).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 }; /** * User details * * GET /appReseller/v1/users/{userId} */ export const getApiAppResellerV1UsersUserId = async (args: GetApiAppResellerV1UsersUserIdArgs, options?: GetApiAppResellerV1UsersUserIdOptions) => { const {baseUrl = "https://marketplace.appdirect.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.context != null) query.append("context", String(args.context)) if (args.companyId != null) query.append("companyId", String(args.companyId)) const url = `${baseUrl.replace(/\/+$/, '')}/appReseller/v1/users/${encodeURIComponent(String(args.userId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(userReadResponse, await res.json()) };