"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const core_1 = require("@nestjs/core");
const common_1 = require("@nestjs/common");
const app_module_1 = require("../app.module");
const didit_service_1 = require("../appapi/kyc/didit.service");
function readArg(name) {
    const idx = process.argv.indexOf(`--${name}`);
    if (idx === -1)
        return undefined;
    return process.argv[idx + 1];
}
async function main() {
    const logger = new common_1.Logger('test-didit-kyc-session');
    const vendorData = readArg('vendorData') ?? readArg('vendor_data') ?? 'user-42';
    const callback = readArg('callback');
    const workflowId = readArg('workflowId') ??
        readArg('workflow_id') ??
        process.env.DIDIT_KYC_WORKFLOW_ID ??
        undefined;
    if (!workflowId) {
        throw new Error('Missing workflowId (pass --workflowId or set DIDIT_KYC_WORKFLOW_ID in env)');
    }
    const app = await core_1.NestFactory.createApplicationContext(app_module_1.AppModule, {
        logger: ['log', 'error', 'warn'],
    });
    try {
        const diditService = app.get(didit_service_1.DiditService);
        const session = await diditService.createSession({
            workflow_id: workflowId,
            vendor_data: vendorData,
            ...(callback ? { callback } : {}),
        });
        logger.log(`Created session: ${JSON.stringify(session)}`);
    }
    finally {
        await app.close();
    }
}
main().catch((err) => {
    console.error(err);
    process.exitCode = 1;
});
//# sourceMappingURL=test-didit-kyc-session.js.map