/** * @module * * Wrapper to have the signature window embeded in your page with an iframe * * @example * ```ts *const yousign = new Yousign({ * signatureLink: "signature_link", * iframeContainerId: "iframe-container", * isSandbox: false, * classes: ["h-full", "w-full"], *}); * *yousign.onStarted((data) => { * console.log("Signer has opened the signature"); * console.log(data); *}); * *yousign.onSuccess((data) => { * console.log("Signer has successfully signed"); * console.log(data); *}); * *yousign.onError((data) => { * console.log("Signer encountered an error when signing"); * console.log(data); *}); * *yousign.onPing((data) => { * console.log("Ping - The signature request is loaded"); * console.log(data); *}); * *yousign.onDeclined((data) => { * console.log("Declined - The signer declined the signature"); * console.log(data); *}); * * ``` */ interface YousignConfig { /** * The URL of the signature request. */ signatureLink: string; /** The id attribute of the element where the iframe is initialized. */ iframeContainerId: string; /** To set if you want to test your integration with sandbox environment */ isSandbox?: boolean; /** Classes to add to the iframe component once it loaded */ classes?: string[]; } type YousignRadio = { /** The radio button ID. */ id: string; /** Determines if the radio button field on the signature was checked. */ checked: boolean; /** Name of the radio button */ name: string; /** Name of the radio button */ x: number; /** Name of the radio button */ y: number; }; type YousignCheckboxAnswer = { /** Field ID. */ field_id: string; field_type: "checkbox"; /** Determines if the checkbox field on the signature was checked. */ checked: boolean; /** Determines if the checkbox field on the signature was optional. */ optional: boolean; }; type YousignTextAnswer = { /** Field ID. */ field_id: string; field_type: "text"; /** The question in the text field on the signature. */ question: string; /** The answer of the question text field on the signature. */ answer: string; }; type YousignRadioGroupAnser = { /** Field ID. */ field_id: string; /** The field type, see {@link https://developers.yousign.com/docs/signer-fields|signer fields} for more information about fields). */ field_type: "radio_group"; /** Determines if the radio group field on the signature was optional. */ optional: boolean; /** List of the radio button attached to the radio group. */ radios: YousignRadio[]; }; type YousignAnswer = YousignTextAnswer | YousignCheckboxAnswer | YousignRadioGroupAnser; type YousignBaseEvent = { /**Always equal to yousign */ type: string; /**The signer ID. */ signer_id: string; /** The signature request ID */ signature_request_id: string; payload?: { redirectUrl?: string; }; }; type YousignSuccessEvent = YousignBaseEvent & { event: "success"; answers: YousignAnswer[]; }; type YousignErrorEvent = YousignBaseEvent & { event: "error"; answers: YousignAnswer[]; }; type YousignStartedEvent = YousignBaseEvent & { event: "started"; }; type YousignDeclinedEvent = YousignBaseEvent & { event: "declined"; }; type YousignPingEvent = YousignBaseEvent & { event: "ping"; }; /** * Collection of possible types of the events */ type YousignEvent = YousignSuccessEvent | YousignErrorEvent | YousignStartedEvent | YousignDeclinedEvent | YousignPingEvent; type EventCallback = (data: T extends YousignEvent["event"] ? Extract : YousignEvent) => void; /** * For security reasons, iFrame is available only in production on whitelisted domains. To add your domains, please get in touch with our support. * @example ````ts const yousign = new Yousign({ signatureLink: "signature_link", iframeContainerId: "iframe-container", isSandbox: false, classes: ["h-full", "w-full"], }); yousign.onStarted((data) => { console.log("Signer has opened the signature"); console.log(data); }); yousign.onSuccess((data) => { console.log("Signer has successfully signed"); console.log(data); }); yousign.onError((data) => { console.log("Signer encountered an error when signing"); console.log(data); }); yousign.onPing((data) => { console.log("Ping - The signature request is loaded"); console.log(data); }); yousign.onDeclined((data) => { console.log("Declined - The signer declined the signature"); console.log(data); }); ``` */ declare class Yousign { private childOrigin; private eventCallbacks; private iframe; private messageHandler; private urlParams; /** * @param {YouSignConfig} config * @throws {InvalidSignatureLink} The signature link is not an URL or not valid. * @throws {IframeContainerNotFound} The Iframe container is not found */ constructor({ signatureLink, iframeContainerId, isSandbox, classes, }: YousignConfig); private receiveMessage; /** * A function that is triggered when the signature is opened. * @throws {InvalidCallbackFunction} Callback on event is not a function */ onStarted(callback: EventCallback<"started">): void; /** * A function that is triggered when the signature is signed successfully. * @throws {InvalidCallbackFunction} Callback on event is not a function */ onSuccess(callback: EventCallback<"success">): void; /** * A function that is triggered when the signature encountered an error when signing. * @throws {InvalidCallbackFunction} Callback on event is not a function */ onError(callback: EventCallback<"error">): void; /** * A function that is triggered every 5 seconds to inform the signature request is loaded. * @throws {InvalidCallbackFunction} Callback on event is not a function */ onPing(callback: EventCallback<"ping">): void; /** * A function that is triggered when the signer declined the signature. * @throws {InvalidCallbackFunction} Callback on event is not a function */ onDeclined(callback: EventCallback<"declined">): void; /** * @throws {InvalidCallbackFunction} Callback on event is not a function */ private setEventCallback; removeMessageListener(): void; } export { Yousign, type YousignEvent };