import {z} from 'zod' export type GetApiV1MarketplacesMarketplaceIdArgs = {marketplaceId: unknown}; export type GetApiV1MarketplacesMarketplaceIdOptions = {baseUrl?: string | undefined, denApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const pluginArchMarketplace = z.object({externalKey: z.string().nullable(), id: z.string().min(30).max(30), organizationId: z.string().min(30).max(30), name: z.string().min(1).max(255), description: z.string().min(1).nullable(), logoUrl: z.string().min(1).nullable(), status: z.enum(["active", "inactive", "deleted", "archived"]), createdByOrgMembershipId: z.string().min(29).max(29), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string().nullable(), pluginCount: z.number().int().gte(0).lte(9007199254740991).optional()}); export const pluginArchMarketplaceDetailResponse = z.object({item: pluginArchMarketplace}); 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 }; /** * Get marketplace * * GET /v1/marketplaces/{marketplaceId} * * Also accepts auth: bearerAuth */ export const getApiV1MarketplacesMarketplaceId = async (args: GetApiV1MarketplacesMarketplaceIdArgs, options?: GetApiV1MarketplacesMarketplaceIdOptions) => { const {baseUrl = "https://api.openworklabs.com", fetch: fetchFn = fetch, denApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (denApiKey !== undefined) headers.set("x-api-key", denApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/marketplaces/${encodeURIComponent(String(args.marketplaceId))}${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(pluginArchMarketplaceDetailResponse, await res.json()) };