import assert from 'node:assert';
import BoxError from '../boxerror.js';
import community from '../community.js';
import { HttpSuccess } from '@cloudron/connect-lastmile';
import safe from 'safetydance';


async function getAppVersion(req, res, next) {
    assert.strictEqual(typeof req.query.url, 'string');
    assert.strictEqual(typeof req.query.version, 'string');

    const [error, result] = await safe(community.resolveVersionsUrl(req.query.url, req.query.version));
    if (error) return next(BoxError.toHttpError(error));

    next(new HttpSuccess(200, result)); // { manifest, publishState, creationDate, ts, resolvedUrl, versionsUrl }
}

export default {
    getAppVersion
};
