UNPKG

forma-embedded-view-sdk

Version:

The Forma Embedded View SDK is a JavaScript library for creating custom extensions in Autodesk Forma (previously Spacemaker).

148 lines (147 loc) 4.94 kB
import type { IframeMessenger } from "./iframe-messenger.js"; interface FieldCommmon { name: string; label: string; hidden?: boolean; } interface NumberField extends FieldCommmon { type: "number"; min?: number; max?: number; step?: number; } interface BooleanField extends FieldCommmon { type: "bool"; } interface EnumField extends FieldCommmon { type: "enum"; options: string[]; } interface StringField extends FieldCommmon { type: "string"; } interface ColorField extends FieldCommmon { type: "color"; } interface PolygonField extends FieldCommmon { type: "polygon"; } interface PolylineField extends FieldCommmon { type: "polyline"; } /** Allowable generator fields */ export type GeneratorSchemaV1Field = NumberField | BooleanField | EnumField | ColorField | StringField | PolygonField | PolylineField; /** Values corresponding to the allowable generator fields */ export type GeneratorSchemaV1Value = number | boolean | string | string | string | { points: [number, number][]; } | { points: [number, number][]; }; type Namespace = string; type Owner = string; type OwnerId = string; type AuthContext = string; type Id = string; /** * Specially formatted URN used as unique identifier for a generator. * * Must satisfy the specified pattern, where * - `Namespace` is a namespace of the generator, currently only `adsk-forma-generators` is allowed * - `Owner` is a name of the generator owner, i.e. `extension` * - `OwnerId` is the `extensionId` of the extension that owns the generator * - `AuthContext` is the authcontext the generator is registered in, i.e. the current `projectId` * - `Id` is a unique identifier of the generator, specified by the extension * and used to keep a stable reference to the generator instance. * */ export type GeneratorUrn = `urn:${Namespace}:${Owner}:${OwnerId}:${AuthContext}:${Id}`; /** [Endpoint runner](https://aps.autodesk.com/en/docs/forma/v1/generators/in-depth/http/) */ export interface ExtensionEndpointRunner { type: "extensionEndpoint"; extension: { extensionId: string; endpointId: string; }; additionalData: unknown; } /** [Script runner](https://aps.autodesk.com/en/docs/forma/v1/generators/in-depth/script/) */ export interface ExtensionScriptRunner { type: "extensionScript"; extensionId: string; bundleId: string; additionalData: unknown; } /** * The v1 schema is a simple schema that supports a few field types and a simple * structure to render a form for the user to specify values to the fields. * * See [our documentation](https://aps.autodesk.com/en/docs/forma/v1/generators/generator-schema-v1/) for more details. */ export interface GeneratorSchemaV1 { version: 1; fields: GeneratorSchemaV1Field[]; defaultValues?: Record<string, GeneratorSchemaV1Value>; } /** * Generator resource model. * * Generators that exist in the context of an extension may only be manipulated * by the extension itself, but can be read by all users. These generators are * useful for cases where you want to provide a single generator to any user of * your extension. */ export interface Generator { /** Unique identifier for the generator, see {@link GeneratorUrn} for format spec. */ id: GeneratorUrn; /** Name of the generator. */ name: string; /** Runners to be employed by the generator. */ runners: ({ type: never; } | ExtensionEndpointRunner | ExtensionScriptRunner)[]; /** Schema defining the fields and default values expected by the generator. */ schema: { version: never; } | GeneratorSchemaV1; } /** * Manage [generators](https://aps.autodesk.com/en/docs/forma/v1/http-specification/generators-api/) registered in Forma. * * @remarks * Available via {@link auto.Forma | Forma}.{@link index.EmbeddedViewSdk.generators | generators}. */ export declare class GeneratorsApi { #private; /** @hidden */ constructor(iframeMessenger: IframeMessenger); /** * Create or replace a generator. * * @returns The created or replaced generator resource model. */ put(request: { /** * Authcontext to use with the request. * * As of now, the currently open project id is both default * and only allowed value. */ authcontext?: string | undefined; /** Generator resource model to create or replace. */ data: Generator; }): Promise<Generator>; /** * List out generators within the specified authcontext. * * @returns List of registered generators. */ list(request?: { /** * Authcontext to use with the request. * * As of now, the currently open project id is both default * and only allowed value. */ authcontext?: string | undefined; } | undefined): Promise<Generator[]>; } export {};