import { type ResponseType } from 'axios'; import { z } from 'zod'; import { healthcheck } from '../../../operators/healthCheck.js'; import { type ThreekitAxiosContext } from '../../../operators/HttpContext.js'; import { request } from '../../../operators/request.js'; import { Configuration, getDefaultResponseType, type RequestResponseReturnType, type RequestResponseType, threekitHostToEnv } from '../../../shared.js'; import { type ThreekitAuthProps } from '../../../ThreekitAuthProps.js'; import { createLocalAxios } from '../utils/createLocalAxios.js'; export const ExporterExport = z.object({ assetId: z.string(), stageId: z.string().optional(), configuration: Configuration.optional(), stageConfiguration: Configuration.optional(), cache: z.boolean().optional(), cacheScope: z.string().optional(), cacheMaxAge: z.number().optional(), version: z .union([z.literal('platform'), z.literal('experimental')]) .optional(), settings: z .union([ z.record(z.string(), z.any()), z.object({ arExport: z.boolean().optional(), prune: z .object({ invisible: z.boolean().optional(), // default true. removes nodes that are invisible in the hierarchy childless: z.boolean().optional() // default true. recursively remove nodes that have no PolyMesh or Connector grandchildren }) .optional() }) ]) .optional() }); export type ExporterExportProps = z.infer; const DEBUG = false; const API_ROUTE = `api/exporter`; const API_HOST = DEBUG ? 'localhost:4003' : 'exporter.alpha.3kit.com'; const API_PROTOCOL = DEBUG ? 'http://' : 'https://'; export class Exporter { context: ThreekitAxiosContext; constructor(auth: ThreekitAuthProps) { this.context = { axios: createLocalAxios({ protocol: API_PROTOCOL, host: API_HOST }), auth, urlPrefix: API_ROUTE }; } healthcheck() { return healthcheck(this.context); } exportGlb( props: ExporterExportProps, responseType = getDefaultResponseType() ) { const auth = this.context.auth; const token = 'publicToken' in auth ? auth.publicToken : 'privateToken' in auth ? auth.privateToken : undefined; if (token === undefined) throw new Error('Only public and private tokens supported'); const { assetId, configuration = {}, cache = true, cacheScope, cacheMaxAge, settings } = ExporterExport.parse(props); const req = request>(this.context, { url: `export`, params: { environment: threekitHostToEnv(this.context.auth.host), orgId: this.context.auth.orgId, bearer_token: token, assetId, configuration, cache, cacheScope, cacheMaxAge, settings }, responseType: responseType as ResponseType }); return req; } }