import {z} from 'zod' export type IncludeResellerActivationProperties = 'user' | 'organization'; export type GetApiV3ResellersResellerIdActivationsArgs = {resellerId: string, page?: number | undefined, limit?: number | undefined, sort?: string | undefined, include?: Array | undefined, organizationId?: ({eq?: unknown | undefined, ne?: unknown | undefined, in?: unknown | undefined, nin?: unknown | undefined}) | undefined, licenseId?: ({eq?: unknown | undefined, ne?: unknown | undefined, in?: unknown | undefined, nin?: unknown | undefined}) | undefined, releaseVersion?: ({eq?: unknown | undefined, ne?: unknown | undefined, sw?: unknown | undefined, ew?: unknown | undefined, cn?: unknown | undefined, nc?: unknown | undefined, in?: unknown | undefined, nin?: unknown | undefined}) | undefined, os?: ({eq?: unknown | undefined, ne?: unknown | undefined, in?: unknown | undefined, nin?: unknown | undefined}) | undefined, 'location.countryCode'?: ({eq?: unknown | undefined, ne?: unknown | undefined, sw?: unknown | undefined, ew?: unknown | undefined, cn?: unknown | undefined, nc?: unknown | undefined, in?: unknown | undefined, nin?: unknown | undefined}) | undefined, lastSyncedAt?: ({eq?: string | undefined, ne?: string | undefined, gt?: string | undefined, gte?: string | undefined, lt?: string | undefined, lte?: string | undefined}) | undefined, 'license.key'?: ({eq?: unknown | undefined, ne?: unknown | undefined, sw?: unknown | undefined, ew?: unknown | undefined, cn?: unknown | undefined, nc?: unknown | undefined, in?: unknown | undefined, nin?: unknown | undefined}) | undefined, userId?: string | undefined, search?: string | undefined, id?: ({eq?: unknown | undefined, ne?: unknown | undefined, in?: unknown | undefined, nin?: unknown | undefined}) | undefined, createdAt?: ({eq?: string | undefined, ne?: string | undefined, gt?: string | undefined, gte?: string | undefined, lt?: string | undefined, lte?: string | undefined}) | undefined, updatedAt?: ({eq?: string | undefined, ne?: string | undefined, gt?: string | undefined, gte?: string | undefined, lt?: string | undefined, lte?: string | undefined}) | undefined}; export type GetApiV3ResellersResellerIdActivationsOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const geoLocationDto = z.object({ipAddress: z.string(), countryCode: z.string().nullable().optional(), countryName: z.string().nullable().optional(), regionCode: z.string().nullable().optional(), regionName: z.string().nullable().optional(), city: z.string().nullable().optional(), zipCode: z.string().nullable().optional(), timeZone: z.string().nullable().optional(), latitude: z.number().nullable().optional(), longitude: z.number().nullable().optional()}); export const activationMeterAttributeDto = z.object({name: z.string(), uses: z.number().int()}); export const resellerOrganizationDto = z.object({id: z.string(), createdAt: z.string(), updatedAt: z.string(), organizationAlias: z.string().nullable().optional(), name: z.string(), email: z.string(), description: z.string(), allowedUsers: z.number().int()}); export const resellerUserDto = z.object({id: z.string(), createdAt: z.string(), updatedAt: z.string(), name: z.string(), firstName: z.string(), lastName: z.string(), email: z.string(), role: z.string(), twoFactorEnabled: z.boolean(), googleSsoEnabled: z.boolean(), lastLoginAt: z.string().nullable().optional(), twoFactorRequiredFrom: z.string().nullable().optional(), organizationId: z.string().nullable().optional(), organization: resellerOrganizationDto.optional(), company: z.string().nullable().optional()}); export const resellerActivationDto = z.object({id: z.string(), createdAt: z.string(), updatedAt: z.string(), os: z.enum(["windows", "linux", "macos", "android", "ios"]), osVersion: z.string().nullable().optional(), hostname: z.string(), location: geoLocationDto, vmName: z.string().nullable().optional(), container: z.boolean(), appVersion: z.string().nullable().optional(), releaseVersion: z.string().nullable().optional(), releaseChannel: z.string().nullable().optional(), releasePlatform: z.string().nullable().optional(), offline: z.boolean(), productId: z.string(), expiresAt: z.string().nullable().optional(), licenseId: z.string(), lastSyncedAt: z.string(), meterAttributes: z.array(activationMeterAttributeDto), leaseExpiresAt: z.string().nullable().optional(), user: resellerUserDto.optional(), organization: resellerOrganizationDto.optional()}); export const getApiV3ResellersResellerIdActivationsResponse = z.array(resellerActivationDto); 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 }; /** * List all reseller activations * * GET /v3/resellers/{resellerId}/activations */ export const getApiV3ResellersResellerIdActivations = async (args: GetApiV3ResellersResellerIdActivationsArgs, options?: GetApiV3ResellersResellerIdActivationsOptions) => { const {baseUrl = "https://api.cryptlex.com", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.sort != null) query.append("sort", String(args.sort)) for (const item of args.include ?? []) query.append("include", String(item)) if (args.organizationId != null) query.append("organizationId", JSON.stringify(args.organizationId)) if (args.licenseId != null) query.append("licenseId", JSON.stringify(args.licenseId)) if (args.releaseVersion != null) query.append("releaseVersion", JSON.stringify(args.releaseVersion)) if (args.os != null) query.append("os", JSON.stringify(args.os)) if (args['location.countryCode'] != null) query.append("location.countryCode", JSON.stringify(args['location.countryCode'])) if (args.lastSyncedAt != null) query.append("lastSyncedAt", JSON.stringify(args.lastSyncedAt)) if (args['license.key'] != null) query.append("license.key", JSON.stringify(args['license.key'])) if (args.userId != null) query.append("userId", String(args.userId)) if (args.search != null) query.append("search", String(args.search)) if (args.id != null) query.append("id", JSON.stringify(args.id)) if (args.createdAt != null) query.append("createdAt", JSON.stringify(args.createdAt)) if (args.updatedAt != null) query.append("updatedAt", JSON.stringify(args.updatedAt)) if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/resellers/${encodeURIComponent(String(args.resellerId))}/activations${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(getApiV3ResellersResellerIdActivationsResponse, await res.json()) };