UNPKG

@adobe/genstudio-extensibility-sdk

Version:
102 lines (101 loc) 4.25 kB
"use strict"; /* Copyright 2025 Adobe. All rights reserved. This file is licensed to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ValidationExtensionService = exports.ValidationExtensionServiceError = void 0; class ValidationExtensionServiceError extends Error { constructor(message) { super(message); this.name = "ValidationExtensionServiceError"; } } exports.ValidationExtensionServiceError = ValidationExtensionServiceError; /** * Manages experience data conversion and retrieval */ class ValidationExtensionService { /** * Opens the validation extension * @param connection - The guest connection to the host * @param extensionId - The ID of the extension to open * @throws Error if connection is missing */ static open(connection, extensionId) { if (!connection) { throw new ValidationExtensionServiceError("Connection is required to open validation extension"); } try { // @ts-ignore Remote API is handled through postMessage connection.host.api.validationExtension.open(extensionId); } catch (error) { throw new ValidationExtensionServiceError("Failed to open validation extension"); } } /** * Fetches experiences from the connection * @param connection - The guest connection to the host * @returns Promise<Experience[]> Array of converted experiences * @throws Error if connection is missing * * In non-HTML canvas, variants are flattened into Experience and returned. Use getExperiencesWithVariants instead. */ static async getExperiences(connection) { if (!connection) { throw new ValidationExtensionServiceError("Connection is required to get experiences"); } try { // @ts-ignore Remote API is handled through postMessage return await connection.host.api.validationExtension.getExperiences(); } catch (error) { throw new ValidationExtensionServiceError("Failed to fetch experiences from host"); } } /** * Gets the generation context from the connection * @param connection - The guest connection to the host * @returns The generation context * @throws Error if connection is missing */ static async getGenerationContext(connection) { if (!connection) { throw new ValidationExtensionServiceError("Connection is required to get generation context"); } try { // @ts-ignore Remote API is handled through postMessage return await connection.host.api.validationExtension.getGenerationContext(); } catch (error) { throw new ValidationExtensionServiceError("Failed to get generation context"); } } /** * Updates a field value on the canvas. * @param connection - The guest connection to the host * @param fieldUpdate - The field update payload describing which field to change and the new value * @throws Error if connection is missing */ static updateField(connection, fieldUpdate) { if (!connection) { throw new ValidationExtensionServiceError("Connection is required to update field"); } try { // @ts-ignore Remote API is handled through postMessage connection.host.api.validationExtension.updateField(fieldUpdate); } catch (error) { throw new ValidationExtensionServiceError("Failed to update field"); } } } exports.ValidationExtensionService = ValidationExtensionService; //# sourceMappingURL=validation-extension-service.js.map