{"version":3,"file":"input.cjs","sources":["../../../../src/types/io/input.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD\n *\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n  CreateGroupRequest,\n  CreateGroupAPIResponse,\n  ESPRMBaseConfig,\n  ESPRMNode,\n  GetGroupsRequestParams,\n} from \"@espressif/rainmaker-base-sdk\";\nimport {\n  MatterControlErrorCodes,\n  MatterControlOperations,\n  MatterStatusTypes,\n  MatterNodeTypes,\n} from \"../../utils/constants\";\nimport { ESPRMFabric } from \"../../ESPRMFabric\";\nimport { ESPMatterControlAdapterInterface } from \"../../services/ESPMatterTransport/ESPMatterControlAdapterInterface\";\nimport { ESPMatterAdapter as ESPMatterSubscriptionAdapter } from \"../../services/ESPMatterSubscriptionChannel\";\nimport type { ClusterConfigMap } from \"../../config/cluster.types\";\nimport type { MatterControlResult } from \"./output\";\n\n/**\n * mDNS browse parameters for Matter local discovery.\n */\ninterface ESPMatterDiscoveryParamsInterface {\n  /** mDNS service type to browse, e.g. `_matter._tcp.`. */\n  serviceType: string;\n  /** mDNS domain, typically `local.`. */\n  domain: string;\n}\n\n/**\n * Local discovery adapter contract used by Matter SDK for operational discovery.\n * Application code can bridge this interface to React Native/native discovery modules.\n */\ninterface ESPMatterLocalDiscoveryAdapterInterface {\n  /**\n   * Start discovery and stream discovered payloads to callback.\n   * Returns an optional cleanup function to remove listeners.\n   */\n  startDiscovery(\n    callback: (data: Record<string, unknown>) => void,\n    params: ESPMatterDiscoveryParamsInterface\n  ): Promise<void | (() => void)> | void | (() => void);\n\n  /**\n   * Stop discovery for a specific service type (preferred for multi-browse setups).\n   */\n  stopDiscoveryForType?(\n    serviceType: string\n  ): Promise<void> | void;\n\n  /**\n   * Stop all active discovery sessions (fallback for adapters without per-type stop).\n   */\n  stopDiscovery?(): Promise<void> | void;\n\n  /**\n   * Register listener for discovery-lost payloads.\n   * Returns an optional cleanup function to remove listener.\n   */\n  addLostListener?(\n    callback: (data: Record<string, unknown>) => void,\n    params?: ESPMatterDiscoveryParamsInterface\n  ): Promise<void | (() => void)> | void | (() => void);\n}\n\n/**\n * Interface for CSR generation result from native platform.\n * This represents the payload returned by the native adapter's generateCSR method.\n */\ninterface ESPRMCSRGenerationResult {\n  /** The generated Certificate Signing Request in base64 format */\n  csr?: string;\n  /** Request body containing CSR requests array */\n  requestBody?: string;\n  /** Additional metadata from native platform */\n  metadata?: Record<string, any>;\n  /** Status of the CSR generation operation */\n  status?: string;\n}\n\n/**\n * Unified interface for NoC request event data from native platform.\n * The native adapter should normalize platform-specific formats to this standard structure.\n */\ninterface ESPRMNoCRequestEventData {\n  /** Event type identifier (always \"NODE_NOC_REQUEST\") */\n  eventType: string;\n  /** Standardized request data - adapters must convert platform formats to this structure */\n  requestData: {\n    /** Certificate Signing Request from device (base64 encoded) */\n    csr: string;\n    /** Device identifier */\n    deviceId: string;\n    /** Group/Fabric ID */\n    groupId: string;\n    /** Fabric ID */\n    fabricId: string;\n  };\n}\n\n/**\n * Unified interface for node confirmation request event data from native platform.\n * The native adapter should normalize platform-specific formats to this standard structure.\n */\ninterface ESPRMConfirmRequestEventData {\n  /** Event type identifier (always \"CONFIRM_REQUEST\") */\n  eventType: string;\n  /** Standardized confirmation data - adapters must convert platform formats to this structure */\n  requestData: {\n    /** ESP RainMaker node ID */\n    rainmakerNodeId: string;\n    /** Matter node ID */\n    matterNodeId: string;\n    /** Challenge response for authentication */\n    challengeResponse: string;\n    /** Optional original challenge, if provided by native layer */\n    challenge?: string;\n    /** Device identifier (should match NOC request) */\n    deviceId: string;\n    /** Request ID from the commissioning process */\n    requestId: string;\n    /** Optional metadata from native platform  */\n    metadata?: Record<string, any>;\n  };\n}\n\n/**\n * Interface for postMessage payload.\n * This provides type safety for data sent from SDK to native platform.\n */\ninterface ESPRMNativeDataPayload {\n  /** Type identifier for the data being sent (from MatterPostMessageTypes) */\n  type: string;\n  /** Payload data - structure varies based on type */\n  data: Record<string, any>;\n}\n\n/**\n * Interface for the request parameters of generateCSR method.\n * This interface defines the parameters required to generate a Certificate Signing Request (CSR)\n * for a Matter fabric.\n */\ninterface ESPRMGenerateCSRRequest {\n  /**\n   * The ID of the target Matter fabric group.\n   * This identifies which fabric the CSR request is targeting.\n   */\n  groupId: string;\n\n  /**\n   * The ID of the target Matter fabric.\n   * This identifies which fabric the CSR request is targeting.\n   */\n  fabricId: string;\n\n  /**\n   * The name of the target Matter fabric.\n   * This identifies which fabric the CSR request is targeting.\n   */\n  name: string;\n}\n\n/**\n * Enum for the status of the commissioning response.\n * This enum defines the possible statuses of the commissioning response.\n */\nenum ESPCommissioningResponseStatus {\n  /**\n   * The status of the commissioning response is in progress.\n   */\n  ON_PROGRESS = \"onProgress\",\n  /**\n   * The status of the commissioning response is successful.\n   */\n  SUCCESS = \"success\",\n  /**\n   * The status of the commissioning response is failed.\n   */\n  FAILED = \"failed\",\n}\n\n/**\n * Interface for the response parameters of commissioning method.\n * This interface defines the parameters required to respond to a commissioning request.\n */\ninterface ESPCommissioningResponse {\n  /**\n   * The status of the commissioning response.\n   * This indicates the success or failure of the commissioning operation.\n   */\n  status: ESPCommissioningResponseStatus;\n\n  /**\n   * The description of the commissioning response.\n   * This provides additional context about the success or failure of the commissioning operation.\n   */\n  description?: string;\n}\n\n/**\n * Interface for ESP Matter Commissioning Adaptor\n *\n * This interface defines the native platform methods for Matter commissioning operations.\n * The adaptor handles native operations and bidirectional communication between\n * the Matter SDK and native platform (Android/iOS).\n *\n * Communication pattern:\n * 1. generateCSR - Generate Certificate Signing Request using native secure storage\n * 2. startCommissioning - Start commissioning with event-based communication\n * 3. postMessage - Unified method to send typed data to native platform\n */\ninterface ESPMatterCommissioningAdaptorInterface {\n  /**\n   * Generate Certificate Signing Request using native secure storage\n   * This method coordinates with native platform (Android KeyStore / iOS Keychain)\n   * to generate CSR for Matter certificates\n   *\n   * @param fabricInfo - Fabric information for CSR generation\n   * @param fabricInfo.groupId - Group ID for the fabric\n   * @param fabricInfo.fabricId - Fabric ID for the CSR\n   * @param fabricInfo.name - Fabric name\n   * @returns Promise<ESPRMCSRGenerationResult> - CSR generation result\n   */\n  generateCSR(\n    fabricInfo: ESPRMGenerateCSRRequest\n  ): Promise<ESPRMCSRGenerationResult>;\n\n  /**\n   * Start Ecosystem device commissioning with event-based communication\n   * This method starts the native commissioning process and sets up event listeners\n   * for bidirectional communication between SDK and native platform\n   *\n   * @param onboardingPayload - Onboarding payload data\n   * @param fabric - Prepared fabric object\n   * @param onEvent - Callback function to handle events from native (NODE_NOC_REQUEST, COMMISSIONING_CONFIRMATION_REQUEST, etc.)\n   * @returns Promise<() => void> - Cleanup function to remove event listeners\n   */\n  startEcosystemCommissioning(\n    onboardingPayload: string,\n    fabric: ESPRMFabric,\n    onEvent: (\n      eventType: string,\n      data: ESPRMNoCRequestEventData | ESPRMConfirmRequestEventData\n    ) => void\n  ): Promise<() => void>;\n\n  /**\n   * Send typed data to native platform\n   * This unified method routes different types of data to appropriate native methods\n   * based on the data type (COMMISSIONING_CONFIRMATION_RESPONSE, ISSUE_NODE_NOC_RESPONSE, etc.)\n   *\n   * @param payload - Typed payload containing data type and data\n   * @param payload.type - Data type identifier for routing to correct native method\n   * @param payload.data - Actual data to send to native platform\n   * @returns Promise<any> - Native processing result\n   */\n  postMessage(payload: ESPRMNativeDataPayload): Promise<any>;\n}\n\n/**\n * Extended request parameters for {@link ESPRMUser.getGroups}.\n */\ninterface ESPRMGetGroupsRequestParams extends GetGroupsRequestParams {\n  /** When true, returns only Matter fabric groups (`is_matter`). */\n  fabricOnly?: boolean;\n  withFabricDetails?: boolean;\n  withNodeDetails?: boolean;\n  withMatterNodeList?: boolean;\n}\n\n/**\n * Optional query flags for {@link ESPRMUser.getFabricById}.\n * Same options as {@link ESPRMGetGroupsRequestParams}, excluding pagination and `fabricOnly`.\n */\ntype ESPRMGetFabricByIdRequestParams = Omit<\n  ESPRMGetGroupsRequestParams,\n  \"fabricOnly\" | \"resultCount\"\n>;\n\n/**\n * Interface for the request parameters of issueNodeNoC method.\n * This interface defines the parameters required to issue a Node Operational Certificate (NoC)\n * for a Matter device using a Certificate Signing Request (CSR) obtained from app-level adapters during commissioning.\n */\ninterface ESPRMIssueNodeNoCRequest {\n  /**\n   * A base64-encoded Certificate Signing Request string received from the Matter device\n   * during the commissioning process. This CSR is typically generated by Matter device\n   * commissioning flows at the application layer.\n   */\n  csr: string;\n\n  /**\n   * Optional array of strings in key:value format for device categorization.\n   * Example: [\"device_type:light\", \"room:kitchen\"]\n   */\n  tags?: string[];\n\n  /**\n   * Optional key-value object for node-specific metadata.\n   * This can include device information, location, or other custom properties.\n   */\n  metadata?: Record<string, any>;\n\n  /**\n   * Optional device identifier supplied by the native layer for response enrichment.\n   */\n  deviceId?: string;\n}\n\n/**\n * Interface for the request parameters of issueUserNoC method.\n * This interface defines the parameters required to issue a Node Operational Certificate (NoC)\n * for a user within a Matter fabric using a Certificate Signing Request from the user's Matter controller.\n */\ninterface ESPRMIssueUserNoCRequest {\n  /**\n   * A base64-encoded Certificate Signing Request from the user's Matter controller.\n   * This CSR is used to generate a user certificate for authentication and access control\n   * within the Matter fabric.\n   */\n  csr: string;\n}\n\n/**\n * Base interface for confirming Matter node commissioning.\n * This interface defines the common parameters required for all types of Matter node commissioning confirmation.\n * It serves as the foundation for both pure Matter and RainMaker + Matter node confirmation requests.\n */\ninterface ESPRMConfirmCommissioningRequest {\n  /**\n   * The status of the commissioning confirmation request.\n   * Must be either \"success\" to confirm successful commissioning or \"failed\" to indicate failure.\n   */\n  status: typeof MatterStatusTypes.SUCCESS | typeof MatterStatusTypes.FAILED;\n\n  /**\n   * Optional metadata to associate with the commissioning confirmation.\n   * This can include device information, commissioning details, or other relevant properties.\n   */\n  metadata?: Record<string, any>;\n}\n\n/**\n * Interface for confirming pure Matter node commissioning.\n * This interface is used for devices that only support local Matter communication\n * and do not have RainMaker cloud integration capabilities.\n */\ninterface ESPRMConfirmPureMatterNodeRequest\n  extends ESPRMConfirmCommissioningRequest {\n  /**\n   * The type of node being confirmed. Always \"pure_matter\" for this interface.\n   * This indicates that the device only supports local Matter mesh communication.\n   */\n  nodeType: typeof MatterNodeTypes.PURE_MATTER;\n}\n\n/**\n * Interface for confirming RainMaker + Matter node commissioning.\n * This interface is used for devices that support both RainMaker cloud integration\n * and local Matter mesh communication, providing hybrid connectivity capabilities.\n */\ninterface ESPRMConfirmRainMakerMatterNodeRequest\n  extends ESPRMConfirmCommissioningRequest {\n  /**\n   * The type of node being confirmed. Always \"rainmaker_matter\" for this interface.\n   * This indicates that the device supports both RainMaker cloud and local Matter communication.\n   */\n  nodeType: typeof MatterNodeTypes.RAINMAKER_MATTER;\n\n  /**\n   * RainMaker node ID obtained from the device during commissioning.\n   * This ID is used for cloud-based device management and control.\n   */\n  rainmakerNodeId: string;\n\n  /**\n   * Matter node ID that was assigned during the commissioning process.\n   * This ID is used for local Matter mesh communication and device identification.\n   */\n  matterNodeId: string;\n\n  /**\n   * Challenge response signed by the device's private key.\n   * This cryptographic proof demonstrates that the device owns the private key\n   * corresponding to its Certificate Signing Request (CSR).\n   */\n  challengeResponse: string;\n\n  /**\n   * The original challenge that was sent to the device for verification.\n   * This is used for server-side verification of the challenge response.\n   * Optional parameter that can be omitted if not required for verification.\n   */\n  challenge?: string;\n}\n\n/**\n * Union type for all Matter node confirmation requests.\n * This type supports both pure Matter nodes (local mesh only) and RainMaker + Matter nodes\n * (cloud + local mesh), enabling flexible device commissioning confirmation.\n */\ntype ESPRMConfirmMatterNodeRequest =\n  | ESPRMConfirmPureMatterNodeRequest\n  | ESPRMConfirmRainMakerMatterNodeRequest;\n\n/**\n * Interface for Matter fabric creation request.\n * This extends the regular group creation request with Matter-specific fields\n * including metadata support for fabric creation.\n */\ninterface CreateFabricRequest extends CreateGroupRequest {\n  /**\n   * Optional group metadata to be stored with the fabric.\n   * This metadata will be sent to the backend using the group_metadata key.\n   */\n  metadata?: Record<string, any>;\n}\n\n/**\n * Interface for Matter fabric creation API response.\n * This extends the regular group creation response with Matter-specific fields\n * including fabric ID for Matter-specific identification.\n */\ninterface CreateFabricAPIResponse extends CreateGroupAPIResponse {\n  /**\n   * Fabric ID assigned to the newly created Matter fabric.\n   * This identifier is used for Matter-specific operations and device management.\n   */\n  fabric_id: string;\n}\n\ntype MatterControlOperation =\n  (typeof MatterControlOperations)[keyof typeof MatterControlOperations];\n\ntype MatterControlErrorCode = keyof typeof MatterControlErrorCodes;\n\n/** Matter Structure TLV used as invoke command payload. */\ninterface MatterDataValueStructure {\n  type: \"Structure\";\n  value: Array<{\n    contextTag: number;\n    data: {\n      type: string;\n      value: number;\n      length?: number;\n      octetLength?: number;\n    };\n  }>;\n}\n\n/** Target Matter end-device referenced in broker cmd-resp write/invoke payloads. */\ninterface MatterControllerTargetObject {\n  matter_node_id: string;\n  matter_endpoint_id: string;\n}\n\n/** One attribute path in a Matter controller read (cmd 4354) payload. */\ninterface MatterControllerAttributePath {\n  endpoint_id: string;\n  cluster_id: string;\n  attribute_id: string;\n}\n\n/** CLI-parity read `data` for cmd 4354 (`attribute_paths`, no `objects`). */\ninterface MatterControllerReadData {\n  matter_node_id: string;\n  attribute_paths: MatterControllerAttributePath[];\n}\n\ninterface MatterControllerWriteRequestPayload {\n  cluster_id: string;\n  attribute_id: string;\n  attribute_value: unknown;\n}\n\ninterface MatterControllerInvokeRequestPayload {\n  cluster_id: string;\n  command_id: string;\n  /** Wire-ready `\"contextTag:typeCode\"` field map for invoke. */\n  command_fields: Record<string, number>;\n}\n\ntype MatterControllerRequestPayload =\n  | MatterControllerWriteRequestPayload\n  | MatterControllerInvokeRequestPayload;\n\n/** CLI-parity write/invoke `data` for cmds 4353 / 4352. */\ninterface MatterControllerWriteInvokeData {\n  objects: MatterControllerTargetObject[];\n  request_payload: MatterControllerRequestPayload;\n}\n\n/**\n * Wire `data` passed to RainMaker `createCmdRespRequest` for matter_controller.\n * Matches CLI Original REST payloads (no SDK `type` field).\n */\ntype MatterControllerDataRequest =\n  | MatterControllerReadData\n  | MatterControllerWriteInvokeData;\n\n/** `{ cmdId, data }` ready for User/Node `createCmdRespRequest`. */\ninterface MatterControllerCmdRespPayload {\n  cmdId: number;\n  data: MatterControllerDataRequest;\n}\n\n/**\n * Metadata for the built-in matter_controller transport handler.\n * App supplies the controller RainMaker node id; SDK owns cmd-resp create/poll/parse.\n */\ninterface MatterControllerTransportMetadata {\n  controllerNodeId: string;\n  /** Optional create/poll timeout in seconds (default 60). */\n  timeoutSeconds?: number;\n}\n\ninterface MatterControlRequest {\n  operation: MatterControlOperation;\n  matterNodeId: string;\n  endpointId: number;\n  clusterId: number;\n  attributeId?: number;\n  commandId?: number;\n  value?: unknown;\n  invokePayload?: Record<string, unknown>;\n  /**\n   * Matter / RainMaker type hint for write encoding (e.g. `uint16`, `bool`).\n   * Used to build CLI-parity `{ \"0:U16\": n }` attribute_value maps.\n   */\n  attributeType?: string;\n  transportMode: string;\n  transportMetadata: Record<string, unknown>;\n}\n\ntype MatterControlInput = Omit<\n  MatterControlRequest,\n  \"transportMode\" | \"transportMetadata\"\n>;\n\ntype MatterTransportHandler = (\n  node: ESPRMNode,\n  request: MatterControlRequest\n) => Promise<MatterControlResult>;\n\n/**\n * Configuration options for ESP Rainmaker Matter SDK.\n * Extends the base SDK configuration with Matter-specific adapters.\n */\ninterface ESPRMMatterBaseConfig extends ESPRMBaseConfig {\n  /**\n   * Matter commissioning adaptor for handling Matter commissioning operations.\n   * This adaptor provides the interface between the SDK and the native Matter\n   * implementation in the application layer.\n   */\n  matterCommissioningAdaptor?: ESPMatterCommissioningAdaptorInterface;\n\n  /**\n   * Matter control adapter for handling Matter cluster commands.\n   * This adapter is used for local Matter control operations (OnOff, LevelControl, etc.).\n   * Optional - if not provided, local Matter control will not be available.\n   */\n  matterControlAdapter?: ESPMatterControlAdapterInterface;\n\n  /**\n   * Matter subscription adapter for handling Matter attribute subscriptions.\n   * This adapter is used for receiving real-time device updates via Matter protocol.\n   * Optional - if not provided, Matter subscription channel will not be available.\n   * \n   * When provided, enables the Matter subscription channel for low-latency local updates.\n   * The subscription channel can be registered with the subscription manager to receive\n   * device parameter updates directly from Matter devices on the local network.\n   * \n   * @example\n   * ```typescript\n   * ESPRMMatterBase.configure({\n   *   // ... other config\n   *   matterSubscriptionAdapter: myMatterSubscriptionAdapter\n   * });\n   * \n   * // Initialize Matter subscription channel\n   * await ESPRMMatterBase.initializeMatterSubscription();\n   * ```\n   */\n  matterSubscriptionAdapter?: ESPMatterSubscriptionAdapter;\n\n  /**\n   * Matter local discovery adapter for discovering/lost operational services.\n   * Optional - if not provided, Matter discovery subscriptions are no-op.\n   */\n  matterLocalDiscoveryAdapter?: ESPMatterLocalDiscoveryAdapterInterface;\n\n  /**\n   * Matter vendor ID for device commissioning.\n   * This ID is required and must be provided during SDK configuration.\n   * It is used during Matter commissioning to identify the vendor.\n   * Example: \"0x131B\" (Espressif vendor ID)\n   */\n  matterVendorId: string;\n\n  /**\n   * App-defined Matter cluster param registry.\n   * Supplied by the host app adaptor (e.g. `ESPRMMatterBase/cluster.config.ts`).\n   * The SDK uses this to compile Matter metadata into UI-ready device params.\n   */\n  clusterConfig?: ClusterConfigMap;\n}\n\nexport type { MatterControlOperations } from \"../../utils/constants\";\nexport {\n  MatterControlOperation,\n  MatterControlErrorCode,\n  MatterControllerDataRequest,\n  MatterControllerCmdRespPayload,\n  MatterControllerTargetObject,\n  MatterControllerAttributePath,\n  MatterControllerReadData,\n  MatterControllerWriteInvokeData,\n  MatterControllerRequestPayload,\n  MatterControllerWriteRequestPayload,\n  MatterControllerInvokeRequestPayload,\n  MatterDataValueStructure,\n  MatterControllerTransportMetadata,\n  MatterControlRequest,\n  MatterControlInput,\n  MatterTransportHandler,\n  ESPRMCSRGenerationResult,\n  ESPRMNoCRequestEventData,\n  ESPRMConfirmRequestEventData,\n  ESPRMNativeDataPayload,\n  ESPMatterCommissioningAdaptorInterface,\n  ESPRMGetGroupsRequestParams,\n  ESPRMGetFabricByIdRequestParams,\n  ESPRMIssueNodeNoCRequest,\n  ESPRMIssueUserNoCRequest,\n  ESPRMConfirmCommissioningRequest,\n  ESPRMConfirmPureMatterNodeRequest,\n  ESPRMConfirmRainMakerMatterNodeRequest,\n  ESPRMConfirmMatterNodeRequest,\n  CreateFabricRequest,\n  CreateFabricAPIResponse,\n  ESPRMMatterBaseConfig,\n  ESPCommissioningResponseStatus,\n  ESPCommissioningResponse,\n  ESPRMGenerateCSRRequest,\n  ESPMatterDiscoveryParamsInterface,\n  ESPMatterLocalDiscoveryAdapterInterface,\n};\n"],"names":["ESPCommissioningResponseStatus"],"mappings":";;AAAA;;;;AAIG;AAoKH;;;AAGG;AACEA;AAAL,CAAA,UAAK,8BAA8B,EAAA;AACjC;;AAEG;AACH,IAAA,8BAAA,CAAA,aAAA,CAAA,GAAA,YAA0B;AAC1B;;AAEG;AACH,IAAA,8BAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB;;AAEG;AACH,IAAA,8BAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACnB,CAAC,EAbIA,sCAA8B,KAA9BA,sCAA8B,GAAA,EAAA,CAAA,CAAA;;"}