//#region src/files.d.ts /** * Payload required to upload a file via {@link PdkApi.uploadFile}. * * @category Files */ type UploadFileRequest = { fileName: string; content: ArrayBuffer | Uint8Array; }; //#endregion //#region src/objects.d.ts interface ListNameToStructureRegistry {} /** * Type representing the names of Resource Management lists. * @category Resource Management Lists */ type ListName = keyof ListNameToStructureRegistry; /** * Type representing the different types of characteristics in Resource Management. * @category Resource Management Objects */ type CharacteristicType = "SHORT_TEXT" | "LONG_TEXT" | "CHECKBOX" | "TOGGLE" | "NUMBER" | "DATE" | "DROPDOWN" | "UPLOAD" | "OBJECT_CONNECT"; /** * String representation of a long text characteristic value from Resource Management. * @category Resource Management Objects */ interface LongTextCharacteristicValue { value?: string; type: "LONG_TEXT"; } /** * String representation of a short text characteristic value from Resource Management. * @category Resource Management Objects */ interface ShortTextCharacteristicValue { value?: string; type: "SHORT_TEXT"; } /** * number representation of a number characteristic value from Resource Management. * @category Resource Management Objects */ interface NumberCharacteristicValue { value?: number; type: "NUMBER"; } /** * boolean representation of a checkbox characteristic value from Resource Management. * @category Resource Management Objects */ interface CheckboxCharacteristicValue { value?: boolean; type: "CHECKBOX"; } /** * Date representation of a date characteristic value from Resource Management. * @category Resource Management Objects */ interface DateCharacteristicValue { value?: Date; type: "DATE"; } /** * Array of ids and values of dropdown characteristic selected options from Resource Management. * @category Resource Management Objects */ interface DropdownCharacteristicValue { value?: Array<{ /** * The id of the dropdown option from the list structure */ id?: string; /** * The value of the dropdown option from the list structure */ value?: string; }>; type: "DROPDOWN"; } /** * Array of connected objects of an object connect characteristic from Resource Management. * Including each connected object's objectId, listId and displayValue. * @category Resource Management Objects */ interface ObjectConnectCharacteristicValue { value?: Array>; type: "OBJECT_CONNECT"; } /** * boolean representation of a toggle characteristic value from Resource Management. * @category Resource Management Objects */ interface ToggleCharacteristicValue { value?: boolean; type: "TOGGLE"; } /** * Array of uploaded file details in an Upload characteristic value from Resource Management. * Including each file's fileId, fileName and mimeType. * @category Resource Management Objects */ interface UploadCharacteristicValue { value?: Array<{ fileId: string; fileName: string; mimeType: string; }>; type: "UPLOAD"; } /** * Unique identifier for a characteristic in Resource Management objects. * Format follows the pattern `{TYPE}_{number}` where TYPE indicates the characteristic type. * * @example * ```ts * const stringChar: CharacteristicId = "STRING_1"; * const numberChar: CharacteristicId = "NUMBER_42"; * const objectConnectChar: CharacteristicId = "OBJECT_CONNECT_5"; * const booleanChar: CharacteristicId = "BOOLEAN_3"; * const dateChar: CharacteristicId = "DATE_7"; * const listChar: CharacteristicId = "LIST_10"; * const uploadChar: CharacteristicId = "UPLOAD_2"; * ``` * @category Resource Management Objects */ type CharacteristicId = `STRING_${number}` | `OBJECT_CONNECT_${number}` | `BOOLEAN_${number}` | `NUMBER_${number}` | `DATE_${number}` | `LIST_${number}` | `UPLOAD_${number}`; /** * Maps characteristic IDs to their corresponding value types in Resource Management objects. * Each characteristic ID pattern (e.g., `STRING_${number}`) maps to its appropriate value interface. * * @remarks * This type provides type-safe access to characteristic values based on their ID format. * The conditional type mapping ensures that STRING characteristics map to text values, * BOOLEAN characteristics map to checkbox/toggle values, etc. * * @example * ```ts * const characteristics: CharacteristicIdToCharacteristicValue = { * STRING_1: { value: "Product name" }, * NUMBER_2: { value: 42 }, * BOOLEAN_3: { value: true }, * DATE_4: { value: new Date("2024-01-01") }, * LIST_5: { value: [{ id: "opt_1", value: "Option A" }] }, * OBJECT_CONNECT_6: { value: [{ listId: "list_1", objectId: "obj_1", displayValue: "Connected Item" }] }, * UPLOAD_7: { value: [{ fileId: "file_1", fileName: "document.pdf", mimeType: "application/pdf" }] }, * }; * ``` * @category Resource Management Objects */ type CharacteristicIdToCharacteristicValue = { [K in CharacteristicId]: K extends `STRING_${number}` ? ShortTextCharacteristicValue | LongTextCharacteristicValue : K extends `OBJECT_CONNECT_${number}` ? ObjectConnectCharacteristicValue : K extends `BOOLEAN_${number}` ? CheckboxCharacteristicValue | ToggleCharacteristicValue : K extends `NUMBER_${number}` ? NumberCharacteristicValue : K extends `DATE_${number}` ? DateCharacteristicValue : K extends `LIST_${number}` ? DropdownCharacteristicValue : K extends `UPLOAD_${number}` ? UploadCharacteristicValue : never }; /** * Maps characteristic types to their corresponding value interfaces. * Used internally for type-safe characteristic value mapping based on the characteristic type. * * @remarks * This utility type ensures that each characteristic type (SHORT_TEXT, NUMBER, etc.) * maps to its correct value interface. It's primarily used by other mapping types * like {@link CharacteristicNameToCharacteristicValue}. * * @example * ```ts * type ShortTextValue = CharacteristicTypeToValue["SHORT_TEXT"]; * type NumberValue = CharacteristicTypeToValue["NUMBER"]; * ``` * @category Resource Management Objects */ type CharacteristicTypeToValue = { SHORT_TEXT: ShortTextCharacteristicValue; LONG_TEXT: LongTextCharacteristicValue; OBJECT_CONNECT: ObjectConnectCharacteristicValue; CHECKBOX: CheckboxCharacteristicValue; TOGGLE: ToggleCharacteristicValue; NUMBER: NumberCharacteristicValue; DATE: DateCharacteristicValue; DROPDOWN: DropdownCharacteristicValue; UPLOAD: UploadCharacteristicValue; }; /** * Maps characteristic names to their update value types for a specific list. * Used internally for type-safe update operations. * * @typeParam Name - The name of the list * * @category Resource Management Types */ type CharacteristicNameToCharacteristicValue = { [K in keyof CharacteristicNameToTypeAndId]: CharacteristicNameToTypeAndId[K] extends { type: infer T extends CharacteristicType; } ? CharacteristicTypeToValue[T] : never }; /** * Represents an object from a Resource Management list with all its characteristic values. * * @remarks * The values are mapped to characteristic names (not IDs) for easier access. * Each characteristic's value is typed according to its definition in the list structure. * * @typeParam Name - The name of the list this object belongs to * * @example * ```ts * const employee: ObjectValues<"Employees"> = { * id: "emp_123", * listId: "list_456", * validationState: "VALID", * values: { * "Full Name": { value: "Jane Doe", type: "SHORT_TEXT" }, * "Salary": { value: 750, type: "NUMBER" }, * "Start Date": { value: new Date("2024-01-15"), type: "DATE" } * } * }; * ``` * * @category Resource Management Objects */ type ObjectValues = { id: string; listId: string; validationState: "VALID" | "REQUIRED_CHARACTERISTIC_MISSING"; values: CharacteristicNameToCharacteristicValue; version?: number; }; /** * Base properties shared by all characteristic definitions. * * @category Resource Management Characteristics */ type BaseCharacteristicDefinition = { id: string; name: string; type: CharacteristicType; required?: boolean; locked?: boolean; hidden?: boolean; unique?: boolean; }; /** * Definition for a short text characteristic (single line text input). * * @category Resource Management Characteristics */ type ShortTextCharacteristicDefinition = BaseCharacteristicDefinition & { type: "SHORT_TEXT"; }; /** * Definition for a long text characteristic (multi-line text area). * * @category Resource Management Characteristics */ type LongTextCharacteristicDefinition = BaseCharacteristicDefinition & { type: "LONG_TEXT"; }; /** * Definition for a number characteristic (numeric input). * * @category Resource Management Characteristics */ type NumberCharacteristicDefinition = BaseCharacteristicDefinition & { type: "NUMBER"; }; /** * Definition for a checkbox characteristic (boolean checkbox). * * @category Resource Management Characteristics */ type CheckboxCharacteristicDefinition = BaseCharacteristicDefinition & { type: "CHECKBOX"; }; /** * Definition for a date characteristic (date picker). * * @category Resource Management Characteristics */ type DateCharacteristicDefinition = BaseCharacteristicDefinition & { type: "DATE"; }; /** * Definition for a dropdown characteristic with predefined options. * * @category Resource Management Characteristics */ type DropdownCharacteristicDefinition = BaseCharacteristicDefinition & { type: "DROPDOWN"; options: { id: string; value: string; }[]; multiSelect?: boolean; }; /** * Definition for an upload characteristic (file attachment). * * @category Resource Management Characteristics */ type UploadCharacteristicDefinition = BaseCharacteristicDefinition & { type: "UPLOAD"; multiUpload?: boolean; }; /** * Configuration for characteristics referenced by an object connect. * Specifies which characteristics from connected objects should be accessible. * * @category Resource Management Characteristics */ type ObjectConnectReferencedCharacteristicDefinition = { listId: string; referencedCharacteristics?: { sectionId: string; characteristicId: string; }[]; }; /** * Definition for an object connect characteristic (reference to objects in other lists). * * @category Resource Management Characteristics */ type ObjectConnectCharacteristicDefinition = BaseCharacteristicDefinition & { type: "OBJECT_CONNECT"; options: ObjectConnectReferencedCharacteristicDefinition[]; multiSelect?: boolean; }; /** * Definition for a toggle characteristic (boolean switch/toggle). * * @category Resource Management Characteristics */ type ToggleCharacteristicDefinition = BaseCharacteristicDefinition & { type: "TOGGLE"; }; /** * Union type of all possible characteristic definitions. * * @category Resource Management Characteristics */ type CharacteristicDefinition = ShortTextCharacteristicDefinition | LongTextCharacteristicDefinition | NumberCharacteristicDefinition | CheckboxCharacteristicDefinition | DateCharacteristicDefinition | DropdownCharacteristicDefinition | UploadCharacteristicDefinition | ObjectConnectCharacteristicDefinition | ToggleCharacteristicDefinition; /** * A section within a list, grouping related characteristics together. * * @category Resource Management Lists */ type SectionStructure = { id?: string; name: string; characteristics?: CharacteristicDefinition[]; }; /** * Complete structure definition of a Resource Management list. * Includes all sections and their characteristics. * * @category Resource Management Lists */ type ListStructure = { id: string; name: string; createdOn: string; updatedOn: string; sections: SectionStructure[]; }; /** * Value payload for updating a toggle characteristic. * * @category Resource Management Updates */ type UpdateToggleCharacteristicValue = { value?: boolean; }; /** * Value payload for updating a short text characteristic. * * @category Resource Management Updates */ type UpdateShortTextCharacteristicValue = { value?: string; }; /** * Value payload for updating a long text characteristic. * * @category Resource Management Updates */ type UpdateLongTextCharacteristicValue = { value?: string; }; /** * Value payload for updating a number characteristic. * * @category Resource Management Updates */ type UpdateNumberCharacteristicValue = { value?: number; }; /** * Value payload for updating a date characteristic. * * @category Resource Management Updates */ type UpdateDateCharacteristicValue = { value?: Date; }; /** * Value payload for updating a checkbox characteristic. * * @category Resource Management Updates */ type UpdateCheckboxCharacteristicValue = { value?: boolean; }; /** * Reference to an object in another list for object connect characteristics. * * @category Resource Management Updates */ type UpdateObjectReferenceDTO = { listId: string; objectId: string; }; /** * Value payload for updating an object connect characteristic. * * @category Resource Management Updates */ type UpdateObjectConnectCharacteristicValue = { value?: UpdateObjectReferenceDTO[]; }; /** * Metadata for an uploaded file. * * @category Resource Management Updates */ type UploadedFileDTO = { fileId: string; fileName: string; mimeType: string; }; /** * Value payload for updating an upload characteristic. * * @category Resource Management Updates */ type UpdateUploadCharacteristicValue = { value?: UploadedFileDTO[]; }; /** * Value payload for updating a dropdown characteristic. * * @category Resource Management Updates */ type UpdateDropdownCharacteristicValue = { value?: { id: string; value: string; }[]; }; /** * Maps characteristic types to their corresponding update value types. * Used internally for type-safe updates. * * @category Resource Management Updates */ type CharacteristicTypeToUpdateCharacteristicValue = { SHORT_TEXT: UpdateShortTextCharacteristicValue; LONG_TEXT: UpdateLongTextCharacteristicValue; OBJECT_CONNECT: UpdateObjectConnectCharacteristicValue; CHECKBOX: UpdateCheckboxCharacteristicValue; TOGGLE: UpdateToggleCharacteristicValue; NUMBER: UpdateNumberCharacteristicValue; DATE: UpdateDateCharacteristicValue; DROPDOWN: UpdateDropdownCharacteristicValue; UPLOAD: UpdateUploadCharacteristicValue; }; /** * Maps characteristic names to their type and ID information for a specific list. * Used internally for type inference. * * @typeParam Name - The name of the list * * @category Resource Management Types */ type CharacteristicNameToTypeAndId = { [C in ListNameToStructureRegistry[Name]["sections"][number]["characteristics"][number] as C["name"]]: { type: C["type"]; id: C["id"]; } }; /** * Maps characteristic names to their update value types for a specific list. * Used internally for type-safe update operations. * * @typeParam Name - The name of the list * * @category Resource Management Types */ type CharacteristicNameToUpdateCharacteristicValue = { [K in keyof CharacteristicNameToTypeAndId]: CharacteristicNameToTypeAndId[K] extends { type: infer T extends CharacteristicType; } ? CharacteristicTypeToUpdateCharacteristicValue[T] : never }; /** * Request payload for creating or updating an object in a list. * Only include the characteristics you want to update - partial updates are supported. * * @typeParam Name - The name of the list * * @example * ```ts * const updateRequest: UpdateObjectRequest<"Products"> = { * values: { * "Product Name": { value: "Premium Widget" }, * "Price": { value: 49.99 }, * "In Stock": { value: true } * } * }; * ``` * * @category Resource Management Updates */ type UpdateObjectRequest = { values: { [K in keyof CharacteristicNameToUpdateCharacteristicValue]?: CharacteristicNameToUpdateCharacteristicValue[K] }; }; /** * Represents a paginated response of objects from a Resource Management list. */ interface ListObjectsPage { size: number; content: ObjectValues[]; number: number; first: boolean; last: boolean; numberOfElements: number; empty: boolean; /** * Returns the next page of results, or `undefined` if this is the last page. */ getNextPage(): ListObjectsPage | undefined; } /** * @category Resource Management Objects */ interface GetObjectsRequest { sort?: string | string[]; page?: number; } /** * Client for performing CRUD operations on objects within a specific list. * * @typeParam Name - The name of the list this client operates on * * @category Resource Management Client */ interface ListObjectsClient { /** * Retrieves a single object by its ID. * * @param objectId - The unique identifier of the object * @returns The object with all its characteristic values */ getObject(objectId: string): ObjectValues; /** * Creates a new object in the list. * * @param request - The characteristic values for the new object * @returns The object with all its characteristic values */ createObject(request: UpdateObjectRequest): ObjectValues; /** * Updates an existing object in the list. * * @param objectId - The unique identifier of the object to update * @param request - The characteristic values to update (partial updates supported) * @returns The updated object with all current values */ updateObject(objectId: string, request: UpdateObjectRequest): ObjectValues; /** * Retrieves a page of objects from the list. * @param request * @returns A page of objects with all characteristic values */ getObjects(request?: GetObjectsRequest): ListObjectsPage; } /** * Main client for interacting with Resource Management. * Provides access to list-specific clients for performing operations on lists and their objects. * * @example * ```ts * // Access via the PDK API * const client = api.createResourceManagementClient(); * const employees = client.listObjectsClient("Employees"); * // Get an employee * const employee = employees.getObject("674a1b2c3d4e5f6g7h8i9j0k"); * console.log(employee.values["Employee Name"]?.value); * * // Query employees in Engineering * const engineeringTeam = employees.getObjects({ * search: "Engineering", * limit: 50 * }); * * // Create a new employee * const newHire = employees.createObject({ * values: { * "Employee Name": { value: "Alice Johnson" }, * "Department": { value: [{ id: "dept_eng", value: "Engineering" }] }, * "Start Date": { value: new Date("2024-03-01") }, * "Salary": { value: 950 } * } * }); * ``` * @category Resource Management Objects */ interface ResourceManagementClient { /** * Creates a type-safe client for operations on a specific list. * The client provides full IntelliSense support for characteristic names and types * based on the list structure registered for this workflow. * * @typeParam Name - The name of the list (must be a registered list name) * @param listName - The name of the list to create a client for * @returns A client for performing CRUD operations on the specified list * @throws Error if the list does not exist or cannot be accessed */ listObjectsClient(listName: Name): ListObjectsClient; /** * Searches for objects in lists specified in the request payload. * Returns a paged response containing all matching objects. * @example * ```typescript * * const client = api.createResourceManagementClient(); * client.searchObjects({ * searchQueries: [ * {listName: "Employees", query: "Peter", characteristicName: "first name", operator: "EQUALS"} * ] * }); * ``` * * @returns The first page of matching objects * @param request */ searchObjects(request: SearchObjectRequest): ListObjectsPage; } interface SearchObjectRequest { page?: number; searchQueries: ListObjectSearchRequest[]; } /** * Request payload for searching objects in a specific list. */ interface ListObjectSearchRequest { listName: Name; query: string; operator: "EQUALS" | "LESS_THAN" | "LESS_THAN_EQUAL" | "GREATER_THAN" | "GREATER_THAN_EQUAL" | "STARTS_WITH" | "ENDS_WITH" | "CONTAINS" | "IN"; characteristicName: keyof CharacteristicNameToTypeAndId; } //#endregion //#region src/tasks.d.ts /** * Boolean task * @category Tasks */ type CheckboxTaskValue = { value: boolean | null; }; /** * Contact selection task including users and teams. * @category Tasks */ type ContactsTaskValue = { value: ConcreteContact[] | null; }; /** * Union of every contact variant that may show up in tasks. * @category Tasks */ type ConcreteContact = Team | User; /** * Representation of a Flowers team. * @category Workflow */ type Team = { refContactId: string; name: string; type: "TEAM"; }; /** * Representation of a Flowers user. * @category Workflow */ type User = { refContactId: string; name: string; email: string; type: "USER"; }; /** * Date task capturing a deadline or reminder. * @category Tasks */ type DateTaskValue = { value: Date | null; }; /** * Files attached to a task, resolved to {@link Document} metadata. * @category Tasks */ type FilesTaskValue = { value: Document[] | null; }; /** * Numeric task enriched with a pre-formatted string for display. * @category Tasks */ type NumberTaskValue = { value: number | null; formattedValue: string | null; }; /** * Object-connect tasks map to a list of referenced objects. * @category Tasks */ type ObjectConnectTaskValue = { value: ConnectedObject[]; }; /** * Row of dropdown task. * If the UI shows 3 columns, this will be an array of 3 strings. * @category Tasks */ type OptionsTaskValue = { value: string[] | null; }; /** * String value used by both short and long text tasks. * @category Tasks */ type StringOrTextTaskValue = { value: string | null; }; /** * Explicit yes/no answer task with optional `null` for empty tasks. * @category Tasks */ type YesOrNoTaskValue = { value: "YES" | "NO" | null; }; /** * Metadata describing an uploaded document. * @category Workflow */ interface Document { id: string; name: string; fileName: string; size: number; mimeType: string; } /** * Minimal information required to reference a connected object inside the PDK. * @category Tasks */ interface ConnectedObject { listId: string; objectId: string; displayValue: string; objectSnapshot: CharacteristicIdToCharacteristicValue; } /** * Union of every task value that can be read from the API. * * @example * ```ts * const readableByType: Record = { * STRING: { value: "Reference number" }, * TEXT: { value: "Detailed installation instructions" }, * NUMBER: { value: 1200, formattedValue: "$1,200.00" }, * CHECKBOX: { value: true }, * YES_NO: { value: "YES" }, * OPTIONS: { value: ["standard", "support"] }, * DATE: { value: new Date("2024-09-01") }, * CONTACTS: { * value: [ * { * refContactId: "user_123", * name: "Ada Lovelace", * email: "ada@example.com", * type: "USER", * }, * ], * }, * FILE: { * value: [ * { * id: "doc_42", * name: "Proposal.pdf", * fileName: "proposal.pdf", * size: 1024, * mimeType: "application/pdf", * }, * ], * }, * OBJECT_CONNECT: { * value: [{ listId: "6514ff1c0f8ffc40d8f4342f", objectId: "6614ff1c0f8ffc40d8f4342f", displayValue: "Acme Corp" }], * }, * }; * ``` * @category Tasks */ type TaskValue = CheckboxTaskValue | ContactsTaskValue | DateTaskValue | FilesTaskValue | NumberTaskValue | ObjectConnectTaskValue | OptionsTaskValue | StringOrTextTaskValue | YesOrNoTaskValue; /** * High-level task categories exposed by the UI and the PDK. * * ```text * (TaskType) ───────┐ * "STRING" │ ┌───────────────────────┐ * "NUMBER" ├──▶│ TaskTypeToTaskValue │──▶ reader shape * "OBJECT_CONNECT"│ └───────────────────────┘ * ... │ ┌───────────────────────┐ * └──▶│ TaskTypeToModifyTaskValue│──▶ writer shape * └───────────────────────┘ * ``` * * @category Tasks */ type TaskType = "STRING" | "TEXT" | "NUMBER" | "CHECKBOX" | "YES_NO" | "OPTIONS" | "DATE" | "CONTACTS" | "FILE" | "OBJECT_CONNECT"; /** * Contact-centric writer shape. Accepts references by `name` or `refContactId`. * @category Tasks */ type ModifyContactsTaskValue = { value: SearchableContact[] | null; }; /** * File writer variant only cares about already-uploaded document identifiers. * @category Tasks */ type ModifyFilesTaskValue = { value: Pick[] | null; }; /** * Simplified contact lookup that mirrors Flowers search behaviour. * @category Tasks */ type SearchableContact = Pick | Pick; /** * Writer shape for object-connect tasks. * @category Tasks */ type ModifyObjectConnectTaskValue = { value: Pick[]; }; /** * Number writer variant. * @category Tasks */ type ModifyNumberTaskValue = Pick; interface TaskNameToTypeRegistry {} /** * Every registered task name in the Flow. * @category Tasks */ type TaskName = keyof TaskNameToTypeRegistry; /** * Maps task types to writer-compatible shapes. * @category Tasks */ type TaskTypeToModifyTaskValue = { [K in TaskType]: K extends "CHECKBOX" ? CheckboxTaskValue : K extends "CONTACTS" ? ModifyContactsTaskValue : K extends "DATE" ? DateTaskValue : K extends "FILE" ? ModifyFilesTaskValue : K extends "NUMBER" ? ModifyNumberTaskValue : K extends "OBJECT_CONNECT" ? ModifyObjectConnectTaskValue | StringOrTextTaskValue : K extends "OPTIONS" ? OptionsTaskValue : K extends "STRING" ? StringOrTextTaskValue : K extends "TEXT" ? StringOrTextTaskValue : K extends "YES_NO" ? YesOrNoTaskValue : never }; /** * Maps task types to reader-friendly shapes. * @category Tasks */ type TaskTypeToTaskValue = { [K in TaskType]: K extends "CHECKBOX" ? CheckboxTaskValue : K extends "CONTACTS" ? ContactsTaskValue : K extends "DATE" ? DateTaskValue : K extends "FILE" ? FilesTaskValue : K extends "NUMBER" ? NumberTaskValue : K extends "OBJECT_CONNECT" ? ObjectConnectTaskValue : K extends "OPTIONS" ? OptionsTaskValue : K extends "STRING" ? StringOrTextTaskValue : K extends "TEXT" ? StringOrTextTaskValue : K extends "YES_NO" ? YesOrNoTaskValue : never }; type TaskNameToModifyTaskValue> = { [K in keyof Reg]: TaskTypeToModifyTaskValue[Reg[K]] }; type TaskNameToTaskValue> = { [K in keyof Reg]: TaskTypeToTaskValue[Reg[K]] }; /** * Entrypoint for narrowing {@link TaskName} to an update payload. * * @remarks * The editor injects the concrete mapping through module augmentation so the editor can offer * autocomplete and type-safe conversions. * @category Tasks */ type TaskNameToModifyTaskValueMap = TaskNameToModifyTaskValue; /** * Entrypoint for narrowing {@link TaskName} to a read payload. * @category Tasks */ type TaskNameToValueMap = TaskNameToTaskValue; /** * Generic update payload accepted by {@link PdkApi.updateTaskValueByName} when the task name is unknown. * * @example * ```ts * const payloadByType: Partial> = { * CHECKBOX: { value: true }, * CONTACTS: { value: [{ refContactId: "user_123" }] }, * DATE: { value: new Date("2024-01-01") }, * FILE: { value: [{ id: "doc_42" }] }, * NUMBER: { value: 499 }, * OBJECT_CONNECT: { value: [{ listId: "6514ff1c0f8ffc40d8f4342f", objectId: "6614ff1c0f8ffc40d8f4342f" }] }, * OPTIONS: { value: ["1", "2"] }, * STRING: { value: "Reference number" }, * TEXT: { value: "Detailed installation instructions" }, * YES_NO: { value: "YES" }, * }; * ``` * @category Tasks */ type ModifyTaskValue = CheckboxTaskValue | ModifyContactsTaskValue | DateTaskValue | ModifyFilesTaskValue | ModifyNumberTaskValue | ModifyObjectConnectTaskValue | OptionsTaskValue | StringOrTextTaskValue | YesOrNoTaskValue; //#endregion //#region src/http.d.ts /** * Shape of primitive JSON values accepted by the Flowers HTTP bridge. * @category HTTP */ type JsonPrimitive = string | number | boolean | null; /** * Recursively describes JSON payloads that may be sent or received through Flowers. * @category HTTP */ type JsonValue = JsonPrimitive | { [key: string]: JsonValue; } | { toJSON: () => unknown; } | TaskValue | JsonValue[]; /** * Enumerates the transport-friendly payload groups that the synchronous HTTP client understands. * * ```text * ┌──────────────────────────┐ * │ Flowers HTTP Bridge │ * ├──────────────────────────┤ * │ "json" → JSON Value │ * Incoming Body Type ─────┤ "text" → string blob │ * │ "binary" → raw bytes │ * │ "form-urlencoded" │ * │ "multipart" │ * └──────────────────────────┘ * ``` * * @remarks * Use {@link BodyInput} to produce the strongly-typed payload object that matches one of these kinds. * @category HTTP */ type BodyKind = "json" | "text" | "binary" | "form-urlencoded" | "multipart"; /** * Key-value pairs encoded as `application/x-www-form-urlencoded` fields. * @category HTTP */ type FormUrlEncodedFields = Record; /** * Individual parts that compose a `multipart/form-data` payload. * @category HTTP */ type MultipartField = { type: "text"; name: string; content: string; contentType?: string; } | { type: "file"; name: string; content: ArrayBuffer | Uint8Array; filename?: string; contentType?: string; }; /** * Maps each {@link BodyKind} to the minimal shape required by {@link HttpClient} helpers. * @category HTTP */ type BodyInputMap = { json: JsonValue; text: { content: string; contentType?: string; }; binary: { content: ArrayBuffer | Uint8Array; contentType?: string; }; "form-urlencoded": { fields: FormUrlEncodedFields; }; multipart: { fields: MultipartField[]; }; }; /** * Resolves to the correct payload interface depending on the declared {@link BodyKind}. * * @example * ```typescript * import type { BodyInput } from "@flowers-software/pdk-types"; * * function buildBinaryBody(): BodyInput<"binary"> { * return { * content: new Uint8Array([0xde, 0xad, 0xbe, 0xef]), * contentType: "application/octet-stream" * }; * } * ``` * @category HTTP */ type BodyInput = BodyInputMap[TKind]; /** * Synchronous response wrapper returned by the HTTP bridge. * * @remarks * Responses expose convenience readers (`json`, `text`, `bytes`) that convert the * underlying QuickJS buffers into typed data on demand. These readers are synchronous * because plugin execution happens inside a cooperative runtime. * @category HTTP */ interface HttpResponse { readonly status: number; readonly statusText: string; readonly headers: Record; readonly ok: boolean; json(): T$1; text(): string; bytes(): ArrayBuffer; } /** * Optional configuration supplied when instantiating a client via {@link PdkApi.http}. * @category HTTP */ interface HttpClientConfig { baseUrl?: string; defaultHeaders?: Record; } /** * Per-request parameters understood by the Flowers HTTP bridge. * @category HTTP */ interface HttpRequestOptions { headers?: Record; queryParams?: Record; } /** * Thin wrapper over the Flowers synchronous HTTP transport. * * @example * ```typescript * export default definePlugin({ * onAutomationActionExecution(api) { * const http = api.http({ baseUrl: "https://api.example.dev" }); * * const response = http.post("/items/create", { * reference: "FLOW-42", * status: "ACTIVE" * }); * * if (!response.ok) { * throw new Error(`Failed to create item: ${response.statusText}`); * } * } * }); * ``` * * @category HTTP */ interface HttpClient { get(url: string, options?: HttpRequestOptions): HttpResponse; delete(url: string, options?: HttpRequestOptions): HttpResponse; post(url: string, body: BodyInput, options?: HttpRequestOptions): HttpResponse; put(url: string, body: BodyInput, options?: HttpRequestOptions): HttpResponse; patch(url: string, body: BodyInput, options?: HttpRequestOptions): HttpResponse; } //#endregion //#region src/workflow-step.d.ts /** * Registry populated via module augmentation that links step names to custom metadata. * * ```text * Step Builder ──────▶ StepNameRegistry (augmentation) * │ * ▼ * StepName (narrowed literals) * │ * ▼ * WorkflowStep objects * ``` * * @category Workflow */ interface StepNameRegistry {} /** * Every registered workflow step name. * @category Workflow */ type StepName = keyof StepNameRegistry; /** * Shape of a Flowers workflow step enriched with helper examples. * * @remarks * Values from `WorkflowStep` can be fed back into {@link PdkApi.updateTaskValueByName} without * additional transformations. * * @example * ```typescript * const billingSteps = api.getWorkflowStepsByName("billing-approval"); * const [step] = billingSteps; * * api.updateTaskValueByName("billing-team", { * value: step.responsibleTeams * }); * ``` * @category Workflow */ type WorkflowStep = { /** * Files attached to the workflow step. * To download a file, use the {@link PdkApi.downloadFile} method. * @example * const file = api.downloadFile(step.files[0].id); * * To be used as a parameter in the {@link PdkApi.updateTaskValueByName} method. * @example * api.updateTaskValueByName("file", { * value: step.files * }); * @see FilesTaskValue */ files: Document[]; /** * Contains the users responsible for the workflow step. * To be used as a parameter in the {@link PdkApi.updateTaskValueByName} method. * @example * api.updateTaskValueByName("contact-task", { * value: step.responsibleUsers * }); * @see ContactsTaskValue */ responsibleUsers: User[]; /** * Contains the teams responsible for the workflow step. * To be used as a parameter in the {@link PdkApi.updateTaskValueByName} method. * @example * api.updateTaskValueByName("contact-task", { * value: step.responsibleTeams * }); * @see ContactsTaskValue */ responsibleTeams: Team[]; /** * Deadline of the workflow step. * To be used as a parameter in the {@link PdkApi.updateTaskValueByName} method. * @example * api.updateTaskValueByName("date-task", { * value: step.deadline * }); * @see DateTaskValue */ deadline: Date; /** * Indicates whether the workflow step is completed. A completed step is immutable. */ completed: boolean; }; //#endregion //#region src/index.d.ts interface PdkApi { /** * Downloads a file from Flowers * @param fileId - The ID of the file to download * @returns The file content as an ArrayBuffer * * @example * ```typescript * const filesOnTasksWithName = api.getAllTaskValuesByName("file-task"); * const fileId = filesOnTasksWithName[0]?.value[0]?.id; * const fileContent = api.downloadFile(fileId); * ``` * */ downloadFile(fileId: string): ArrayBuffer; /** * Upload a file to Flowers * * @example * ```typescript * const imageUpload: UploadFileRequest = { * fileName: "iamge.png", * content: new ArrayBuffer(1024), * }; * api.uploadFile(imageUpload); * ``` * * @returns The uploaded Document metadata * @param request */ uploadFile(request: UploadFileRequest): Document; /** * Returns all task values by name, in case of subtasks, it will return an array of task values. * In most other cases, it will return an array with one element. * If more than one task is found, the types can diverge. * * @example * ```typescript * const [owner] = api.getAllTaskValuesByName("account-owner"); * if (owner?.value?.length) { * console.log(owner.value[0]?.name); * } * ``` * @param taskName * @returns An array of task values */ getAllTaskValuesByName(taskName: Name): TaskNameToValueMap[Name][]; /** * Returns all task values by name, in case of subtasks, it will return an array of task values. * In most other cases, it will return an array with one element. * If more than one task is found, the types can diverge. * * @example * ```typescript * const [owner] = api.getAllTaskValuesByName("account-owner"); * if (owner?.value?.length) { * console.log(owner.value[0]?.name); * } * ``` * @param taskName * @returns An array of task values */ getAllTaskValuesByName(taskName: string): TaskValue[]; /** * Updates a task value by name. * * Notes: * - Updates are enqueued and applied together at the end of plugin execution. * - A brief compatibility check runs when enqueued; if types mismatch, this may throw. * - If plugin execution fails or aborts, enqueued updates are discarded. * - Not every task is convertible to all task types. * * @example * ```typescript * api.updateTaskValueByName("approval-notes", { value: "Ready to ship" }); * ``` * * @throws Error if the task is not found or the value type is incorrect. * @param taskName * @param value - The new value for the task. * @param index - Optional index of the task value to update. Defaults to 0. */ updateTaskValueByName(taskName: Name, value: TaskNameToModifyTaskValueMap[Name], index?: number): void; /** * Updates a task value by name. * * Notes: * - Updates are enqueued and applied together at the end of plugin execution. * - Compatibility is briefly checked when enqueued; without a known `TaskName`, type mismatch may only be caught at runtime and may throw. * - If plugin execution fails or aborts, enqueued updates are discarded. * - Not every task is convertible to all task types. * * @example * ```typescript * api.updateTaskValueByName("approval-notes", { value: "Ready to ship" }); * ``` * @throws Error if the task is not found or the value type is incorrect. * @param taskName * @param value - The new value for the task. * @param index - Optional index of the task value to update. Defaults to 0. */ updateTaskValueByName(taskName: string, value: ModifyTaskValue, index?: number): void; /** * * Notes: * - this might return more than one item if there are multiple steps with the same name * @param stepName * @returns list of workflow steps by name */ getWorkflowStepsByName(stepName: Name): WorkflowStep[]; /** * * Notes: * - this might return more than one item if there are multiple steps with the same name * @param stepName * @returns list of workflow steps by name */ getWorkflowStepsByName(stepName: string): WorkflowStep[]; /** * Returns a synchronous HTTP client instance * @param config - Optional configuration for the HTTP client * @returns HttpClient instance for making synchronous HTTP requests */ http(config?: HttpClientConfig): HttpClient; /** * Creates a Resource Management client for interacting with Lists and their Objects. * * @remarks * This method automatically injects authentication tokens and configures the base URL * for Resource Management API access. The returned client provides type-safe access * to lists and their objects with full autocomplete support. * * @param config - Optional HTTP client configuration. If not provided, uses default * settings with automatic authentication and base URL configuration. * * * @example * ```typescript * const client = api.createResourceManagementClient(); * const employeesClient = client.listObjectsClient("Employees"); * ``` * * @returns ResourceManagementClient instance for accessing lists and objects */ createResourceManagementClient(config?: HttpClientConfig): ResourceManagementClient; } interface UserPlugin { onAutomationActionExecution?(api: PdkApi, ctx: HostedCodeExecutionContext): void; } type HostedCodeExecutionContext = { customerId: string; workflowId: string; details: WorkflowExecutionDetails; }; type WorkflowExecutionDetails = { /** * flow name of the workflow that is being executed */ referenceFlowName: string; /** * name of the workflow that is being executed */ workflowName: string; /** * id of the workflow that is being executed */ workflowId: string; /** * name of the process step that is being executed */ sourceObjectName: string; /** * external reference key of the workflow that is being executed */ workflowExternalReferenceKey: string; /** * subject of the email that created the workflow */ workflowCreatorEmailSubject?: string; /** * body of the email that created the workflow */ workflowCreatorEmailBody?: string; /** * send of the email that created the workflow */ workflowCreatorEmailSender?: string; /** flow id of the workflow that is being executed */ referenceFlowId: string; }; /** * Flowers Plugin Development Kit (PDK) Types * * This package exposes the `definePlugin` helper alongside runtime contracts such as {@link PdkApi} * and {@link HostedCodeExecutionContext} so plugins can stay type-safe. * * @example * ```typescript * import { * definePlugin, * type HostedCodeExecutionContext, * type PdkApi, * } from "@flowers-software/pdk-types"; * * export default definePlugin({ * onAutomationActionExecution(api: PdkApi, ctx: HostedCodeExecutionContext) { * const [owner] = api.getAllTaskValuesByName("account-owner"); * * if (owner?.value?.length) { * api.updateTaskValueByName("account-owner", { value: owner.value }); * } * }, * }); * ``` * * Flowers plugins run inside QuickJS with no access to Node or browser globals. * Additionally, async functions are not supported, so you must use synchronous code. * * @packageDocumentation */ /** * Declares a Flowers plugin while preserving strong typing for user-defined handlers. */ declare function definePlugin(plugin: TPlugin): TPlugin; //#endregion export { BaseCharacteristicDefinition, BodyInput, BodyInputMap, BodyKind, CharacteristicDefinition, CharacteristicId, CharacteristicIdToCharacteristicValue, CharacteristicNameToCharacteristicValue, CharacteristicNameToTypeAndId, CharacteristicNameToUpdateCharacteristicValue, CharacteristicType, CharacteristicTypeToUpdateCharacteristicValue, CharacteristicTypeToValue, CheckboxCharacteristicDefinition, CheckboxCharacteristicValue, CheckboxTaskValue, ConcreteContact, ConnectedObject, ContactsTaskValue, DateCharacteristicDefinition, DateCharacteristicValue, DateTaskValue, Document, DropdownCharacteristicDefinition, DropdownCharacteristicValue, FilesTaskValue, FormUrlEncodedFields, GetObjectsRequest, HostedCodeExecutionContext, HttpClient, HttpClientConfig, HttpRequestOptions, HttpResponse, JsonPrimitive, JsonValue, ListName, ListNameToStructureRegistry, ListObjectSearchRequest, ListObjectsClient, ListObjectsPage, ListStructure, LongTextCharacteristicDefinition, LongTextCharacteristicValue, ModifyContactsTaskValue, ModifyFilesTaskValue, ModifyNumberTaskValue, ModifyObjectConnectTaskValue, ModifyTaskValue, MultipartField, NumberCharacteristicDefinition, NumberCharacteristicValue, NumberTaskValue, ObjectConnectCharacteristicDefinition, ObjectConnectCharacteristicValue, ObjectConnectReferencedCharacteristicDefinition, ObjectConnectTaskValue, ObjectValues, OptionsTaskValue, PdkApi, ResourceManagementClient, SearchObjectRequest, SearchableContact, SectionStructure, ShortTextCharacteristicDefinition, ShortTextCharacteristicValue, StepName, StepNameRegistry, StringOrTextTaskValue, TaskName, TaskNameToModifyTaskValueMap, TaskNameToTypeRegistry, TaskNameToValueMap, TaskType, TaskTypeToModifyTaskValue, TaskTypeToTaskValue, TaskValue, Team, ToggleCharacteristicDefinition, ToggleCharacteristicValue, UpdateCheckboxCharacteristicValue, UpdateDateCharacteristicValue, UpdateDropdownCharacteristicValue, UpdateLongTextCharacteristicValue, UpdateNumberCharacteristicValue, UpdateObjectConnectCharacteristicValue, UpdateObjectReferenceDTO, UpdateObjectRequest, UpdateShortTextCharacteristicValue, UpdateToggleCharacteristicValue, UpdateUploadCharacteristicValue, UploadCharacteristicDefinition, UploadCharacteristicValue, UploadFileRequest, UploadedFileDTO, User, UserPlugin, WorkflowExecutionDetails, WorkflowStep, YesOrNoTaskValue, definePlugin };