UNPKG

@ar.io/sdk

Version:

[![codecov](https://codecov.io/gh/ar-io/ar-io-sdk/graph/badge.svg?token=7dXKcT7dJy)](https://codecov.io/gh/ar-io/ar-io-sdk)

114 lines (113 loc) 5.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setAntRecordCLICommand = setAntRecordCLICommand; exports.setAntBaseNameCLICommand = setAntBaseNameCLICommand; exports.setAntUndernameCLICommand = setAntUndernameCLICommand; exports.transferRecordOwnershipCLICommand = transferRecordOwnershipCLICommand; exports.upgradeAntCLICommand = upgradeAntCLICommand; const utils_js_1 = require("../utils.js"); /** @deprecated -- use set-ant-base-name and set-ant-undername */ async function setAntRecordCLICommand(o) { const ttlSeconds = +(o.ttlSeconds ?? utils_js_1.defaultTtlSecondsCLI); const undername = (0, utils_js_1.requiredStringFromOptions)(o, 'undername'); const transactionId = (0, utils_js_1.requiredStringFromOptions)(o, 'transactionId'); const writeAnt = (0, utils_js_1.writeANTFromOptions)(o); const recordParams = { undername, transactionId, ttlSeconds, ...(0, utils_js_1.antRecordMetadataFromOptions)(o), }; if (!o.skipConfirmation) { await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to set this record on the ANT process ${writeAnt.processId}?\n${JSON.stringify(recordParams, null, 2)}`, o); } return (0, utils_js_1.writeANTFromOptions)(o).setRecord(recordParams, (0, utils_js_1.customTagsFromOptions)(o)); } async function setAntBaseNameCLICommand(o) { const ttlSeconds = +(o.ttlSeconds ?? utils_js_1.defaultTtlSecondsCLI); const transactionId = (0, utils_js_1.requiredStringFromOptions)(o, 'transactionId'); const params = { transactionId, ttlSeconds, ...(0, utils_js_1.antRecordMetadataFromOptions)(o), }; const writeAnt = (0, utils_js_1.writeANTFromOptions)(o); if (!o.skipConfirmation) { await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to set this base name on the ANT process ${writeAnt.processId}?\n${JSON.stringify(params, null, 2)}`, o); } return (0, utils_js_1.writeANTFromOptions)(o).setBaseNameRecord(params, (0, utils_js_1.customTagsFromOptions)(o)); } async function setAntUndernameCLICommand(o) { const ttlSeconds = +(o.ttlSeconds ?? utils_js_1.defaultTtlSecondsCLI); const undername = (0, utils_js_1.requiredStringFromOptions)(o, 'undername'); const transactionId = (0, utils_js_1.requiredStringFromOptions)(o, 'transactionId'); const params = { undername, transactionId, ttlSeconds, ...(0, utils_js_1.antRecordMetadataFromOptions)(o), }; const writeAnt = (0, utils_js_1.writeANTFromOptions)(o); if (!o.skipConfirmation) { await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to set this undername on the ANT process ${writeAnt.processId}?\n${JSON.stringify(params, null, 2)}`, o); } return (0, utils_js_1.writeANTFromOptions)(o).setUndernameRecord(params, (0, utils_js_1.customTagsFromOptions)(o)); } async function transferRecordOwnershipCLICommand(o) { const undername = (0, utils_js_1.requiredStringFromOptions)(o, 'undername'); const recipient = (0, utils_js_1.requiredStringFromOptions)(o, 'recipient'); const writeAnt = (0, utils_js_1.writeANTFromOptions)(o); if (!o.skipConfirmation) { await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to transfer ownership of "${undername}" to "${recipient}" on ANT process ${writeAnt.processId}?\n${JSON.stringify({ undername, recipient }, null, 2)}`, o); } return (0, utils_js_1.writeANTFromOptions)(o).transferRecord({ undername, recipient }, (0, utils_js_1.customTagsFromOptions)(o)); } async function upgradeAntCLICommand(o) { const writeAnt = (0, utils_js_1.writeANTFromOptions)(o); const arioProcessId = (0, utils_js_1.arioProcessIdFromOptions)(o); const ario = (0, utils_js_1.readARIOFromOptions)(o); const reassignAffiliatedNames = (0, utils_js_1.booleanFromOptions)(o, 'reassignAffiliatedNames'); const names = (0, utils_js_1.stringArrayFromOptions)(o, 'names') || []; if (reassignAffiliatedNames) { // Fetch all ArNS records that point to this ANT process const allRecords = await ario.getArNSRecords({ filters: { processId: writeAnt.processId, }, }); // Filter records that belong to this ANT const affiliatedNames = allRecords.items.map((record) => record.name); names.push(...affiliatedNames); } if (names.length === 0) { throw new Error('No names to reassign'); } if (!o.skipConfirmation) { await (0, utils_js_1.assertConfirmationPrompt)(`Upgrade all names affiliated with this ANT on ARIO process?\n` + `ARIO Process ID: ${arioProcessId}\n` + `ANT Process ID: ${writeAnt.processId}\n` + `Names that will be reassigned (${names.length}): ${names.join(', ')}`, o); } const result = reassignAffiliatedNames ? await (0, utils_js_1.writeANTFromOptions)(o).upgrade({ reassignAffiliatedNames, arioProcessId, }) : await (0, utils_js_1.writeANTFromOptions)(o).upgrade({ names, arioProcessId, }); // Serialize error objects for JSON compatibility const serializedFailedReassignedNames = {}; for (const [name, failure] of Object.entries(result.failedReassignedNames)) { serializedFailedReassignedNames[name] = { id: failure.id, error: failure.error.message, }; } return { forkedProcessId: result.forkedProcessId, reassignedNames: result.reassignedNames, failedReassignedNames: serializedFailedReassignedNames, }; }