import {z} from 'zod' export type CreateApiLicenseManagementImportArgs = {body: BodyInit}; export type CreateApiLicenseManagementImportOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const effectiveLicenseStatus = z.enum(["ACTIVE", "GRACE", "RECOVERY", "MISSING", "EXPIRED", "REVOKED", "SUSPENDED", "INVALID", "BLOCKED"]); export const productLicenseSummary = z.object({product: z.string(), edition: z.string(), modules: z.array(z.string()).optional(), quotaKeys: z.array(z.string()).optional()}); export const licenseStatusProjection = z.object({status: effectiveLicenseStatus, productSummaries: z.array(productLicenseSummary).optional(), customerId: z.string().nullable().optional(), installationId: z.string().nullable().optional(), issuer: z.string().nullable().optional(), signingCertificateFingerprint: z.string().nullable().optional(), expiresAt: z.string().nullable().optional(), daysToExpiry: z.number().int().nullable().optional(), recoveryMode: z.boolean().optional(), graceMode: z.boolean().optional(), warnings: z.array(z.string()).optional()}); export const setupLicenseBundleImportResult = z.object({license: licenseStatusProjection, importedFiles: z.array(z.string()), recipientPrivateKeyInstalled: z.boolean(), platformCertificateInstalled: z.boolean(), licenseRootCaInstalled: z.boolean(), customerPartyInfoImported: z.boolean()}); 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 }; /** * Import a protected license renewal bundle * * POST /license-management/import */ export const createApiLicenseManagementImport = async (args: CreateApiLicenseManagementImportArgs, options?: CreateApiLicenseManagementImportOptions) => { const {baseUrl = "https://api.example.com/api/platform/setup/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/license-management/import${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(setupLicenseBundleImportResult, await res.json()) };