How-to for common workflows

Recipe for basic create and send an eSignature package

import { PactimaApi, ESignaturePackageWebhookArtifactEnum, ESignatureEntryPadTypeEnum, ESignatureKindEnum } from '@pactima/node'
import { readFile } from 'fs/promises';
import { join } from 'path';

const SECRET_KEY = 'pctm_sk_live_xxx....';
const TEAM_ID = 'team_id...';
const senderEmail = '[email protected]';
const signerInfo = {
    name: 'Signer Sample',
    email: '[email protected]'
}
// This can be a PDF, DOCX, or any other supported file type
const filePath = join(__dirname, 'sample.pdf');

const main = async () => {
    const pactimaApi = new PactimaApi(SECRET_KEY);

    const members = await pactimaApi.teams.members.list(TEAM_ID);

    let esp = await pactimaApi.eSignaturePackages.create({
        title: 'Sample live package by Node SDK ',
        owner: members?.data?.find((x) => x.email === senderEmail)?.userId ?? '',
        kind: ESignatureKindEnum.Live,
        advancedOptions: {
            notifications: [
                // Disable all email notifications
                {
                    event: 'EVENTS.ALL',
                    participantId: 'PARTICIPANTS.ALL',
                    enabled: false
                }
            ],
            exitRedirectUriConfigurations: [
                // Redirect all partitipants to pactima.com after signing
                {
                    participantId: 'PARTICIPANTS.ALL',
                    redirectUri: 'https://pactima.com'
                }
            ],
            inlineWebhook: {
                // Have a webhook that will be called for all events, and if completed, package will be sent
                urlToPublish: 'https://webhook.site/xxx...',
                triggerEvents: ['EVENTS.ALL'],
                requestedArtifacts: [{
                    artifactKind: ESignaturePackageWebhookArtifactEnum.CompletedPackage,
                }]
            }
        }
    });

    esp = await pactimaApi.eSignaturePackages.update(esp.id, {
      signers: [ signerInfo ]
    })


    const d = await pactimaApi.eSignaturePackages.documents.create(esp.id , {
        name: 'Dample Doc',
        data: await readFile(filePath)
    });

    /**
     * Insert an entry pad for the document
     * This could be done via template or even embedded preparation
     */
    await pactimaApi.eSignaturePackages.documents.entryPads.create(esp.id, d.id ?? '', {
        type: ESignatureEntryPadTypeEnum.Signature,
        left: 15,
        top: 4,
        height: 6,
        width: 4.5,
        pageIndex: 0,
        signerId: esp.signers?.find((x) => x.email === signerInfo.email)?.id ?? ''
    });

    // Trigger the package to be sent / scheduled
    await pactimaApi.eSignaturePackages.actions.trigger(esp.id);

}

(async () => {
    await main();
})();